feat(collections): add label to show archived notes

This commit is contained in:
Elian Doran 2025-09-12 17:57:58 +03:00
parent f300b6c8a2
commit d1e57e85b6
No known key found for this signature in database
2 changed files with 8 additions and 7 deletions

View File

@ -256,20 +256,20 @@ export default class FNote {
return this.children;
}
async getSubtreeNoteIds() {
async getSubtreeNoteIds(includeArchived = false) {
let noteIds: (string | string[])[] = [];
for (const child of await this.getChildNotes()) {
if (child.isArchived) continue;
if (child.isArchived && !includeArchived) continue;
noteIds.push(child.noteId);
noteIds.push(await child.getSubtreeNoteIds());
noteIds.push(await child.getSubtreeNoteIds(includeArchived));
}
return noteIds.flat();
}
async getSubtreeNotes() {
const noteIds = await this.getSubtreeNoteIds();
return (await this.froca.getNotes(noteIds)).filter(note => !note.isArchived)
return (await this.froca.getNotes(noteIds));
}
async getChildNotes() {

View File

@ -1,5 +1,5 @@
import { allViewTypes, ViewModeProps, ViewTypeOptions } from "./interface";
import { useNoteContext, useNoteLabel, useTriliumEvent } from "../react/hooks";
import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useTriliumEvent } from "../react/hooks";
import FNote from "../../entities/fnote";
import "./NoteList.css";
import { ListView, GridView } from "./legacy/ListOrGridView";
@ -109,6 +109,7 @@ function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) {
const [ noteIds, setNoteIds ] = useState<string[]>([]);
const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");
async function refreshNoteIds() {
if (!note) {
@ -118,12 +119,12 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |
setNoteIds(note.getChildNoteIds());
} else {
console.log("Refreshed note IDs");
setNoteIds(await note.getSubtreeNoteIds());
setNoteIds(await note.getSubtreeNoteIds(includeArchived));
}
}
// Refresh on note switch.
useEffect(() => { refreshNoteIds() }, [ note ]);
useEffect(() => { refreshNoteIds() }, [ note, includeArchived ]);
// Refresh on alterations to the note subtree.
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {