Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(app): add search, tag filters, and sorting to memories table

Louis Beaumonte4a7c7d648d5
diff --git a/apps/screenpipe-app-tauri/components/settings/memories-section.tsx b/apps/screenpipe-app-tauri/components/settings/memories-section.tsx
index 937322338..d007f668b 100644
--- a/apps/screenpipe-app-tauri/components/settings/memories-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/memories-section.tsx
@@ -8,7 +8,18 @@ import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { useToast } from "@/components/ui/use-toast";
import { Skeleton } from "@/components/ui/skeleton";
-import { Trash2, Check, X, Loader2, ExternalLink, Copy } from "lucide-react";
+import {
+ Trash2,
+ Check,
+ X,
+ Loader2,
+ ExternalLink,
+ Copy,
+ Search,
+ ArrowUpDown,
+ Tag,
+} from "lucide-react";
+import { Input } from "@/components/ui/input";
interface MemoryRecord {
id: number;
@@ -72,6 +83,9 @@ function MemoriesSkeleton() {
);
}
+type SortField = "created_at" | "importance";
+type SortDir = "desc" | "asc";
+
export function MemoriesSection() {
const { toast } = useToast();
const [memories, setMemories] = useState<MemoryRecord[]>([]);
@@ -85,6 +99,37 @@ export function MemoriesSection() {
const scrollRef = useRef<HTMLDivElement>(null);
const loadingMoreRef = useRef(false);
+ // search, filter & sort
+ const [searchQuery, setSearchQuery] = useState("");
+ const [debouncedQuery, setDebouncedQuery] = useState("");
+ const [activeTag, setActiveTag] = useState<string | null>(null);
+ const [sortField, setSortField] = useState<SortField>("created_at");
+ const [sortDir, setSortDir] = useState<SortDir>("desc");
+ const [allTags, setAllTags] = useState<string[]>([]);
+
+ // debounce search
+ useEffect(() => {
+ const timer = setTimeout(() => setDebouncedQuery(searchQuery), 300);
+ return () => clearTimeout(timer);
+ }, [searchQuery]);
+
+ const sortMemories = useCallback(
+ (data: MemoryRecord[]) => {
+ return [...data].sort((a, b) => {
+ const aVal =
+ sortField === "created_at"
+ ? new Date(a.created_at).getTime()
+ : a.importance;
+ const bVal =
+ sortField === "created_at"
+ ? new Date(b.created_at).getTime()
+ : b.importance;
+ return sortDir === "desc" ? bVal - aVal : aVal - bVal;
+ });
+ },
+ [sortField, sortDir],
+ );
+
const fetchPage = useCallback(
async (offset: number, append: boolean) => {
if (offset === 0) setLoading(true);
@@ -96,19 +141,42 @@ export function MemoriesSection() {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10_000);
+ const params = new URLSearchParams({
+ limit: String(PAGE_SIZE),
+ offset: String(offset),
+ });
+ if (debouncedQuery) params.set("q", debouncedQuery);
+ if (activeTag) params.set("tags", activeTag);
const res = await fetch(
- `http://localhost:3030/memories?limit=${PAGE_SIZE}&offset=${offset}`,
+ `http://localhost:3030/memories?${params}`,
{ signal: controller.signal },
);
clearTimeout(timeout);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data: MemoryListResponse = await res.json();
- const sorted = data.data.sort(
- (a, b) =>
- new Date(b.created_at).getTime() -
- new Date(a.created_at).getTime(),
+ const sorted = sortMemories(data.data);
+
+ // collect all unique tags
+ if (offset === 0) {
+ const tags = new Set<string>();
+ data.data.forEach((m) => m.tags.forEach((t) => tags.add(t)));
+ setAllTags((prev) => {
+ const merged = new Set([...prev, ...tags]);
+ return Array.from(merged).sort();
+ });
+ } else {
+ data.data.forEach((m) =>
+ m.tags.forEach((t) =>
+ setAllTags((prev) =>
+ prev.includes(t) ? prev : [...prev, t].sort(),
+ ),
+ ),
+ );
+ }
+
+ setMemories((prev) =>
+ append ? sortMemories([...prev, ...sorted]) : sorted,
);
- setMemories((prev) => (append ? [...prev, ...sorted] : sorted));
setTotal(data.pagination.total);
} catch (err) {
if (offset === 0) {
@@ -124,12 +192,18 @@ export function MemoriesSection() {
loadingMoreRef.current = false;
}
},
- [toast],
+ [toast, debouncedQuery, activeTag, sortMemories],
);
+ // fetch on mount + refetch when search/tag filter changes
useEffect(() => {
fetchPage(0, false);
- }, [fetchPage]);
+ }, [debouncedQuery, activeTag]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ // re-sort locally when sort changes (no refetch needed)
+ useEffect(() => {
+ setMemories((prev) => (prev.length > 0 ? sortMemories(prev) : prev));
+ }, [sortField, sortDir, sortMemories]);
// infinite scroll via IntersectionObserver
useEffect(() => {
@@ -180,7 +254,19 @@ export function MemoriesSection() {
facts and preferences the AI has learned from your activity
</p>
- <div className="flex items-center gap-2">
+ {/* search bar */}
+ <div className="relative">
+ <Search className="absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground" />
+ <Input
+ placeholder="search memories..."
+ value={searchQuery}
+ onChange={(e) => setSearchQuery(e.target.value)}
+ className="pl-8 h-8 text-sm"
+ />
+ </div>
+
+ {/* filters row */}
+ <div className="flex items-center gap-2 flex-wrap">
{loading ? (
<Skeleton className="h-6 w-12 rounded-full" />
) : total > 0 ? (
@@ -188,17 +274,94 @@ export function MemoriesSection() {
{total}
</Badge>
) : null}
+
+ {/* tag filter pills */}
+ {allTags.length > 0 && (
+ <>
+ <div className="w-px h-4 bg-border" />
+ {allTags.slice(0, 8).map((tag) => (
+ <button
+ key={tag}
+ onClick={() =>
+ setActiveTag((prev) => (prev === tag ? null : tag))
+ }
+ className={`inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded-full border transition-colors ${
+ activeTag === tag
+ ? "bg-foreground text-background border-foreground"
+ : "border-border text-muted-foreground hover:bg-muted"
+ }`}
+ >
+ <Tag className="h-2.5 w-2.5" />
+ {tag}
+ </button>
+ ))}
+ </>
+ )}
+
+ {/* sort toggle */}
+ <div className="ml-auto flex items-center gap-1">
+ <button
+ onClick={() => {
+ if (sortField === "created_at") {
+ setSortDir((d) => (d === "desc" ? "asc" : "desc"));
+ } else {
+ setSortField("created_at");
+ setSortDir("desc");
+ }
+ }}
+ className={`inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded border transition-colors ${
+ sortField === "created_at"
+ ? "bg-foreground/10 border-foreground/20"
+ : "border-border text-muted-foreground hover:bg-muted"
+ }`}
+ >
+ <ArrowUpDown className="h-2.5 w-2.5" />
+ {sortField === "created_at" && sortDir === "desc"
+ ? "newest"
+ : sortField === "created_at" && sortDir === "asc"
+ ? "oldest"
+ : "date"}
+ </button>
+ <button
+ onClick={() => {
+ if (sortField === "importance") {
+ setSortDir((d) => (d === "desc" ? "asc" : "desc"));
+ } else {
+ setSortField("importance");
+ setSortDir("desc");
+ }
+ }}
+ className={`inline-flex items-center gap-1 px-2 py-0.5 text-[10px] rounded border transition-colors ${
+ sortField === "importance"
+ ? "bg-foreground/10 border-foreground/20"
+ : "border-border text-muted-foreground hover:bg-muted"
+ }`}
+ >
+ <ArrowUpDown className="h-2.5 w-2.5" />
+ {sortField === "importance" && sortDir === "desc"
+ ? "important"
+ : sortField === "importance" && sortDir === "asc"
+ ? "least"
+ : "importance"}
+ </button>
+ </div>
</div>
{loading ? (
<MemoriesSkeleton />
) : memories.length === 0 ? (
<div className="text-sm text-muted-foreground py-8 space-y-2">
- <p>no memories yet</p>
- <p className="text-xs">
- memories are created when the AI learns something about you during
- chat conversations. try asking the AI to remember something.
+ <p>
+ {debouncedQuery || activeTag
+ ? "no memories match your search"
+ : "no memories yet"}
</p>
+ {!debouncedQuery && !activeTag && (
+ <p className="text-xs">
+ memories are created when the AI learns something about you during
+ chat conversations. try asking the AI to remember something.
+ </p>
+ )}
</div>
) : (
<div