export const useGetActiveNotes = (label?: string) => {
return useLiveInfiniteQuery(
(q) => {
if (label) {
return q
.from({ notes: notesCollection })
.where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
.where(({ notes }) => inArray(label, notes.labels))
.orderBy(({ notes }) => notes.updated, "desc");
} else {
return q
.from({ notes: notesCollection })
.where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
.orderBy(({ notes }) => notes.updated, "desc");
}
},
{
pageSize: MAX_PAGE_SIZE,
getNextPageParam: (lastPage, allPages) =>
lastPage.length === MAX_PAGE_SIZE ? allPages.length : undefined,
},
[label]
);
};
export const useGetActiveNotes = (label?: string) => {
return useLiveInfiniteQuery(
(q) => {
if (label) {
return q
.from({ notes: notesCollection })
.where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
.where(({ notes }) => inArray(label, notes.labels))
.orderBy(({ notes }) => notes.updated, "desc");
} else {
return q
.from({ notes: notesCollection })
.where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
.orderBy(({ notes }) => notes.updated, "desc");
}
},
{
pageSize: MAX_PAGE_SIZE,
getNextPageParam: (lastPage, allPages) =>
lastPage.length === MAX_PAGE_SIZE ? allPages.length : undefined,
},
[label]
);
};