1import { parseNewThreadLink } from "@t3tools/shared/promptLinks";
2import { createFileRoute, useLocation } from "@tanstack/react-router";
3import { useMemo } from "react";
4
5import { NewThreadLinkView } from "../components/promptLinks/NewThreadLinkView";
6import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../components/ui/empty";
7import { SidebarInset } from "../components/ui/sidebar";
8
9// The query is read raw: the router's own search parsing turns `prompt=123` into a number.
10function NewThreadLinkRoute() {
11 const search = useLocation({ select: (location) => location.searchStr });
12 const parsed = useMemo(() => parseNewThreadLink(search), [search]);
13 if (!parsed.ok) {
14 return (
15 <SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none">
16 <Empty className="flex-1">
17 <EmptyHeader className="max-w-md">
18 <EmptyTitle>Could not open the link</EmptyTitle>
19 <EmptyDescription>{parsed.error}</EmptyDescription>
20 </EmptyHeader>
21 </Empty>
22 </SidebarInset>
23 );
24 }
25 return <NewThreadLinkView key={search} link={parsed.value} />;
26}
27
28export const Route = createFileRoute("/_chat/new")({
29 component: NewThreadLinkRoute,
30});