MCPcopy Create free account
hub / github.com/code-with-antonio/nightcode / Session

Function Session

packages/cli/src/screens/session.tsx:114–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112}
113
114export function Session() {
115 const { id } = useParams();
116 const location = useLocation();
117 const navigate = useNavigate();
118 const toast = useToast();
119
120 const prefetched = useMemo(() => {
121 const parsed = sessionLocationSchema.safeParse(location.state);
122 return parsed.success ? parsed.data : null;
123 }, [location.state]);
124
125 const [session, setSession] = useState<SessionData | null>(prefetched?.session ?? null);
126
127 useEffect(() => {
128 // Skip fetch if session was passed via location state
129 if (prefetched?.session) return;
130
131 setSession(null);
132
133 if (!id) return;
134
135 let ignore = false;
136 const fetchSession = async () => {
137 try {
138 const res = await apiClient.sessions[":id"].$get({
139 param: { id },
140 });
141 if (ignore) return;
142 if (!res.ok) throw new Error(await getErrorMessage(res));
143 const resolved = await res.json();
144 setSession(resolved);
145 } catch (err) {
146 if (ignore) return;
147 toast.show({
148 variant: "error",
149 message: err instanceof Error ? err.message : "Failed to load session",
150 });
151 navigate("/", { replace: true });
152 }
153 };
154
155 fetchSession();
156 return () => {
157 ignore = true;
158 };
159 }, [id, prefetched, toast, navigate]);
160
161 if (!session) {
162 return <SessionShell onSubmit={() => {}} inputDisabled loading />;
163 }
164
165 return (
166 <SessionChat
167 key={session.id}
168 session={session}
169 initialPrompt={prefetched?.initialPrompt}
170 />
171 );

Callers

nothing calls this directly

Calls 2

useToastFunction · 0.90
fetchSessionFunction · 0.85

Tested by

no test coverage detected