Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/content manager: show a placeholder message while the list is initializing
Adorian Doran0eae96fd097d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f8cf3222f4..14f83de74e 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2609,6 +2609,7 @@"category_icon_packs": "Icon Packs","category_templates": "Templates","category_snippets": "Snippets",+ "loading": "Retrieving content...","sort_order": "Sort by","sort_by_name": "Name","sort_by_date_created": "Creation date",diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.css b/apps/client/src/widgets/type_widgets/options/content_manager.cssindex 4de0e24572..6d6020d5f7 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager.css+++ b/apps/client/src/widgets/type_widgets/options/content_manager.css@@ -9,6 +9,10 @@white-space: nowrap;}+.content-manager-loading {+ opacity: 0.7;+}+.content-manager-items {display: flex;flex-direction: column;diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsxindex 1f31cf156a..64bf7ed989 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx@@ -21,7 +21,6 @@ import OptionsSection from "./components/OptionsSection";export default function ContentManagerSettings() {const [ sortOrder, setSortOrder ] = useTriliumOption("contentManagerSortOrder");const categories = useCategoryNotes(sortOrder as ContentSortOrder);- const isEmpty = categories.every(({ notes }) => !notes.length);return (<>@@ -32,21 +31,39 @@ export default function ContentManagerSettings() {<SortOrderSelect currentValue={sortOrder} onChange={(newValue) => void setSortOrder(newValue)} /></div>- {isEmpty- ? <NoItems icon="bx bx-package" text={t("content_manager.no_items")}>- <small>{t("content_manager.no_items_hint")}</small>- </NoItems>- : categories.map(({ category, notes }) => notes.length > 0 && (- <OptionsSection key={category.id} title={t(category.titleKey)}>- <div className="content-manager-items">- {notes.map((note) => (- <p key={note.noteId} className="content-manager-item">- <NoteLink notePath={note.noteId} showNoteIcon showNotePath />- </p>- ))}- </div>- </OptionsSection>- ))}+ <CategoryList categories={categories} />+ </>+ );+}++function CategoryList({ categories }: { categories: CategoryNotes[] | null }) {+ if (!categories) {+ return <p className="content-manager-loading">{t("content_manager.loading")}</p>;+ }++ const populated = categories.filter(({ notes }) => notes.length > 0);++ if (!populated.length) {+ return (+ <NoItems icon="bx bx-package" text={t("content_manager.no_items")}>+ <small>{t("content_manager.no_items_hint")}</small>+ </NoItems>+ );+ }++ return (+ <>+ {populated.map(({ category, notes }) => (+ <OptionsSection key={category.id} title={t(category.titleKey)}>+ <div className="content-manager-items">+ {notes.map((note) => (+ <p key={note.noteId} className="content-manager-item">+ <NoteLink notePath={note.noteId} showNoteIcon showNotePath />+ </p>+ ))}+ </div>+ </OptionsSection>+ ))}</>);}@@ -85,8 +102,9 @@ interface CategoryNotes {* be noticeable.*/function useCategoryNotes(sortOrder: ContentSortOrder) {- const [ categories, setCategories ] = useState<CategoryNotes[]>(() =>- CONTENT_CATEGORIES.map((category) => ({ category, notes: [] })));+ // `null` until the first search resolves, so the page can tell "still loading" apart from+ // "genuinely nothing to show" instead of flashing the empty state on every open.+ const [ categories, setCategories ] = useState<CategoryNotes[] | null>(null);const refresh = useCallback(async () => {setCategories(await Promise.all(CONTENT_CATEGORIES.map(async (category) => ({