Skip to content

Commit 501a65c

Browse files
committed
fix(force): Force mode workflow update.
1 parent 3e1cdfb commit 501a65c

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/main.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,20 @@ export default class InvioPlugin extends Plugin {
312312
loadingModal.close();
313313
loadingModal = null;
314314

315-
await new Promise((resolve, reject) => {
316-
if (fileList?.length > 0) {
317-
resolve('skip');
318-
return;
319-
}
320-
321-
const touchedPlanModel = new TouchedPlanModel(this.app, this, touchedFileMap, (pub: boolean) => {
322-
log.info('user confirmed: ', pub);
323-
pub ? resolve('ok') : reject('cancelled')
324-
});
325-
touchedPlanModel.open();
326-
})
315+
if (triggerSource !== 'force') {
316+
await new Promise((resolve, reject) => {
317+
if (fileList?.length > 0) {
318+
resolve('skip');
319+
return;
320+
}
321+
322+
const touchedPlanModel = new TouchedPlanModel(this.app, this, touchedFileMap, (pub: boolean) => {
323+
log.info('user confirmed: ', pub);
324+
pub ? resolve('ok') : reject('cancelled')
325+
});
326+
touchedPlanModel.open();
327+
})
328+
}
327329
} catch (error) {
328330
log.info('user cancelled');
329331
this.syncStatus = "idle";
@@ -357,7 +359,14 @@ export default class InvioPlugin extends Plugin {
357359
log.info('init stats view: ', view);
358360
if (view) {
359361
const initData: Record<string, FileOrFolderMixedState> = {};
360-
toRemoteFiles.forEach(f => {
362+
let changingFiles = toRemoteFiles;
363+
if (triggerSource === 'force') {
364+
changingFiles = allFiles.map(f => {
365+
const fState: FileOrFolderMixedState = { key: f.path, syncStatus: 'syncing' }
366+
return fState;
367+
})
368+
}
369+
changingFiles.forEach(f => {
361370
initData[f.key] = f;
362371
})
363372
view.info('Stats data init...');
@@ -368,7 +377,7 @@ export default class InvioPlugin extends Plugin {
368377
view?.info('Start to sync');
369378

370379
// TODO: Delete all remote html files if triggerSource === force
371-
const pubPathList: string[] = [];
380+
let pubPathList: string[] = [];
372381
const unPubList: string[] = [];
373382
await doActualSync(
374383
client,
@@ -424,9 +433,8 @@ export default class InvioPlugin extends Plugin {
424433
// selected mode
425434
// Get redo file list and redo the publish/unpublish job
426435
if (fileList?.length > 0) {
427-
const localFiles = this.app.vault.getMarkdownFiles().filter(file => file.path.startsWith(this.settings.localWatchDir) && !file.path.endsWith('.conflict.md'));
428436
fileList.forEach(p => {
429-
const exist = localFiles.find(file => file.path === p);
437+
const exist = allFiles.find(file => file.path === p);
430438
if (exist) {
431439
if (pubPathList.indexOf(p) === -1) {
432440
pubPathList.push(p)
@@ -453,6 +461,11 @@ export default class InvioPlugin extends Plugin {
453461
}
454462
});
455463

464+
// Force Mode - Publish all docs
465+
if (triggerSource === 'force') {
466+
pubPathList.push(...allFiles.map(file => file.path));
467+
pubPathList = pubPathList.filter((p, idx) => pubPathList.indexOf(p) === idx);
468+
}
456469
if (pubPathList?.length === 0) {
457470
if (unPubList?.length > 0) {
458471
// Need to update left tree links for unpublish means link deduction
@@ -473,8 +486,6 @@ export default class InvioPlugin extends Plugin {
473486
}
474487
});
475488

476-
477-
478489
if (triggerSource === 'force') {
479490
const forceList: string[] = [];
480491
for (const key in plan.mixedStates) {

0 commit comments

Comments
 (0)