Skip to content

Commit

Permalink
Better user feedback when publishing multiple notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Feb 10, 2023
1 parent ba2dc31 commit 237c41c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default class DigitalGarden extends Plugin {
callback: async () => {
const statusBarItem = this.addStatusBarItem();
try {

new Notice('Processing files to publish...');
const { vault, metadataCache } = this.app;
const publisher = new Publisher(vault, metadataCache, this.settings);
const siteManager = new DigitalGardenSiteManager(metadataCache, this.settings);
Expand All @@ -122,10 +124,12 @@ export default class DigitalGarden extends Plugin {
const filesToPublish = publishStatus.changedNotes.concat(publishStatus.unpublishedNotes);
const filesToDelete = publishStatus.deletedNotePaths;
const imagesToDelete = publishStatus.deletedImagePaths;
const statusBar = new PublishStatusBar(statusBarItem, filesToPublish.length + filesToDelete.length);
const statusBar = new PublishStatusBar(statusBarItem, filesToPublish.length + filesToDelete.length + imagesToDelete.length);

let errorFiles = 0;
let errorDeleteFiles = 0;
let errorDeleteImage = 0;
new Notice(`Publishing ${filesToPublish.length} notes, deleting ${filesToDelete.length} notes and ${imagesToDelete.length} images. See the status bar in lower right corner for progress.`, 8000);
for (const file of filesToPublish) {
try {
statusBar.increment();
Expand All @@ -150,7 +154,7 @@ export default class DigitalGarden extends Plugin {
statusBar.increment();
await publisher.deleteImage(filePath);
} catch {
errorDeleteFiles++;
errorDeleteImage++;
new Notice(`Unable to delete image ${filePath}, skipping it.`)
}
}
Expand All @@ -160,6 +164,9 @@ export default class DigitalGarden extends Plugin {
if (filesToDelete.length > 0) {
new Notice(`Successfully deleted ${filesToDelete.length - errorDeleteFiles} notes from your garden.`);
}
if(imagesToDelete.length > 0) {
new Notice(`Successfully deleted ${imagesToDelete.length - errorDeleteImage} images from your garden.`);
}

} catch (e) {
statusBarItem.remove();
Expand Down
4 changes: 2 additions & 2 deletions src/PublishStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class PublishStatusBar {

increment() {

this.status.innerText = `⌛Publishing Notes: ${++this.counter}/${this.numberOfNotesToPublish}`;
this.status.innerText = `⌛Publishing files: ${++this.counter}/${this.numberOfNotesToPublish}`;
}

finish(displayDurationMillisec: number) {
this.status.innerText = `✅ Published Notes: ${this.counter}/${this.numberOfNotesToPublish}`;
this.status.innerText = `✅ Published files: ${this.counter}/${this.numberOfNotesToPublish}`;
setTimeout(() => {
this.statusBarItem.remove();
}, displayDurationMillisec);
Expand Down

0 comments on commit 237c41c

Please sign in to comment.