11'use client'
22
3- import { type ReactNode , useState } from 'react'
4- import { Chip , cn , toast } from '@sim/emcn'
3+ import type { ReactNode } from 'react'
4+ import { Chip , cn } from '@sim/emcn'
55import { Clock } from '@sim/emcn/icons'
66import { inter } from '@/app/_styles/fonts/inter/inter'
7+ import { useSearchLandingHistory } from '@/app/o/[organizationId]/components/use-search-landing-history'
78import { SourceCard } from '@/app/workspace/[workspaceId]/home/components/message-content/components/source-card'
8- import { useClearSearchHistory , useSearchHistory } from '@/hooks/queries/search-history'
99
1010interface SearchLandingHistoryProps {
1111 organizationId : string
@@ -21,13 +21,8 @@ export function SearchLandingHistory({
2121 onSearch,
2222 children,
2323} : SearchLandingHistoryProps ) {
24- const history = useSearchHistory ( organizationId )
25- const clear = useClearSearchHistory ( organizationId , userId )
26- const [ selection , setSelection ] = useState < 'sources' | 'queries' | null > ( null )
27- const data = history . isError ? undefined : history . data
28- const sources = data ?. sources . slice ( 0 , 5 ) ?? [ ]
29- const queries = data ?. queries . slice ( 0 , 5 ) ?? [ ]
30- const selected = selection ?? ( sources . length > 0 ? 'sources' : 'queries' )
24+ const { failed, retrying, retry, sources, queries, selected, setSelection, clear, isClearing } =
25+ useSearchLandingHistory ( organizationId , userId )
3126 return (
3227 < div className = { cn ( 'relative w-full min-w-0' , inter . className ) } >
3328 { children }
@@ -51,12 +46,7 @@ export function SearchLandingHistory({
5146 Recent searches
5247 </ Chip >
5348 </ div >
54- < Chip
55- disabled = { clear . isPending }
56- onClick = { ( ) =>
57- clear . mutate ( undefined , { onError : ( error ) => toast . error ( error . message ) } )
58- }
59- >
49+ < Chip disabled = { isClearing } onClick = { clear } >
6050 Clear history
6151 </ Chip >
6252 </ div >
@@ -102,10 +92,10 @@ export function SearchLandingHistory({
10292 </ div >
10393 </ section >
10494 ) }
105- { history . isError && (
95+ { failed && (
10696 < div className = 'mt-6 flex items-center gap-2 px-4 text-[var(--text-tertiary)] text-small' >
10797 Recent activity couldn’t load.
108- < Chip onClick = { ( ) => void history . refetch ( ) } disabled = { history . isFetching } >
98+ < Chip onClick = { retry } disabled = { retrying } >
10999 Try again
110100 </ Chip >
111101 </ div >
0 commit comments