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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: grid layout for search results
Louis Beaumont18e8f131586c
diff --git a/openrewind/app/search/page.tsx b/openrewind/app/search/page.tsxindex 9d0c11702..cf60b76f0 100644--- a/openrewind/app/search/page.tsx+++ b/openrewind/app/search/page.tsx@@ -125,18 +125,15 @@ function SearchPage() {) : null}{isSearching && searchResults.length === 0 && (- <div- className="flex flex-row gap-4 p-8 overflow-hidden"- style={{ direction: "rtl" }}- >- {Array.from({ length: 8 }).map((_, index) => (+ <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4 p-4">+ {Array.from({ length: 15 }).map((_, index) => (<SkeletonCard key={`skeleton-${index}`} />))}</div>)}{querys.query && !(searchResults.length === 0) ? (- <div className="h-64 flex items-end">+ <div className="flex-1 overflow-hidden"><ImageGrid searchResult={searchResults} pageRef={pageRef} /></div>) : (diff --git a/openrewind/components/rewind/image-card.tsx b/openrewind/components/rewind/image-card.tsxindex cff31230e..5ae91cc58 100644--- a/openrewind/components/rewind/image-card.tsx+++ b/openrewind/components/rewind/image-card.tsx@@ -8,12 +8,14 @@ import { Loader2 } from "lucide-react";import { useKeywordParams } from "@/lib/hooks/use-keyword-params";export const SkeletonCard = () => (- <div className="flex flex-col shrink-0 w-56 h-full relative overflow-hidden rounded-lg bg-card border border-border shadow-sm">- <div className="aspect-video bg-neutral-200 animate-pulse" />- <div className="p-3 space-y-2" style={{ direction: "ltr" }}>- <div className="h-4 bg-neutral-200 rounded animate-pulse" />- <div className="h-3 bg-neutral-200 rounded animate-pulse w-3/4" />- <div className="h-3 bg-neutral-200 rounded animate-pulse w-1/2" />+ <div className="flex flex-col relative overflow-hidden bg-card border border-border">+ <div className="p-2 border-b border-border">+ <div className="h-3 bg-muted animate-pulse w-32" />+ </div>+ <div className="aspect-video bg-muted animate-pulse" />+ <div className="p-2 space-y-1 border-t border-border">+ <div className="h-4 bg-muted animate-pulse w-20" />+ <div className="h-3 bg-muted animate-pulse w-32" /></div></div>);@@ -38,13 +40,13 @@ export const ImageGrid = ({if (!container) return;if (searchResults.length === 0) return;- const scrollPosition = Math.abs(container.scrollLeft);- const scrollWidth = container.scrollWidth;- const clientWidth = container.clientWidth;+ const scrollPosition = container.scrollTop;+ const scrollHeight = container.scrollHeight;+ const clientHeight = container.clientHeight;- const scrollPercentage = scrollPosition / (scrollWidth - clientWidth);+ const scrollPercentage = scrollPosition / (scrollHeight - clientHeight);- if (scrollPercentage > 0.6) {+ if (scrollPercentage > 0.7) {searchKeywords(query ?? "", {offset: searchResult.length,limit: 20,@@ -70,156 +72,93 @@ export const ImageGrid = ({};}, [checkScrollAndFetch]);- const handleScroll = useMemo(- () =>- throttle(- (e: WheelEvent) => {- const isWithinAiPanel =- e.target instanceof Node &&- document.getElementById("ai-response")?.contains(e.target);-- if (isWithinAiPanel) return;-- e.preventDefault();- e.stopPropagation();-- const scrollIntensity = Math.abs(e.deltaY);- const direction = -Math.sign(e.deltaY);- const limitIndexChange = 5;-- const indexChange =- direction *- Math.min(- limitIndexChange,- Math.ceil(Math.pow(scrollIntensity / 50, 1.5)),- );-- requestAnimationFrame(() => {- const newIndex = Math.min(- Math.max(0, Math.floor(currentResultIndex + indexChange)),- searchResult.length - 1,- );- setCurrentResultIndex(newIndex);- });- },- 16,- { leading: true, trailing: false },- ),- [searchResult.length, currentResultIndex, setCurrentResultIndex],- );-+ // Keyboard navigation for griduseEffect(() => {- const preventScroll = (e: WheelEvent) => {- const isWithinSettingsDialog = document- .querySelector('[data-settings-dialog]')- ?.contains(e.target as Node);- const isWithinDialog = document- .querySelector('[role="dialog"]')- ?.contains(e.target as Node);-- if (!isWithinSettingsDialog && !isWithinDialog) {- e.preventDefault();+ const handleKeyDown = (e: KeyboardEvent) => {+ if (searchResult.length === 0) return;++ const cols = 5; // Match lg:grid-cols-5+ let newIndex = currentResultIndex;++ switch (e.key) {+ case "ArrowRight":+ newIndex = Math.min(currentResultIndex + 1, searchResult.length - 1);+ break;+ case "ArrowLeft":+ newIndex = Math.max(currentResultIndex - 1, 0);+ break;+ case "ArrowDown":+ newIndex = Math.min(currentResultIndex + cols, searchResult.length - 1);+ break;+ case "ArrowUp":+ newIndex = Math.max(currentResultIndex - cols, 0);+ break;+ default:+ return;}- };-- document.addEventListener("wheel", preventScroll, { passive: false });- return () => document.removeEventListener("wheel", preventScroll);- }, []);-- useEffect(() => {- const container = containerRef.current;- if (container && pageRef.current) {- pageRef.current.addEventListener("wheel", handleScroll, {- passive: false,- });- }- return () => {- if (container && pageRef.current) {- pageRef.current.removeEventListener("wheel", handleScroll);+ if (newIndex !== currentResultIndex) {+ e.preventDefault();+ setCurrentResultIndex(newIndex);}};- }, [handleScroll]);-- useEffect(() => {- const container = containerRef.current;- if (!container || !searchResult[currentResultIndex]) return;-- const currentTimestamp = searchResult[currentResultIndex].timestamp;- const currentElement = container.querySelector(- `[data-timestamp="${currentTimestamp}"]`,- );-- if (!currentElement) return;- requestAnimationFrame(() => {- const containerWidth = container.clientWidth;- const elementWidth = (currentElement as HTMLElement).offsetWidth;- const elementOffsetRight =- container.scrollWidth -- ((currentElement as HTMLElement).offsetLeft + elementWidth);-- const centerPosition =- elementOffsetRight - (containerWidth - elementWidth) / 2;-- container.scrollTo({- left: container.scrollWidth - containerWidth - centerPosition,- behavior: "smooth",- });- });- }, [currentResultIndex, searchResult]);+ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [currentResultIndex, searchResult.length, setCurrentResultIndex]);return (<div className="relative w-full h-full"><divref={containerRef}- className="sticky inset-0 w-full overflow-x-auto overflow-y-hidden select-none scrollbar-hide"- style={{ direction: "rtl" }}+ className="w-full overflow-y-auto overflow-x-hidden select-none scrollbar-hide">- <div className="inline-flex min-w-full px-[50vw]">- <div className="flex flex-row gap-4 p-8" style={{ direction: "rtl" }}>- {searchResult.map((result, index) => (- <div- key={result.frame_id}- data-timestamp={result.timestamp}- className={cn(- "group flex flex-col shrink-0 w-56 h-full relative overflow-hidden rounded-lg bg-card border border-border shadow-sm transition-all duration-300 hover:shadow-md snap-center cursor-pointer",- currentResultIndex === index && "ring-2 ring-blue-500",- )}- onClick={() => setCurrentResultIndex(index)}- style={{ direction: "ltr" }}- >- <div className="aspect-video overflow-hidden flex-1 relative">- <div className="absolute inset-0 flex items-center justify-center bg-neutral-100">- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />- </div>- <img- src={`http://localhost:3030/frames/${result.frame_id}`}- alt={`${result.app_name} - ${result.window_name}`}- className="h-full w-full object-cover transition-transform duration-300 relative group-hover:scale-105"- loading="lazy"- draggable={false}- onLoad={(e) => {- (e.target as HTMLImageElement).style.opacity = "1";- }}- style={{ opacity: 0 }}- />- </div>- <div className="p-3 space-y-1">- <p className="text-sm font-medium text-neutral-900 truncate">- {result.app_name}- </p>- <p className="text-xs text-neutral-500 truncate">- {result.window_name}- </p>- <p className="text-xs text-neutral-400">- {format(new Date(result.timestamp), "PPp")}- </p>+ <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4 p-4">+ {searchResult.map((result, index) => (+ <div+ key={result.frame_id}+ data-timestamp={result.timestamp}+ className={cn(+ "group flex flex-col relative overflow-hidden bg-card border border-border transition-all duration-200 cursor-pointer",+ currentResultIndex === index && "ring-1 ring-foreground",+ )}+ onClick={() => setCurrentResultIndex(index)}+ >+ <div className="text-xs font-mono text-muted-foreground p-2 border-b border-border">+ {format(new Date(result.timestamp), "yyyy-MM-dd HH:mm:ss")}+ </div>+ <div className="aspect-video overflow-hidden relative">+ <div className="absolute inset-0 flex items-center justify-center bg-muted">+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" /></div>+ <img+ src={`http://localhost:3030/frames/${result.frame_id}`}+ alt={`${result.app_name} - ${result.window_name}`}+ className="h-full w-full object-cover transition-transform duration-200 relative group-hover:scale-105"+ loading="lazy"+ draggable={false}+ onLoad={(e) => {+ (e.target as HTMLImageElement).style.opacity = "1";+ }}+ style={{ opacity: 0 }}+ /></div>- ))}- </div>+ <div className="p-2 space-y-1 border-t border-border">+ <p className="text-sm font-mono truncate">+ {result.app_name}+ </p>+ <p className="text-xs font-mono text-muted-foreground truncate">+ {result.window_name}+ </p>+ </div>+ </div>+ ))}</div>+ {isSearching && (+ <div className="flex justify-center py-4">+ <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />+ </div>+ )}</div></div>);