Skip to content

Commit 0a4a9e0

Browse files
committed
feat(loading): Move the notification into loading modal if it exists.
1 parent 0e13a45 commit 0a4a9e0

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/loadingModal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export class LoadingModal extends Modal {
1010
this.plugin = plugin;
1111
}
1212

13+
info(msg: string) {
14+
let { contentEl } = this;
15+
let container = contentEl.querySelector('.loading-logs');
16+
if (!container) {
17+
container = contentEl.createDiv('loading-logs');
18+
}
19+
const logItem = container.createDiv('loading-log-item');
20+
logItem.innerText = msg;
21+
}
22+
1323
onOpen() {
1424
let { contentEl } = this;
1525
const t = (x: TransItemType, vars?: any) => {

src/main.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ export default class InvioPlugin extends Plugin {
119119
return this.i18n.t(x, vars);
120120
};
121121

122-
const getNotice = (x: string, timeout?: number) => {
122+
const getNotice = (modal: LoadingModal, x: string, timeout?: number) => {
123123
// only show notices in manual mode
124124
// no notice in auto mode
125125
if (triggerSource === "manual" || triggerSource === "dry") {
126+
if (modal) {
127+
modal.info(x);
128+
return;
129+
}
126130
new Notice(x, timeout);
127131
}
128132
};
@@ -164,10 +168,14 @@ export default class InvioPlugin extends Plugin {
164168
);
165169
}
166170

171+
loadingModal = new LoadingModal(this.app, this);
172+
loadingModal.open();
173+
167174
const MAX_STEPS = 8;
168175

169176
if (triggerSource === "dry") {
170177
getNotice(
178+
loadingModal,
171179
t("syncrun_step0", {
172180
maxSteps: `${MAX_STEPS}`,
173181
})
@@ -176,6 +184,7 @@ export default class InvioPlugin extends Plugin {
176184

177185
//log.info(`huh ${this.settings.password}`)
178186
getNotice(
187+
loadingModal,
179188
t("syncrun_step1", {
180189
maxSteps: `${MAX_STEPS}`,
181190
serviceType: this.settings.serviceType,
@@ -184,14 +193,13 @@ export default class InvioPlugin extends Plugin {
184193
this.syncStatus = "preparing";
185194

186195
getNotice(
196+
loadingModal,
187197
t("syncrun_step2", {
188198
maxSteps: `${MAX_STEPS}`,
189199
})
190200
);
191201

192202

193-
loadingModal = new LoadingModal(this.app, this);
194-
loadingModal.open();
195203

196204
this.syncStatus = "getting_remote_files_list";
197205
const self = this;
@@ -207,6 +215,7 @@ export default class InvioPlugin extends Plugin {
207215
const remoteContents = remoteRsp.Contents.filter(item => item.key !== RemoteSrcPrefix);
208216

209217
getNotice(
218+
loadingModal,
210219
t("syncrun_step3", {
211220
maxSteps: `${MAX_STEPS}`,
212221
})
@@ -217,11 +226,12 @@ export default class InvioPlugin extends Plugin {
217226
this.settings.password
218227
);
219228
if (!passwordCheckResult.ok) {
220-
getNotice(t("syncrun_passworderr"));
229+
getNotice(loadingModal, t("syncrun_passworderr"));
221230
throw Error(passwordCheckResult.reason);
222231
}
223232

224233
getNotice(
234+
loadingModal,
225235
t("syncrun_step4", {
226236
maxSteps: `${MAX_STEPS}`,
227237
})
@@ -244,6 +254,7 @@ export default class InvioPlugin extends Plugin {
244254
console.log('fetchMetadataFile result: ', origMetadataOnRemote);
245255

246256
getNotice(
257+
loadingModal,
247258
t("syncrun_step5", {
248259
maxSteps: `${MAX_STEPS}`,
249260
})
@@ -271,6 +282,7 @@ export default class InvioPlugin extends Plugin {
271282
log.info('local history: ', localHistory);
272283

273284
getNotice(
285+
loadingModal,
274286
t("syncrun_step6", {
275287
maxSteps: `${MAX_STEPS}`,
276288
})
@@ -298,6 +310,7 @@ export default class InvioPlugin extends Plugin {
298310

299311
try {
300312
loadingModal.close();
313+
loadingModal = null;
301314

302315
await new Promise((resolve, reject) => {
303316
if (fileList?.length > 0) {
@@ -314,7 +327,7 @@ export default class InvioPlugin extends Plugin {
314327
} catch (error) {
315328
log.info('user cancelled');
316329
this.syncStatus = "idle";
317-
getNotice('user cancelled')
330+
getNotice(loadingModal, 'user cancelled')
318331
if (this.syncRibbon !== undefined) {
319332
setIcon(this.syncRibbon, iconNameSyncLogo);
320333
this.syncRibbon.setAttribute("aria-label", originLabel);
@@ -477,13 +490,15 @@ export default class InvioPlugin extends Plugin {
477490
} else {
478491
this.syncStatus = "syncing";
479492
getNotice(
493+
null,
480494
t("syncrun_step7skip", {
481495
maxSteps: `${MAX_STEPS}`,
482496
})
483497
);
484498
}
485499

486500
getNotice(
501+
null,
487502
t("syncrun_step8", {
488503
maxSteps: `${MAX_STEPS}`,
489504
})
@@ -516,13 +531,13 @@ export default class InvioPlugin extends Plugin {
516531
loadingModal.close();
517532
log.error(msg);
518533
log.error(error);
519-
getNotice(msg, 10 * 1000);
534+
getNotice(null, msg, 10 * 1000);
520535
if (error instanceof AggregateError) {
521536
for (const e of error.errors) {
522-
getNotice(e.message, 10 * 1000);
537+
getNotice(null, e.message, 10 * 1000);
523538
}
524539
} else {
525-
getNotice(error.message, 10 * 1000);
540+
getNotice(null, error.message, 10 * 1000);
526541
}
527542
this.syncStatus = "idle";
528543
if (this.syncRibbon !== undefined) {

styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@
132132
width: 100%;
133133
}
134134

135+
.loading-logs {
136+
display: block;
137+
padding: 12px;
138+
border-top: 1px solid #f5f5f5;
139+
}
140+
141+
.loading-log-item {
142+
padding: 6px 8px;
143+
font-size: small;
144+
color: currentColor;
145+
}
146+
135147
.hide-loading-container {
136148
display: none;
137149
}

0 commit comments

Comments
 (0)