feat(save_indicator): indicate errors

This commit is contained in:
Elian Doran 2026-01-02 23:22:33 +02:00
parent 62af66b5ae
commit 5f14861682
No known key found for this signature in database
2 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import type { SaveState } from "../components/note_context";
import { getErrorMessage } from "./utils";
type Callback = () => Promise<void> | void;
@ -38,7 +39,8 @@ export default class SpacedUpdate {
this.stateCallback?.("saved");
} catch (e) {
this.changed = true;
this.stateCallback?.("error");
logError(getErrorMessage(e));
throw e;
}
}
@ -68,15 +70,20 @@ export default class SpacedUpdate {
this.updateInterval = interval;
}
triggerUpdate() {
async triggerUpdate() {
if (!this.changed) {
return;
}
if (Date.now() - this.lastUpdated > this.updateInterval) {
this.stateCallback?.("saving");
this.updater();
this.stateCallback?.("saved");
try {
await this.updater();
this.stateCallback?.("saved");
} catch (e) {
this.stateCallback?.("error");
logError(getErrorMessage(e));
}
this.lastUpdated = Date.now();
this.changed = false;
} else {

View File

@ -141,7 +141,7 @@ function SaveStatusBadge() {
return (
<Badge
className={clsx("save-status-badge", saveState)}
className={clsx("save-status-badge", saveState.state)}
icon={icon}
text={title}
tooltip={tooltip}