import type { Note } from "$lib/model"; import { extractWikilinkTitles } from "$lib/wikilink"; import { A } from "@solidjs/router"; import type { Component } from "solid-js"; import { createMemo, For, Show } from "solid-js"; type FilterType = "all" | "linked" | "orphaned"; type NotesSidebarProps = { notes: Note[]; selectedTag?: string; selectedFilter?: FilterType; onTagSelect?: (tag: string | undefined) => void; onFilterSelect?: (filter: FilterType) => void; }; type TagCount = { tag: string; count: number }; export const NotesSidebar: Component = (props) => { const tagCounts = createMemo(() => { const counts = new Map(); props.notes.forEach((note) => { note.tags.forEach((tag) => { counts.set(tag, (counts.get(tag) ?? 0) + 1); }); }); return Array.from(counts.entries()).map(([tag, count]) => ({ tag, count })).sort((a, b) => b.count - a.count); }); const recentNotes = createMemo(() => { return [...props.notes].sort((a, b) => { const dateA = a.updated_at ?? a.created_at ?? ""; const dateB = b.updated_at ?? b.created_at ?? ""; return dateB.localeCompare(dateA); }).slice(0, 5); }); const linkedCount = createMemo(() => { return props.notes.filter((note) => extractWikilinkTitles(note.body).length > 0).length; }); const orphanedCount = createMemo(() => { return props.notes.filter((note) => extractWikilinkTitles(note.body).length === 0).length; }); const filterButtonClass = (filter: FilterType) => { const isActive = props.selectedFilter === filter; return `px-3 py-1.5 text-sm rounded-md transition-colors ${ isActive ? "bg-blue-500/20 text-blue-400 font-medium" : "text-slate-400 hover:text-white hover:bg-slate-800" }`; }; return ( ); };