fix(notes): activate workspace filtering
This commit is contained in:
parent
55bbc107a0
commit
ab159501fa
@ -9,6 +9,7 @@ import type { NoteSummary, WorkspaceSummary } from "@/lib/types";
|
||||
export default function WorkspacesPage() {
|
||||
const [notes, setNotes] = useState<NoteSummary[]>([]);
|
||||
const [workspaces, setWorkspaces] = useState<WorkspaceSummary[]>([]);
|
||||
const [query, setQuery] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@ -52,6 +53,31 @@ export default function WorkspacesPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const filteredWorkspaces = useMemo(() => {
|
||||
const normalized = query.trim().toLowerCase();
|
||||
if (!normalized) {
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
return workspaces.filter((workspace) => {
|
||||
const workspaceNotes = notesByWorkspace.get(workspace.id) ?? [];
|
||||
|
||||
return (
|
||||
workspace.name.toLowerCase().includes(normalized) ||
|
||||
workspace.description.toLowerCase().includes(normalized) ||
|
||||
workspace.owner.toLowerCase().includes(normalized) ||
|
||||
workspace.visibility.toLowerCase().includes(normalized) ||
|
||||
workspace.tags.some((tag) => tag.toLowerCase().includes(normalized)) ||
|
||||
workspaceNotes.some(
|
||||
(note) =>
|
||||
note.title.toLowerCase().includes(normalized) ||
|
||||
note.excerpt.toLowerCase().includes(normalized) ||
|
||||
note.tags.some((tag) => tag.toLowerCase().includes(normalized)),
|
||||
)
|
||||
);
|
||||
});
|
||||
}, [notesByWorkspace, query, workspaces]);
|
||||
|
||||
return (
|
||||
<AppShell
|
||||
title="Workspaces"
|
||||
@ -78,6 +104,8 @@ export default function WorkspacesPage() {
|
||||
aria-label="Filter workspaces"
|
||||
className="input-shell"
|
||||
placeholder="Filter workspaces by owner, tag, or visibility"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
<div style={{ display: "flex", gap: "var(--ml-space-2)", flexWrap: "wrap" }}>
|
||||
<span className="badge">owner:any</span>
|
||||
@ -94,7 +122,7 @@ export default function WorkspacesPage() {
|
||||
</section>
|
||||
) : null}
|
||||
<section style={{ display: "grid", gap: "var(--ml-space-4)" }}>
|
||||
{workspaces.map((workspace) => {
|
||||
{filteredWorkspaces.map((workspace) => {
|
||||
const workspaceNotes = notesByWorkspace.get(workspace.id) ?? [];
|
||||
return (
|
||||
<article key={workspace.id} className="surface-card" style={{ padding: "var(--ml-space-6)", display: "grid", gap: "var(--ml-space-4)" }}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user