π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
feat: library sorting, pagination, and grid default
Luis Ortizd87f53a878ba
diff --git a/src/ui/fullview/LibraryContent.tsx b/src/ui/fullview/LibraryContent.tsxindex af042b5..b3ded74 100644--- a/src/ui/fullview/LibraryContent.tsx+++ b/src/ui/fullview/LibraryContent.tsx@@ -1,5 +1,13 @@-import { FileText, LayoutGrid, LayoutList } from 'lucide-react';-import { useCallback, useEffect, useState } from 'react';+import {+ ArrowDownWideNarrow,+ ChevronDown,+ ChevronLeft,+ ChevronRight,+ FileText,+ LayoutGrid,+ LayoutList,+} from 'lucide-react';+import { useCallback, useEffect, useRef, useState } from 'react';import {type GuideChangeEvent,getFirstScreenshot,@@ -12,9 +20,8 @@ import {softDeleteGuide,toggleStar,} from '@/core/guides/service';-import type { Screenshot } from '@/core/guides/types';+import type { Guide, Screenshot } from '@/core/guides/types';import { useFullview } from '@/stores/fullview';-import { Button } from '@/ui/components/ui/button';import GuideGridView from './components/GuideGridView';import GuideListView from './components/GuideListView';@@ -22,16 +29,38 @@ interface LibraryContentProps {category: 'all' | 'starred' | 'trash';}-const titles: Record<string, string> = { all: 'All Guides', starred: 'Starred', trash: 'Trash' };const emptyMessages: Record<string, string> = {all: 'No guides yet. Start a capture from the Mimik extension.',starred: 'No starred guides. Star a guide to find it quickly.',trash: 'Trash is empty.',};+type SortKey = 'recent' | 'oldest' | 'alpha' | 'steps';+const sortLabels: Record<SortKey, string> = {+ recent: 'Recent first',+ oldest: 'Oldest first',+ alpha: 'A β Z',+ steps: 'Most steps',+};++const PAGE_SIZE = 9;++function sortGuides(guides: Guide[], sort: SortKey): Guide[] {+ const sorted = [...guides];+ switch (sort) {+ case 'recent':+ return sorted.sort((a, b) => b.updatedAt - a.updatedAt);+ case 'oldest':+ return sorted.sort((a, b) => a.updatedAt - b.updatedAt);+ case 'alpha':+ return sorted.sort((a, b) => a.title.localeCompare(b.title));+ case 'steps':+ return sorted.sort((a, b) => b.stepIds.length - a.stepIds.length);+ }+}+export default function LibraryContent({ category }: LibraryContentProps) {const {- guides,setGuides,updateGuide,setThumbnails,@@ -39,7 +68,6 @@ export default function LibraryContent({ category }: LibraryContentProps) {setLibraryLoading: setLoading,setCounts,} = useFullview((s) => ({- guides: s.guides,setGuides: s.setGuides,updateGuide: s.updateGuide,setThumbnails: s.setThumbnails,@@ -49,8 +77,22 @@ export default function LibraryContent({ category }: LibraryContentProps) {}));const [display, setDisplay] = useState<'list' | 'grid'>(- () => (localStorage.getItem('mimik-display') as 'list' | 'grid') || 'list',+ () => (localStorage.getItem('mimik-display') as 'list' | 'grid') || 'grid',);+ const [sort, setSort] = useState<SortKey>('recent');+ const [sortOpen, setSortOpen] = useState(false);+ const [page, setPage] = useState(0);+ const sortRef = useRef<HTMLDivElement>(null);++ const allGuidesRef = useRef<Guide[]>([]);++ useEffect(() => {+ const handler = (e: MouseEvent) => {+ if (sortRef.current && !sortRef.current.contains(e.target as Node)) setSortOpen(false);+ };+ document.addEventListener('mousedown', handler);+ return () => document.removeEventListener('mousedown', handler);+ }, []);const refreshCounts = useCallback(async () => {const [all, starred, trashed] = await Promise.all([getGuides(), getStarredGuides(), getTrashedGuides()]);@@ -63,7 +105,12 @@ export default function LibraryContent({ category }: LibraryContentProps) {setCounts({ all: all.length, starred: starred.length, trash: trashed.length });const current = category === 'starred' ? starred : category === 'trash' ? trashed : all;- setGuides(current);+ allGuidesRef.current = current;++ const sorted = sortGuides(current, sort);+ const paged = sorted.slice(0, PAGE_SIZE);+ setGuides(paged);+ setPage(0);const thumbMap = new Map<string, Screenshot>();for (const guide of current.slice(0, 20)) {@@ -72,7 +119,7 @@ export default function LibraryContent({ category }: LibraryContentProps) {}setThumbnails(thumbMap);setLoading(false);- }, [category, setCounts, setGuides, setThumbnails, setLoading]);+ }, [category, sort, setCounts, setGuides, setThumbnails, setLoading]);useEffect(() => {loadGuides();@@ -91,6 +138,34 @@ export default function LibraryContent({ category }: LibraryContentProps) {[refreshCounts, loadGuides, updateGuide],);+ const totalPages = Math.ceil(allGuidesRef.current.length / PAGE_SIZE);++ const applyPage = useCallback(+ async (newPage: number) => {+ const sorted = sortGuides(allGuidesRef.current, sort);+ const start = newPage * PAGE_SIZE;+ const paged = sorted.slice(start, start + PAGE_SIZE);+ setGuides(paged);+ setPage(newPage);++ const thumbMap = new Map<string, Screenshot>();+ for (const guide of paged) {+ const screenshot = await getFirstScreenshot(guide.id);+ if (screenshot) thumbMap.set(guide.id, screenshot);+ }+ setThumbnails(thumbMap);+ },+ [sort, setGuides, setThumbnails],+ );++ const handleSort = (key: SortKey) => {+ setSort(key);+ setSortOpen(false);+ const sorted = sortGuides(allGuidesRef.current, key);+ setGuides(sorted.slice(0, PAGE_SIZE));+ setPage(0);+ };+const toggleDisplay = () => {const next = display === 'list' ? 'grid' : 'list';setDisplay(next);@@ -99,7 +174,7 @@ export default function LibraryContent({ category }: LibraryContentProps) {const handleStar = async (e: React.MouseEvent, id: string) => {e.stopPropagation();- const guide = guides.find((g) => g.id === id);+ const guide = allGuidesRef.current.find((g) => g.id === id);if (guide) updateGuide(id, { starred: !guide.starred });await toggleStar(id);await refreshCounts();@@ -121,23 +196,50 @@ export default function LibraryContent({ category }: LibraryContentProps) {await loadGuides();};+ const showPagination = !loading && allGuidesRef.current.length > PAGE_SIZE;+return (<div>- <div className="flex items-center justify-between mb-6">- <h2 className="text-2xl font-bold text-foreground">{titles[category]}</h2>- <Button- variant="outline"- size="icon-sm"+ <div className="flex items-center justify-end gap-2 mb-4">+ <div ref={sortRef} className="relative">+ <button+ onClick={() => setSortOpen(!sortOpen)}+ className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground px-3 py-1.5 rounded-lg border border-border bg-card hover:border-amber hover:text-warm transition-colors"+ >+ <ArrowDownWideNarrow size={13} />+ {sortLabels[sort]}+ <ChevronDown size={10} className="ml-0.5" />+ </button>+ {sortOpen && (+ <div className="absolute right-0 top-full mt-1 bg-card border border-border rounded-lg shadow-lg py-1 z-10 min-w-[140px]">+ {(Object.keys(sortLabels) as SortKey[]).map((key) => (+ <button+ key={key}+ onClick={() => handleSort(key)}+ className={`w-full text-left text-xs font-medium px-3 py-2 transition-colors ${+ sort === key+ ? 'text-foreground bg-secondary'+ : 'text-muted-foreground hover:bg-secondary/50 hover:text-foreground'+ }`}+ >+ {sortLabels[key]}+ </button>+ ))}+ </div>+ )}+ </div>+ <buttononClick={toggleDisplay}+ className="flex items-center justify-center w-8 h-8 rounded-lg border border-border bg-card text-muted-foreground hover:border-amber hover:text-warm transition-colors"title={display === 'list' ? 'Grid view' : 'List view'}>- {display === 'list' ? <LayoutGrid size={16} /> : <LayoutList size={16} />}- </Button>+ {display === 'list' ? <LayoutGrid size={15} /> : <LayoutList size={15} />}+ </button></div>{loading ? (<p className="text-sm py-12 text-center text-warm">Loading...</p>- ) : guides.length === 0 ? (+ ) : allGuidesRef.current.length === 0 ? (<div className="text-center py-20"><FileText size={40} className="mx-auto mb-3 text-border" /><p className="text-lg text-muted-foreground">{emptyMessages[category]}</p>@@ -153,6 +255,28 @@ export default function LibraryContent({ category }: LibraryContentProps) {) : (<GuideGridView />)}++ {showPagination && (+ <div className="flex items-center justify-center gap-3 mt-6">+ <button+ onClick={() => applyPage(page - 1)}+ disabled={page === 0}+ className="flex items-center justify-center w-8 h-8 rounded-lg border border-border bg-card text-muted-foreground hover:border-amber hover:text-warm transition-colors disabled:opacity-30 disabled:pointer-events-none"+ >+ <ChevronLeft size={15} />+ </button>+ <span className="text-xs font-medium text-muted-foreground">+ {page + 1} / {totalPages}+ </span>+ <button+ onClick={() => applyPage(page + 1)}+ disabled={page >= totalPages - 1}+ className="flex items-center justify-center w-8 h-8 rounded-lg border border-border bg-card text-muted-foreground hover:border-amber hover:text-warm transition-colors disabled:opacity-30 disabled:pointer-events-none"+ >+ <ChevronRight size={15} />+ </button>+ </div>+ )}</div>);}