Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖

feat(ui): open search near the top with recent guides and library-style rows

Luis Ortiz4ceb7480de33
diff --git a/packages/ui/src/search/components/KeyboardHints.tsx b/packages/ui/src/search/components/KeyboardHints.tsx
deleted file mode 100644
index c43baf9..0000000
--- a/packages/ui/src/search/components/KeyboardHints.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { i18n } from '@mimik/core/env';
-
-const hints = [
- { key: '↑↓', labelKey: 'keyboard_navigate' as const },
- { key: '↵', labelKey: 'keyboard_open' as const },
- { key: 'esc', labelKey: 'keyboard_close' as const },
-];
-
-export function KeyboardHints() {
- return (
- <div className="flex items-center gap-3 px-4 py-2 border-t border-border">
- {hints.map((h) => (
- <span key={h.key} className="contents">
- <span className="text-[9px] font-semibold px-1.5 py-0.5 rounded bg-lavender text-foreground">{h.key}</span>
- <span className="text-[10px] text-purple">{i18n.t(h.labelKey)}</span>
- </span>
- ))}
- </div>
- );
-}
diff --git a/packages/ui/src/search/components/MatchText.tsx b/packages/ui/src/search/components/MatchText.tsx
new file mode 100644
index 0000000..0ba7961
--- /dev/null
+++ b/packages/ui/src/search/components/MatchText.tsx
@@ -0,0 +1,12 @@
+export function MatchText({ text, query }: { text: string; query: string }) {
+ const start = query ? text.toLowerCase().indexOf(query.toLowerCase()) : -1;
+ if (start < 0) return <>{text}</>;
+ const end = start + query.length;
+ return (
+ <>
+ {text.slice(0, start)}
+ <mark className="rounded-[3px] bg-lavender px-px text-foreground">{text.slice(start, end)}</mark>
+ {text.slice(end)}
+ </>
+ );
+}
diff --git a/packages/ui/src/search/components/SearchModal.tsx b/packages/ui/src/search/components/SearchModal.tsx
index ab3caa1..ed7b968 100644
--- a/packages/ui/src/search/components/SearchModal.tsx
+++ b/packages/ui/src/search/components/SearchModal.tsx
@@ -1,19 +1,19 @@
import { i18n } from '@mimik/core/env';
-import { getGuideDomain, getGuides } from '@mimik/core/guides/service';
-import type { Guide } from '@mimik/core/guides/types';
-import { Search, X } from 'lucide-react';
-import { useCallback, useEffect, useRef, useState } from 'react';
+import { getGuides } from '@mimik/core/guides/service';
+import type { Guide, Screenshot } from '@mimik/core/guides/types';
+import { Search } from 'lucide-react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
+import { MascotIcon } from '../../common/components/MascotIcon';
import { Dialog, DialogPortal } from '../../components/ui/dialog';
import { Input } from '../../components/ui/input';
+import { loadCardData } from '../../library/lib/load-card-data';
+import type { GuidePlace } from '../../library/types';
import { navigate } from '../../navigation/lib/navigate';
import { useFullview } from '../../stores/use-fullview';
-import { KeyboardHints } from './KeyboardHints';
import { SearchResults } from './SearchResults';
-interface GuideResult {
- guide: Guide;
- domain: string;
-}
+const RECENT = 5;
+const SHOWN = 8;
export function SearchModal() {
const {
@@ -27,21 +27,12 @@ export function SearchModal() {
}));
const [query, setQuery] = useState('');
- const [results, setResults] = useState<GuideResult[]>([]);
+ const [guides, setGuides] = useState<Guide[] | null>(null);
+ const [thumbnails, setThumbnails] = useState(new Map<string, Screenshot>());
+ const [places, setPlaces] = useState(new Map<string, GuidePlace>());
const [selected, setSelected] = useState(0);
const inputRef = useRef<HTMLInputElement>(null);
- const loadResults = useCallback(async () => {
- const guides = await getGuides();
- const withFavicons = await Promise.all(
- guides.map(async (guide) => {
- const domain = await getGuideDomain(guide.id);
- return { guide, domain: domain || '' };
- }),
- );
- setResults(withFavicons);
- }, []);
-
useEffect(() => {
const handler = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
@@ -54,15 +45,33 @@ export function SearchModal() {
}, [toggleSearch]);
useEffect(() => {
- if (open) {
- setQuery('');
- setSelected(0);
- loadResults();
- setTimeout(() => inputRef.current?.focus(), 50);
- }
- }, [open, loadResults]);
+ if (!open) return;
+ setQuery('');
+ setSelected(0);
+ setGuides(null);
+ void getGuides().then(setGuides);
+ setTimeout(() => inputRef.current?.focus(), 50);
+ }, [open]);
- const filtered = query ? results.filter((r) => r.guide.title.toLowerCase().includes(query.toLowerCase())) : [];
+ const shown = useMemo(() => {
+ if (!guides) return [];
+ const needle = query.trim().toLowerCase();
+ if (!needle) return guides.slice(0, RECENT);
+ return guides.filter((g) => g.title.toLowerCase().includes(needle)).slice(0, SHOWN);
+ }, [guides, query]);
+
+ useEffect(() => {
+ if (!shown.length) return;
+ let live = true;
+ void loadCardData(shown).then((data) => {
+ if (!live) return;
+ setThumbnails(data.thumbnails);
+ setPlaces(data.places);
+ });
+ return () => {
+ live = false;
+ };
+ }, [shown]);
const handleSelect = useCallback(
(guideId: string) => {
@@ -76,32 +85,41 @@ export function SearchModal() {
(e: React.KeyboardEvent) => {
if (e.key === 'ArrowDown') {
e.preventDefault();
- setSelected((s) => Math.min(s + 1, filtered.length - 1));
+ setSelected((s) => Math.min(s + 1, shown.length - 1));
} else if (e.key === 'ArrowUp') {
e.preventDefault();
setSelected((s) => Math.max(s - 1, 0));
} else if (e.key === 'Enter') {
e.preventDefault();
- if (filtered[selected]) handleSelect(filtered[selected].guide.id);
+ if (shown[selected]) handleSelect(shown[selected].id);
}
},
- [filtered, selected, handleSelect],
+ [shown, selected, handleSelect],
);
+ const typed = query.trim();
+ const heading = !typed
+ ? i18n.t('search_recent')
+ : shown.length === 1
+ ? i18n.t('search_resultsOne')
+ : i18n.t('search_results', [String(shown.length)]);
+
return (
<Dialog open={open} onOpenChange={setSearchOpen} modal={false}>
<DialogPortal>
<div
- className="fixed inset-0 z-50 flex items-center justify-center bg-black/20 backdrop-blur-sm"
+ className="fixed inset-0 z-50 flex items-start justify-center bg-primary/25 px-4 pt-[12vh]"
onClick={() => setSearchOpen(false)}
>
<div
- className="w-full max-w-[640px] rounded-xl overflow-hidden bg-card shadow-lg"
+ role="dialog"
+ aria-label={i18n.t('fullview_searchPlaceholder')}
+ className="w-full max-w-[620px] overflow-hidden rounded-2xl border border-border bg-card shadow-[0_30px_80px_rgba(30,27,75,0.3)]"
onClick={(e) => e.stopPropagation()}
onKeyDown={handleKeyDown}
>
- <div className="flex items-center gap-3 px-4 py-3 border-b border-border">
- <Search size={18} className="text-accent shrink-0" />
+ <div className="flex h-[58px] items-center gap-3 border-b border-secondary px-[18px]">
+ <Search size={19} className="shrink-0 text-foreground" />
<Input
ref={inputRef}
placeholder={i18n.t('fullview_searchPlaceholder')}
@@ -110,41 +128,32 @@ export function SearchModal() {
setQuery(e.target.value);
setSelected(0);
}}
- className="flex-1 text-[15px] font-medium border-0 bg-transparent p-0 shadow-none focus-visible:ring-0 h-auto text-foreground"
+ className="h-auto flex-1 border-0 bg-transparent p-0 text-base font-medium text-foreground shadow-none focus-visible:ring-0"
/>
- {query && (
- <button onClick={() => setQuery('')} className="p-0.5 rounded text-purple">
- <X size={14} />
- </button>
- )}
</div>
- {filtered.length > 0 ? (
- <div className="max-h-[320px] overflow-y-auto py-1">
+ {guides && shown.length > 0 && (
+ <div className="px-2 pt-1.5 pb-2">
+ <p className="px-3 pt-2.5 pb-1 text-[11px] font-semibold text-muted-foreground">{heading}</p>
<SearchResults
- results={filtered}
- query={query}
+ guides={shown}
+ thumbnails={thumbnails}
+ places={places}
+ query={typed}
selected={selected}
onSelect={handleSelect}
onHover={setSelected}
/>
</div>
- ) : (
- <div className="flex flex-col items-center py-7 gap-2.5">
- <svg width="56" height="52" viewBox="0 0 56 52" fill="none">
- <rect x="8" y="16" width="40" height="24" rx="3" fill="#1E1B4B" />
- <path d="M8 16 L8 11 Q8 3, 28 3 Q48 3, 48 11 L48 16 Z" fill="#3730A3" />
- <rect x="8" y="15" width="40" height="1.5" fill="#C7D2FE" />
- <path d="M17 27 Q20.5 23 24 27" stroke="#C7D2FE" strokeWidth="2" fill="none" strokeLinecap="round" />
- <path d="M22 36 Q28 40 34 36" stroke="#C7D2FE" strokeWidth="1.5" fill="none" strokeLinecap="round" />
- <circle cx="38" cy="24" r="8" stroke="#1E1B4B" strokeWidth="2" fill="none" />
- <line x1="44" y1="30" x2="50" y2="36" stroke="#1E1B4B" strokeWidth="2.5" strokeLinecap="round" />
- <circle cx="38" cy="24" r="3" fill="#C7D2FE" />
- <circle cx="39" cy="23.5" r="1" fill="#1E1B4B" />
- </svg>
- <span className="text-[13px] font-medium text-muted-foreground/50">{i18n.t('search_startTyping')}</span>
+ )}
+ {guides && shown.length === 0 && (
+ <div className="flex flex-col items-center gap-2 px-6 pt-7 pb-8 text-center">
+ <MascotIcon size={52} pose="lookaway" />
+ <p className="text-sm font-semibold text-foreground">
+ {typed ? i18n.t('search_noMatch', [typed]) : i18n.t('search_noGuidesYet')}
+ </p>
+ {typed && <p className="text-[12.5px] text-muted-foreground">{i18n.t('search_noMatchHint')}</p>}
</div>
)}
- <KeyboardHints />
</div>
</div>
</DialogPortal>
diff --git a/packages/ui/src/search/components/SearchResults.tsx b/packages/ui/src/search/components/SearchResults.tsx
index 2a863cb..b3ca4d5 100644
--- a/packages/ui/src/search/components/SearchResults.tsx
+++ b/packages/ui/src/search/components/SearchResults.tsx
@@ -1,91 +1,78 @@
import { i18n } from '@mimik/core/env';
-import type { Guide } from '@mimik/core/guides/types';
+import type { Guide, Screenshot } from '@mimik/core/guides/types';
+import { CornerDownLeft } from 'lucide-react';
import { FaviconImg } from '../../common/components/FaviconImg';
import { formatDateShort } from '../../common/lib/format-date-short';
-
-interface GuideResult {
- guide: Guide;
- domain: string;
-}
+import { ScreenshotView } from '../../guide/components/ScreenshotView';
+import { MimikEyes } from '../../library/components/MimikEyes';
+import type { GuidePlace } from '../../library/types';
+import { MatchText } from './MatchText';
interface SearchResultsProps {
- results: GuideResult[];
+ guides: Guide[];
+ thumbnails: Map<string, Screenshot>;
+ places: Map<string, GuidePlace>;
query: string;
selected: number;
onSelect: (guideId: string) => void;
onHover: (index: number) => void;
}
-export function SearchResults({ results, query, selected, onSelect, onHover }: SearchResultsProps) {
- if (results.length === 0) {
- return (
- <div className="py-8 text-center">
- <p className="text-sm text-purple">
- {query ? i18n.t('search_noMatchingGuides') : i18n.t('search_noGuidesYet')}
- </p>
- </div>
- );
- }
-
+export function SearchResults({ guides, thumbnails, places, query, selected, onSelect, onHover }: SearchResultsProps) {
return (
<>
- {results.map((r, i) => (
- <div
- key={r.guide.id}
- className="flex items-center gap-3 cursor-pointer transition-colors"
- style={
- i === selected
- ? { background: 'var(--color-primary)', borderRadius: '8px', margin: '0 6px', padding: '10px 12px' }
- : { padding: '10px 16px' }
- }
- onClick={() => onSelect(r.guide.id)}
- onMouseEnter={() => onHover(i)}
- >
- <div
- className="w-5 h-5 rounded flex items-center justify-center text-[8px] font-bold shrink-0 overflow-hidden"
- style={
- i === selected
- ? {
- background: 'rgba(199,210,254,0.15)',
- border: '1px solid rgba(199,210,254,0.2)',
- color: 'var(--color-lavender)',
- }
- : {
- background: 'var(--color-secondary)',
- border: '1px solid var(--color-border)',
- color: 'var(--color-muted-foreground)',
- }
- }
+ {guides.map((guide, i) => {
+ const thumb = thumbnails.get(guide.id);
+ const place = places.get(guide.id);
+ const active = i === selected;
+ const steps = guide.stepIds.length;
+ return (
+ <button
+ key={guide.id}
+ type="button"
+ onClick={() => onSelect(guide.id)}
+ onMouseEnter={() => onHover(i)}
+ className={`flex w-full items-center gap-3 rounded-[10px] px-2.5 py-2 text-left ${active ? 'bg-secondary' : ''}`}
>
- <FaviconImg domain={r.domain} size={14} />
- </div>
- <div className="flex-1 min-w-0">
- <p
- className="text-[13px] font-medium truncate"
- style={{ color: i === selected ? 'var(--color-lavender)' : 'var(--color-foreground)' }}
- >
- {r.guide.title}
- </p>
- {r.guide.description && (
- <p
- className="text-[11px] mt-0.5 line-clamp-1"
- style={{ color: i === selected ? 'rgba(199,210,254,0.6)' : 'var(--color-muted-foreground)' }}
- >
- {r.guide.description}
+ <div className="relative aspect-video w-16 shrink-0 overflow-hidden rounded-md border border-border [&_svg]:h-auto [&_svg]:w-9">
+ {thumb ? (
+ <ScreenshotView
+ screenshot={thumb}
+ alt=""
+ crop
+ cache
+ frameRatio={16 / 9}
+ className="!rounded-none !border-0"
+ readOnly
+ />
+ ) : (
+ <MimikEyes />
+ )}
+ </div>
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
+ <p className="truncate text-[13.5px] font-semibold text-foreground">
+ <MatchText text={guide.title || i18n.t('fullview_untitledGuide')} query={query} />
+ </p>
+ <p className="flex min-w-0 items-center gap-1.5 text-[11.5px] text-muted-foreground">
+ {place && (
+ <>
+ <FaviconImg domain={place.name} size={14} letterOnly={place.kind === 'app'} />
+ <span className="truncate">{place.name}</span>
+ <span>&middot;</span>
+ </>
+ )}
+ <span className="shrink-0">
+ {steps === 1
+ ? i18n.t('fullview_stepCount', ['1'])
+ : i18n.t('fullview_stepCountPlural', [String(steps)])}{' '}
+ &middot; {formatDateShort(guide.updatedAt)}
+ </span>
</p>
- )}
- <p
- className="text-[10px] mt-0.5"
- style={{ color: i === selected ? 'rgba(199,210,254,0.6)' : 'var(--color-muted-foreground)' }}
- >
- {r.guide.stepIds.length !== 1
- ? i18n.t('fullview_stepCountPlural', [String(r.guide.stepIds.length)])
- : i18n.t('fullview_stepCount', [String(r.guide.stepIds.length)])}{' '}
- · {formatDateShort(r.guide.updatedAt)}
- </p>
- </div>
- </div>
- ))}
+ </div>
+ {active && <CornerDownLeft size={15} className="shrink-0 text-foreground" />}
+ </button>
+ );
+ })}
</>
);
}
diff --git a/src/locales/de.yml b/src/locales/de.yml
index 87fc3b3..27d6158 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -286,15 +286,13 @@ sort:
listView: Listenansicht
search:
- startTyping: Tippe, um eine Anleitung zu finden
- noMatchingGuides: Keine passenden Anleitungen
+ recent: "Zuletzt"
+ results: "$1 Anleitungen"
+ resultsOne: "1 Anleitung"
+ noMatch: "Keine Anleitung passt zu „$1“"
+ noMatchHint: "Versuche ein Wort aus dem Titel der Anleitung."
noGuidesYet: Noch keine Anleitungen
-keyboard:
- navigate: navigieren
- open: öffnen
- close: schließen
-
confirmDelete:
title: "Anleitung löschen?"
message: Diese Anleitung wird endgültig gelöscht. Das kann nicht rückgängig gemacht werden.
diff --git a/src/locales/en.yml b/src/locales/en.yml
index 0f1fe81..aa450cb 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -286,15 +286,13 @@ sort:
listView: List view
search:
- startTyping: Start typing to find a guide
- noMatchingGuides: No matching guides
+ recent: "Recent"
+ results: "$1 guides"
+ resultsOne: "1 guide"
+ noMatch: "No guides match “$1”"
+ noMatchHint: "Try a word from the guide's title."
noGuidesYet: No guides yet
-keyboard:
- navigate: navigate
- open: open
- close: close
-
confirmDelete:
title: "Delete guide?"
message: This will permanently delete this guide. This cannot be undone.
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 9af9afe..457c3e1 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -286,15 +286,13 @@ sort:
listView: Ver lista
search:
- startTyping: Escribe para buscar una guía
- noMatchingGuides: No se encontraron guías
+ recent: "Recientes"
+ results: "$1 guías"
+ resultsOne: "1 guía"
+ noMatch: "Ninguna guía coincide con «$1»"
+ noMatchHint: "Prueba con una palabra del título de la guía."
noGuidesYet: No hay guías todavía
-keyboard:
- navigate: navegar
- open: abrir
- close: cerrar
-
confirmDelete:
title: "¿Eliminar esta guía?"
message: Se eliminará de forma permanente. No hay vuelta atrás.
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index bb319a3..2f6355f 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -286,15 +286,13 @@ sort:
listView: Vue liste
search:
- startTyping: Tapez pour trouver un guide
- noMatchingGuides: Aucun guide trouvé
+ recent: "Récents"
+ results: "$1 guides"
+ resultsOne: "1 guide"
+ noMatch: "Aucun guide ne correspond à « $1 »"
+ noMatchHint: "Essayez un mot du titre du guide."
noGuidesYet: Pas encore de guide
-keyboard:
- navigate: naviguer
- open: ouvrir
- close: fermer
-
confirmDelete:
title: "Supprimer ce guide ?"
message: "Il sera supprimé définitivement. Pas de retour en arrière."
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index ec33371..f6c500a 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -286,15 +286,13 @@ sort:
listView: Ver em lista
search:
- startTyping: "Digite para buscar um guia"
- noMatchingGuides: Nenhum guia encontrado
+ recent: "Recentes"
+ results: "$1 guias"
+ resultsOne: "1 guia"
+ noMatch: "Nenhum guia corresponde a “$1”"
+ noMatchHint: "Tente uma palavra do título do guia."
noGuidesYet: Nenhum guia ainda
-keyboard:
- navigate: navegar
- open: abrir
- close: fechar
-
confirmDelete:
title: "Excluir este guia?"
message: Vai ser excluído de vez. Não tem como desfazer.
diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml
index 96ff859..c307e70 100644
--- a/src/locales/zh-CN.yml
+++ b/src/locales/zh-CN.yml
@@ -286,15 +286,13 @@ sort:
listView: 列表视图
search:
- startTyping: 开始输入以查找指南
- noMatchingGuides: 没有匹配的指南
+ recent: "最近"
+ results: "$1 个指南"
+ resultsOne: "1 个指南"
+ noMatch: "没有与“$1”匹配的指南"
+ noMatchHint: "试试指南标题中的某个词。"
noGuidesYet: 暂无指南
-keyboard:
- navigate: 导航
- open: 打开
- close: 关闭
-
confirmDelete:
title: "删除指南?"
message: 这将永久删除该指南,且无法撤销。