mobile: add useNoteLocked hook

This commit is contained in:
Ammar Ahmed
2024-03-11 14:33:25 +05:00
committed by Abdullah Atta
parent c106db2422
commit 1c0a8e00a6

View File

@@ -120,6 +120,40 @@ export const useDBItem = <T extends keyof ItemTypeKey>(
];
};
export const useNoteLocked = (noteId: string | undefined) => {
const [locked, setLocked] = useState(false);
useEffect(() => {
if (!noteId) return;
db.vaults
.itemExists({
type: "note",
id: noteId
})
.then((exists) => {
setLocked(exists);
});
const sub = eSubscribeEvent(eDBItemUpdate, (id: string) => {
if (id === noteId) {
db.vaults
.itemExists({
type: "note",
id: noteId
})
.then((exists) => {
setLocked(exists);
});
}
});
return () => {
sub?.unsubscribe();
};
}, [noteId]);
return locked;
};
export const useTotalNotes = (type: "notebook" | "tag" | "color") => {
const [totalNotesById, setTotalNotesById] = useState<{
[id: string]: number;