Skip to content

Commit b942eba

Browse files
committed
Visual indication of initial indexing progress (red circle)
1 parent 1910ffc commit b942eba

File tree

10 files changed

+62
-18
lines changed

10 files changed

+62
-18
lines changed

plug-api/syscalls/editor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ export function hidePanel(
256256
return syscall("editor.hidePanel", id);
257257
}
258258

259+
export function showProgress(
260+
progressPercentage?: number,
261+
progressType?: string,
262+
) {
263+
return syscall("editor.showProgress", progressPercentage, progressType);
264+
}
265+
259266
/**
260267
* Insert text at the specified position into the editor
261268
* @param text the text to insert

plugs/index/command.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ export async function reindexSpace() {
3030
console.log("Queing", files.length, "pages to be indexed.");
3131
// Queue all file names to be indexed
3232
await mq.batchSend("indexQueue", files.map((file) => file.name));
33+
await editor.showProgress(0, "index");
3334

3435
// Now let's wait for the processing to finish
3536
let queueStats = await mq.getQueueStats("indexQueue");
3637
while (queueStats.queued > 0 || queueStats.processing > 0) {
3738
await sleep(500);
3839
queueStats = await mq.getQueueStats("indexQueue");
40+
await editor.showProgress(
41+
100 - Math.round(queueStats.queued / files.length * 100),
42+
"index",
43+
);
3944
}
4045
// And notify the user
4146
console.log("Indexing completed!");
47+
await editor.showProgress();
4248
}
4349

4450
export async function processIndexQueue(messages: MQMessage[]) {

web/client.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class Client {
287287
// "sync:success" is called with a number of operations only from syncSpace(), not from syncing individual pages
288288
this.fullSyncCompleted = true;
289289

290-
console.log("Full sync completed");
290+
console.log("[sync]", "Full sync completed");
291291

292292
// A full sync just completed
293293
if (!initialSync) {
@@ -297,9 +297,9 @@ export class Client {
297297
);
298298
} else { // initialSync
299299
console.log(
300+
"[sync]",
300301
"Initial sync completed, now need to do a full space index to ensure all pages are indexed using any custom indexers",
301302
);
302-
console.log("Enabling eventing on space primitives");
303303
this.space.spacePrimitives.enablePageEvents = true;
304304
this.clientSystem.ensureFullIndex().catch(
305305
console.error,
@@ -309,7 +309,7 @@ export class Client {
309309
}
310310
if (operations) {
311311
// Likely initial sync so let's show visually that we're synced now
312-
this.showProgress(100);
312+
this.showProgress(100, "sync");
313313
}
314314

315315
this.ui.viewDispatch({ type: "sync-change", syncSuccess: true });
@@ -329,6 +329,7 @@ export class Client {
329329
this.eventHook.addLocalListener("sync:progress", (status: SyncStatus) => {
330330
this.showProgress(
331331
Math.round(status.filesProcessed / status.totalFiles * 100),
332+
"sync",
332333
);
333334
});
334335

@@ -825,10 +826,11 @@ export class Client {
825826
// Progress circle handling
826827
private progressTimeout?: number;
827828

828-
showProgress(progressPerc: number) {
829+
showProgress(progressPercentage?: number, progressType?: "sync" | "index") {
829830
this.ui.viewDispatch({
830831
type: "set-progress",
831-
progressPerc,
832+
progressPercentage,
833+
progressType,
832834
});
833835
if (this.progressTimeout) {
834836
clearTimeout(this.progressTimeout);
@@ -839,7 +841,7 @@ export class Client {
839841
type: "set-progress",
840842
});
841843
},
842-
10000,
844+
5000,
843845
);
844846
}
845847

web/client_system.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,21 @@ export class ClientSystem {
279279
const currentIndexVersion = await this.getCurrentIndexVersion();
280280

281281
console.info(
282+
"[index]",
282283
"Current space index version",
283284
currentIndexVersion,
284-
"index ongoing",
285+
"index ongoing?",
285286
this.indexOngoing,
286287
);
287288

288289
if (currentIndexVersion !== desiredIndexVersion && !this.indexOngoing) {
289290
console.info(
291+
"[index]",
290292
"Performing a full space reindex, this could take a while...",
291293
);
292294
this.indexOngoing = true;
293295
await this.system.invokeFunction("index.reindexSpace", []);
294-
console.info("Full space index complete.");
296+
console.info("[index]", "Full space index complete.");
295297
await this.markFullSpaceIndexComplete();
296298
this.indexOngoing = false;
297299
// Let's load space scripts again, which probably weren't loaded before

web/components/top_bar.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function TopBar({
2727
actionButtons,
2828
darkMode,
2929
vimMode,
30-
progressPerc,
30+
progressPercentage,
31+
progressType,
3132
completer,
3233
lhs,
3334
onClick,
@@ -43,7 +44,8 @@ export function TopBar({
4344
notifications: Notification[];
4445
darkMode?: boolean;
4546
vimMode: boolean;
46-
progressPerc?: number;
47+
progressPercentage?: number;
48+
progressType?: string;
4749
onRename: (newName?: string) => Promise<void>;
4850
onClick: () => void;
4951
completer: (context: CompletionContext) => Promise<CompletionResult | null>;
@@ -104,17 +106,17 @@ export function TopBar({
104106
</div>
105107
)}
106108
<div className="sb-sync-progress">
107-
{progressPerc !== undefined &&
109+
{progressPercentage !== undefined &&
108110
(
109111
<div
110112
className="progress-wrapper"
111-
title={`Sync Progress: ${progressPerc}%`}
113+
title={`${progressType} progress: ${progressPercentage}%`}
112114
>
113115
<div
114116
className="progress-bar"
115-
style={`background: radial-gradient(closest-side, var(--top-background-color) 79%, transparent 80% 100%), conic-gradient(var(--button-color) ${progressPerc}%, var(--button-background-color) 0);`}
117+
style={`background: radial-gradient(closest-side, var(--top-background-color) 79%, transparent 80% 100%), conic-gradient(var(--progress-${progressType}-color) ${progressPercentage}%, var(--progress-background-color) 0);`}
116118
>
117-
{progressPerc}
119+
{progressPercentage}
118120
</div>
119121
</div>
120122
)}

web/editor_ui.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ export class MainUI {
279279
isLoading={viewState.isLoading}
280280
vimMode={viewState.uiOptions.vimMode}
281281
darkMode={viewState.uiOptions.darkMode}
282-
progressPerc={viewState.progressPerc}
282+
progressPercentage={viewState.progressPercentage}
283+
progressType={viewState.progressType}
283284
completer={client.miniEditorComplete.bind(client)}
284285
onClick={() => {
285286
if (!client.isDocumentEditor()) {

web/reducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ export default function reducer(
274274
case "set-progress":
275275
return {
276276
...state,
277-
progressPerc: action.progressPerc,
277+
progressPercentage: action.progressPercentage,
278+
progressType: action.progressType,
278279
};
279280
}
280281
}

web/styles/theme.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ html {
6262

6363
--text-field-background-color: var(--button-background-color);
6464

65+
--progress-background-color: #eee;
66+
--progress-sync-color: black;
67+
--progress-index-color: rgb(176, 0, 59);
68+
6569
--action-button-background-color: transparent;
6670
--action-button-color: #292929;
6771
--action-button-hover-color: #0772be;
@@ -201,6 +205,10 @@ html[data-theme="dark"] {
201205
--primary-button-color: var(--ui-accent-contrast-color);
202206
--primary-button-border-color: transparent;
203207

208+
--progress-background-color: #555;
209+
--progress-sync-color: white;
210+
--progress-index-color: yellow;
211+
204212
--text-field-background-color: var(--button-background-color);
205213

206214
--action-button-background-color: transparent;

web/syscalls/editor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ export function editorSyscalls(client: Client): SysCallMapping {
222222
client.editorView.dispatch({});
223223
});
224224
},
225+
"editor.showProgress": (
226+
_ctx,
227+
progressPercentage?: number,
228+
progressType?: "sync" | "index",
229+
) => {
230+
client.showProgress(progressPercentage, progressType);
231+
},
225232
"editor.insertAtPos": (
226233
_ctx,
227234
text: string,

web/type.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export type AppViewState = {
3434
showCommandPaletteContext?: string;
3535
unsavedChanges: boolean;
3636
syncFailures: number; // Reset everytime a sync succeeds
37-
progressPerc?: number;
37+
38+
// Progress tracker
39+
progressPercentage?: number; // Used to show progress circle
40+
progressType?: string; // Used for styling
41+
3842
panels: { [key: string]: PanelConfig };
3943
commands: Map<string, AppCommand>;
4044
notifications: Notification[];
@@ -158,4 +162,8 @@ export type Action =
158162
}
159163
| { type: "hide-confirm" }
160164
| { type: "set-ui-option"; key: string; value: any }
161-
| { type: "set-progress"; progressPerc?: number };
165+
| {
166+
type: "set-progress";
167+
progressPercentage?: number;
168+
progressType?: string;
169+
};

0 commit comments

Comments
 (0)