Skip to content

Commit

Permalink
fixed duration display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
terryli710 committed Mar 12, 2024
1 parent 91de1b4 commit 03f3516
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/ui/Duration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
export let params: TaskDisplayParams;
export let displayDuration: boolean;
const interactiveMode = interactive;
let duration: Duration;
if (interactive) {
if (interactiveMode) {
duration = taskSyncManager.obsidianTask.hasDuration() ? taskSyncManager.obsidianTask.duration : undefined;
} else {
duration = taskItem.duration;
Expand Down Expand Up @@ -105,7 +107,6 @@
new Notice(`[TaskCard] Invalid duration format: ${durationInputString}`);
}
}
taskSyncManager.updateObsidianTaskAttribute('duration', duration);
origDurationInputString = durationInputString;
Expand Down Expand Up @@ -138,7 +139,7 @@ function parseDurationInput(input: string): { hours: number, minutes: number } |
}
$: {
if (interactive) {
if (interactiveMode) {
displayDuration = taskSyncManager.obsidianTask.hasDuration() || taskSyncManager.getTaskCardStatus('durationStatus') === 'editing';
} else {
displayDuration = !!taskItem.duration; // The double bang '!!' converts a truthy/falsy value to a boolean true/false
Expand All @@ -162,7 +163,7 @@ function parseDurationInput(input: string): { hours: number, minutes: number } |
<div class="task-card-duration-left-part">
<span class="task-card-duration-prefix"><History width={"14"} height={"14"} ariaLabel="duration"/></span>
</div>
{#if taskSyncManager.getTaskCardStatus('durationStatus') === 'editing'}
{#if interactiveMode && taskSyncManager.getTaskCardStatus('durationStatus') === 'editing'}
<input
type="text"
bind:value={durationInputString}
Expand Down
26 changes: 12 additions & 14 deletions src/ui/StaticTaskCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
import CircularProgressBar from '../components/CircularProgressBar.svelte';
import SyncLogos from './SyncLogos.svelte';
import Schedule from './Schedule.svelte';
// import Description from './Description.svelte';
import Content from './Content.svelte';
import Duration from './Duration.svelte';
import Due from './Due.svelte';
var md = require('markdown-it');
var taskLists = require('markdown-it-task-lists');
var mdParser = md().use(taskLists);
export let taskItem: PositionedObsidianTask;
export let plugin: TaskCardPlugin;
Expand Down Expand Up @@ -92,7 +90,7 @@
const currentWorkspaceDisplayMode =
plugin.app.workspace.activeLeaf.view.getState();
console.log(currentWorkspaceDisplayMode);
// console.log(currentWorkspaceDisplayMode);
const openViewState: OpenViewState = {
active: true,
Expand All @@ -116,15 +114,17 @@
const displayDue = task.hasDue();
// const displayDescription = task.hasDescription();
const taskDescriptionHTML = transformTaskDescriptionHTML(mdParser.render(task.description));
const taskDescriptionHTML = transformTaskDescriptionHTML(
mdParser.render(task.description)
);
/**
* Transforms the HTML generated by the markdown parser for task descriptions to match a specified structure.
* It specifically adjusts <ul> and <li> elements within the task descriptions to ensure they have the correct
* classes and attributes. This includes adding 'contains-task-list' class to <ul> elements, ensuring 'task-list-item'
* class is present on relevant <li> elements, and adjusting <input> elements inside these list items to have the
* appropriate attributes.
*
*
* @param {string} taskDescriptionHTML - The HTML string generated by the markdown parser for a task description.
* @returns {string} The transformed HTML string with the updated structure.
*/
Expand All @@ -144,8 +144,7 @@
wrapperDiv.appendChild(ulElement);
let lis = doc.body.querySelectorAll('li');
console.log('doc', doc);
// console.log("lis", lis);
lis.forEach((li, index) => {
let newLi = document.createElement('li');
let lineIndex = index + 1;
Expand All @@ -154,7 +153,8 @@
newLi.setAttribute('data-line', lineIndex.toString());
newLi.setAttribute('data-real-line', lineIndex.toString());
if (input instanceof HTMLInputElement) { // Ensure input is an HTMLInputElement
if (input instanceof HTMLInputElement) {
// Ensure input is an HTMLInputElement
let clonedInput = input.cloneNode(true) as HTMLInputElement; // Cast the cloned node
clonedInput.setAttribute('class', 'task-list-item-checkbox');
clonedInput.setAttribute('data-line', lineIndex.toString());
Expand Down Expand Up @@ -183,7 +183,6 @@
}
ulElement.appendChild(newLi);
});
// Use XMLSerializer to convert the document back to a string
Expand All @@ -192,7 +191,6 @@
return transformedHTML;
}
</script>

{#if taskDisplayParams.mode === 'single-line'}
Expand Down Expand Up @@ -321,21 +319,21 @@
<!-- Schedule/Duration/Due -->
<Schedule
interactive={false}
{displaySchedule}
displaySchedule={displaySchedule}
params={{ mode: 'multi-line' }}
taskItem={task}
/>
<Duration
interactive={false}
params={{ mode: 'multi-line' }}
taskItem={task}
{displayDuration}
displayDuration={displayDuration}
/>
<Due
interactive={false}
params={{ mode: 'multi-line' }}
taskItem={task}
{displayDue}
displayDue={displayDue}
/>
<!-- Labels -->
<div class="task-card-labels">
Expand Down

0 comments on commit 03f3516

Please sign in to comment.