forked from Disciplr-Org/Disciplr-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotesDraft.ts
More file actions
53 lines (44 loc) · 1.01 KB
/
Copy pathnotesDraft.ts
File metadata and controls
53 lines (44 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const NOTES_DRAFT_PREFIX = 'validation-notes-draft:';
function draftKey(taskId: string): string {
return `${NOTES_DRAFT_PREFIX}${taskId}`;
}
function storageAvailable(): Storage | null {
if (typeof window === 'undefined') {
return null;
}
try {
return window.localStorage;
} catch {
return null;
}
}
export function readNotesDraft(taskId: string | undefined): string {
if (!taskId) {
return '';
}
try {
return storageAvailable()?.getItem(draftKey(taskId)) ?? '';
} catch {
return '';
}
}
export function writeNotesDraft(taskId: string | undefined, notes: string): void {
if (!taskId) {
return;
}
try {
storageAvailable()?.setItem(draftKey(taskId), notes);
} catch {
// Draft persistence is best-effort; verification must keep working.
}
}
export function clearNotesDraft(taskId: string | undefined): void {
if (!taskId) {
return;
}
try {
storageAvailable()?.removeItem(draftKey(taskId));
} catch {
// Draft cleanup is best-effort.
}
}