mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-10 16:21:22 +00:00
fix(notes): dedupe quota failure toasts during autosave
Debounced draft flushes can hit QuotaExceededError repeatedly; rate-limit the error toast so users are not spammed every 300ms. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
This commit is contained in:
2 files changed
+12
-4
No files matched your search
@@ -288,6 +288,7 @@ export const useVaultState = () => {
|
||||
const hostsRef = useRef<Host[]>([]);
|
||||
const notesRef = useRef<VaultNote[]>([]);
|
||||
const noteGroupsRef = useRef<string[]>([]);
|
||||
const notesPersistFailureNotifiedAtRef = useRef(0);
|
||||
customGroupsRef.current = customGroups;
|
||||
managedSourcesRef.current = managedSources;
|
||||
hostsRef.current = hosts;
|
||||
@@ -611,10 +612,15 @@ export const useVaultState = () => {
|
||||
setNotes(cleaned);
|
||||
publishNotesSnapshot({ notes: cleaned, noteGroups: noteGroupsRef.current });
|
||||
if (!persisted) {
|
||||
notify.error(
|
||||
"Notes could not be saved. Free some local storage space and try again.",
|
||||
"Notes",
|
||||
);
|
||||
const now = Date.now();
|
||||
// Debounced autosave can hit quota repeatedly; avoid toast spam.
|
||||
if (now - notesPersistFailureNotifiedAtRef.current > 10_000) {
|
||||
notesPersistFailureNotifiedAtRef.current = now;
|
||||
notify.error(
|
||||
"Notes could not be saved. Free some local storage space and try again.",
|
||||
"Notes",
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -50,4 +50,6 @@ test("useVaultState updateNotes surfaces storage write failures", () => {
|
||||
assert.match(source, /notify\.error/);
|
||||
assert.match(source, /!persisted|persisted === false/);
|
||||
assert.match(source, /return false/);
|
||||
assert.match(source, /notesPersistFailureNotifiedAtRef/);
|
||||
assert.match(source, /10_000/);
|
||||
});
|
||||
Reference in new issue
Block a user