Skip to content

Commit

Permalink
moved around async code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Aug 9, 2024
1 parent 07c083d commit 321f017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class SimpleTimeTrackerPlugin extends Plugin {
}
}));

await displayTracker(tracker, e, getFile, () => i.getSectionInfo(e), this.settings, component);
displayTracker(tracker, e, getFile, () => i.getSectionInfo(e), this.settings, component);
i.addChild(component);
});

Expand Down
21 changes: 11 additions & 10 deletions src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function loadAllTrackers(fileName: string): Promise<{ section: Mark

type GetFile = () => string;

export async function displayTracker(tracker: Tracker, element: HTMLElement, getFile: GetFile, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, component: MarkdownRenderChild): Promise<void> {
export function displayTracker(tracker: Tracker, element: HTMLElement, getFile: GetFile, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, component: MarkdownRenderChild): void {

element.addClass("simple-time-tracker-container");
// add start/stop controls
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function displayTracker(tracker: Tracker, element: HTMLElement, get
createEl("th"));

for (let entry of orderedEntries(tracker.entries, settings))
await addEditableTableRow(tracker, entry, table, newSegmentNameBox, running, getFile, getSectionInfo, settings, 0, component);
addEditableTableRow(tracker, entry, table, newSegmentNameBox, running, getFile, getSectionInfo, settings, 0, component);

// add copy buttons
let buttons = element.createEl("div", { cls: "simple-time-tracker-bottom" });
Expand Down Expand Up @@ -339,7 +339,7 @@ function createTableSection(entry: Entry, settings: SimpleTimeTrackerSettings):
return ret;
}

async function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, trackerRunning: boolean, getFile: GetFile, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, indent: number, component: MarkdownRenderChild): Promise<void> {
function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableElement, newSegmentNameBox: TextComponent, trackerRunning: boolean, getFile: GetFile, getSectionInfo: () => MarkdownSectionInformation, settings: SimpleTimeTrackerSettings, indent: number, component: MarkdownRenderChild): void {
let entryRunning = getRunningEntry(tracker.entries) == entry;
let row = table.createEl("tr");

Expand All @@ -349,7 +349,7 @@ async function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTa

row.createEl("td", { text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : "" });

await renderNameAsMarkdown(nameField.label, getFile, component);
void renderNameAsMarkdown(nameField.label, getFile, component);

let expandButton = new ButtonComponent(nameField.label)
.setClass("clickable-icon")
Expand Down Expand Up @@ -394,7 +394,7 @@ async function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTa
await saveTracker(tracker, getFile(), getSectionInfo());
editButton.setIcon("lucide-pencil");

await renderNameAsMarkdown(nameField.label, getFile, component);
void renderNameAsMarkdown(nameField.label, getFile, component);
} else {
nameField.beginEdit(entry.name);
expandButton.buttonEl.style.display = "none";
Expand Down Expand Up @@ -426,7 +426,7 @@ async function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTa

if (entry.subEntries && !entry.collapsed) {
for (let sub of orderedEntries(entry.subEntries, settings))
await addEditableTableRow(tracker, sub, table, newSegmentNameBox, trackerRunning, getFile, getSectionInfo, settings, indent + 1, component);
addEditableTableRow(tracker, sub, table, newSegmentNameBox, trackerRunning, getFile, getSectionInfo, settings, indent + 1, component);
}
}

Expand All @@ -437,10 +437,11 @@ function showConfirm(message: string): Promise<boolean> {
});
}

async function renderNameAsMarkdown(label: HTMLSpanElement, getFile: GetFile, component: Component): Promise<void> {
await MarkdownRenderer.renderMarkdown(label.innerHTML, label, getFile(), component);
// rendering wraps it in a paragraph
label.innerHTML = label.querySelector("p").innerHTML;
function renderNameAsMarkdown(label: HTMLSpanElement, getFile: GetFile, component: Component): void {
MarkdownRenderer.renderMarkdown(label.innerHTML, label, getFile(), component).then(() => {
// rendering wraps it in a paragraph
label.innerHTML = label.querySelector("p").innerHTML;
});
}


Expand Down

0 comments on commit 321f017

Please sign in to comment.