Fix notes workspace filters for string-based boolean fields
This commit is contained in:
+22
-9
@@ -282,6 +282,18 @@
|
||||
return [];
|
||||
}
|
||||
|
||||
function toBoolFlag(value) {
|
||||
if (typeof value === 'boolean') return value;
|
||||
if (typeof value === 'number') return value !== 0;
|
||||
if (typeof value === 'string') {
|
||||
const v = value.trim().toLowerCase();
|
||||
if (!v) return false;
|
||||
if (['false', '0', 'no', 'off', 'null', 'undefined'].includes(v)) return false;
|
||||
if (['true', '1', 'yes', 'on'].includes(v)) return true;
|
||||
}
|
||||
return Boolean(value);
|
||||
}
|
||||
|
||||
function buildNotePayload() {
|
||||
const title = titleInput.value.trim() || 'Untitled';
|
||||
const bodyPlain = bodyInput.value.trim();
|
||||
@@ -340,15 +352,15 @@
|
||||
}
|
||||
|
||||
function passFilter(note) {
|
||||
if (Boolean(note?.delete)) return false;
|
||||
if (toBoolFlag(note?.delete)) return false;
|
||||
|
||||
const wantHidden = hiddenMode.value === 'hidden';
|
||||
const isHidden = Boolean(note?.hidden);
|
||||
const isHidden = toBoolFlag(note?.hidden);
|
||||
if (wantHidden !== isHidden) return false;
|
||||
|
||||
if (currentFilter === 'myshared' && !(isMine(note) && Boolean(note?.shared))) return false;
|
||||
if (currentFilter === 'myshared' && !(isMine(note) && toBoolFlag(note?.shared))) return false;
|
||||
if (currentFilter === 'sharedwithme' && !isSharedWithCurrentUser(note)) return false;
|
||||
if (currentFilter === 'job' && !(Boolean(note?.job_note) || noteType(note) === 'job')) return false;
|
||||
if (currentFilter === 'job' && !(toBoolFlag(note?.job_note) || noteType(note) === 'job')) return false;
|
||||
if (currentFilter === 'manager' && noteType(note) !== 'manager') return false;
|
||||
if (currentFilter === 'personal' && noteType(note) !== 'personal') return false;
|
||||
|
||||
@@ -382,8 +394,9 @@
|
||||
notesList.innerHTML = filtered.map((note) => {
|
||||
const mine = isMine(note);
|
||||
const sharedWithMe = isSharedWithCurrentUser(note);
|
||||
const badge = sharedWithMe ? 'Shared w/ me' : note.shared ? 'Shared by me' : 'Private';
|
||||
const tone = sharedWithMe ? 'text-cyan-300' : note.shared ? 'text-emerald-300' : 'text-slate-300';
|
||||
const sharedByMe = toBoolFlag(note?.shared);
|
||||
const badge = sharedWithMe ? 'Shared w/ me' : sharedByMe ? 'Shared by me' : 'Private';
|
||||
const tone = sharedWithMe ? 'text-cyan-300' : sharedByMe ? 'text-emerald-300' : 'text-slate-300';
|
||||
const preview = String(note.body_plain || '').replace(/\s+/g, ' ').trim().slice(0, 160);
|
||||
const selected = selectedNote?.id === note.id ? 'active' : '';
|
||||
return `
|
||||
@@ -438,7 +451,7 @@
|
||||
saveBtn.disabled = false;
|
||||
hideBtn.disabled = false;
|
||||
deleteBtn.disabled = false;
|
||||
hideBtn.textContent = Boolean(note.hidden) ? 'Unhide' : 'Hide';
|
||||
hideBtn.textContent = toBoolFlag(note.hidden) ? 'Unhide' : 'Hide';
|
||||
}
|
||||
|
||||
async function updatePbStatus() {
|
||||
@@ -523,7 +536,7 @@
|
||||
await ensurePocketBaseClient();
|
||||
ensureLoggedIn();
|
||||
const payload = buildNotePayload();
|
||||
payload.hidden = Boolean(selectedNote.hidden);
|
||||
payload.hidden = toBoolFlag(selectedNote.hidden);
|
||||
const record = await pb.collection(NOTES_COLLECTION).update(selectedNote.id, payload);
|
||||
await loadNotes();
|
||||
selectNote(record);
|
||||
@@ -536,7 +549,7 @@
|
||||
await ensurePocketBaseClient();
|
||||
ensureLoggedIn();
|
||||
const updated = await pb.collection(NOTES_COLLECTION).update(selectedNote.id, {
|
||||
hidden: !Boolean(selectedNote.hidden),
|
||||
hidden: !toBoolFlag(selectedNote.hidden),
|
||||
});
|
||||
await loadNotes();
|
||||
selectNote(updated);
|
||||
|
||||
Reference in New Issue
Block a user