import * as React from "react" import { useAccountOrGuest, useCoState } from "@/lib/providers/jazz-provider" import { LaIcon } from "@/components/custom/la-icon" import { Topic, PersonalLink, PersonalPage } from "@/lib/schema" import { PublicGlobalGroup } from "@/lib/schema/master/public-group" import { JAZZ_GLOBAL_GROUP_ID } from "@/lib/constants" import { createFileRoute } from "@tanstack/react-router" import AiSearch from "~/components/custom/ai-search" import { Link } from "@tanstack/react-router" export const Route = createFileRoute("/_layout/_pages/search/")({ component: () => , }) interface SearchTitleProps { title: string count: number } interface SearchItemProps { icon: string href: string title: string subtitle?: string topic?: Topic } const SearchTitle: React.FC = ({ title, count }) => (

{title}

{count}
) const SearchItem: React.FC = ({ icon, href, title, subtitle, topic, }) => (
e.stopPropagation()} className="text-sm font-medium hover:text-primary hover:opacity-70" > {title} {subtitle && ( e.stopPropagation()} className="ml-2 truncate text-xs text-muted-foreground hover:underline" > {subtitle} )} {topic && ( {topic.latestGlobalGuide?.sections?.reduce( (total, section) => total + (section?.links?.length || 0), 0, ) || 0}{" "} links )}
) const SearchComponent = () => { const [searchText, setSearchText] = React.useState("") const [showAiSearch, setShowAiSearch] = React.useState(false) const [searchResults, setSearchResults] = React.useState<{ topics: Topic[] links: PersonalLink[] pages: PersonalPage[] }>({ topics: [], links: [], pages: [] }) const { me } = useAccountOrGuest() const globalGroup = useCoState(PublicGlobalGroup, JAZZ_GLOBAL_GROUP_ID, { root: { topics: [], }, }) const handleSearch = (e: React.ChangeEvent) => { const value = e.target.value.toLowerCase() setSearchText(value) if (!value) { setSearchResults({ topics: [], links: [], pages: [] }) return } setSearchResults({ topics: globalGroup?.root.topics.filter( (topic: Topic | null): topic is Topic => topic !== null && topic.prettyName.toLowerCase().startsWith(value), ) || [], links: me?._type === "Anonymous" ? [] : me?.root?.personalLinks?.filter( (link: PersonalLink | null): link is PersonalLink => link !== null && link.title.toLowerCase().startsWith(value), ) || [], pages: me?._type === "Anonymous" ? [] : me?.root?.personalPages?.filter( (page): page is PersonalPage => page !== null && page.title !== undefined && page.title.toLowerCase().startsWith(value), ) || [], }) } const clearSearch = () => { setSearchText("") setSearchResults({ topics: [], links: [], pages: [] }) setShowAiSearch(false) } return (
{searchText && ( )}
{Object.values(searchResults).some((arr) => arr.length > 0) ? (
{searchResults.links.length > 0 && ( <> {searchResults.links.map((link) => ( ))} )} {searchResults.pages.length > 0 && ( <> {searchResults.pages.map((page) => ( ))} )} {searchResults.topics.length > 0 && ( <> {searchResults.topics.map((topic) => ( ))} )}
) : (
{/* {searchText && !showAiSearch && ( */} {searchText && (
setShowAiSearch(true)} > ✨ Didn't find what you were looking for? Will soon have AI assistant builtin
)} {showAiSearch && }
)}
) }