Skip to content

Commit 15cfef0

Browse files
committed
Links: land to former conversations #356
1 parent 695af02 commit 15cfef0

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

pages/link/chat/[chatLinkId].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export default function ChatLinkPage() {
1111
// external state
1212
const { chatLinkId } = useRouterQuery<{ chatLinkId: string | undefined }>();
1313

14-
return withLayout({ type: 'optima', suspendAutoModelsSetup: true }, <AppChatLink linkId={chatLinkId || ''} />);
14+
return withLayout({ type: 'optima', suspendAutoModelsSetup: true }, <AppChatLink chatLinkId={chatLinkId || null} />);
1515
}

src/apps/link/AppChatLink.tsx

+40-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Head from 'next/head';
33
import { useQuery } from '@tanstack/react-query';
44

5-
import { Box, Typography } from '@mui/joy';
5+
import { Box, Card, CardContent, Typography } from '@mui/joy';
66

77
import { createConversationFromJsonV1 } from '~/modules/trade/trade.client';
88

@@ -20,6 +20,9 @@ import { AppChatLinkMenuItems } from './AppChatLinkMenuItems';
2020
import { ViewChatLink } from './ViewChatLink';
2121

2222

23+
const SPECIAL_LIST_PAGE_ID = 'list';
24+
25+
2326
const Centerer = (props: { backgroundColor: string, children?: React.ReactNode }) =>
2427
<Box sx={{
2528
backgroundColor: props.backgroundColor,
@@ -29,6 +32,21 @@ const Centerer = (props: { backgroundColor: string, children?: React.ReactNode }
2932
{props.children}
3033
</Box>;
3134

35+
const ListPlaceholder = () =>
36+
<Box sx={{ p: { xs: 3, md: 6 } }}>
37+
<Card>
38+
<CardContent>
39+
<Typography level='title-md'>
40+
Shared Conversations
41+
</Typography>
42+
<Typography level='body-sm'>
43+
Here you can see formely exported shared conversations. Please select a conversation from the drawer.
44+
</Typography>
45+
</CardContent>
46+
</Card>
47+
</Box>;
48+
49+
3250
const ShowLoading = () =>
3351
<Centerer backgroundColor={themeBgAppDarker}>
3452
<LogoProgress showProgress={true} />
@@ -48,7 +66,10 @@ const ShowError = (props: { error: any }) =>
4866
* Note: we don't have react-query for the Node functions, so we use the immediate API here,
4967
* and wrap it in a react-query hook
5068
*/
51-
async function fetchStoredChatV1(objectId: string) {
69+
async function fetchStoredChatV1(objectId: string | null) {
70+
if (!objectId)
71+
throw new Error('No Stored Chat');
72+
5273
// fetch
5374
const result = await apiAsyncNode.trade.storageGet.query({ objectId });
5475
if (result.type === 'error')
@@ -68,13 +89,17 @@ async function fetchStoredChatV1(objectId: string) {
6889
}
6990

7091

71-
export function AppChatLink(props: { linkId: string }) {
92+
export function AppChatLink(props: { chatLinkId: string | null }) {
93+
94+
// derived state
95+
const isListPage = props.chatLinkId === SPECIAL_LIST_PAGE_ID;
96+
const linkId = isListPage ? null : props.chatLinkId;
7297

7398
// external state
7499
const { data, isError, error, isLoading } = useQuery({
75-
enabled: !!props.linkId,
76-
queryKey: ['chat-link', props.linkId],
77-
queryFn: () => fetchStoredChatV1(props.linkId),
100+
enabled: !!linkId,
101+
queryKey: ['chat-link', linkId],
102+
queryFn: () => fetchStoredChatV1(linkId),
78103
refetchOnWindowFocus: false,
79104
staleTime: 1000 * 60 * 60 * 24, // 24 hours
80105
});
@@ -96,13 +121,15 @@ export function AppChatLink(props: { linkId: string }) {
96121
<title>{capitalizeFirstLetter(pageTitle)} · {Brand.Title.Base} 🚀</title>
97122
</Head>
98123

99-
{isLoading
100-
? <ShowLoading />
101-
: isError
102-
? <ShowError error={error} />
103-
: !!data?.conversation
104-
? <ViewChatLink conversation={data.conversation} storedAt={data.storedAt} expiresAt={data.expiresAt} />
105-
: <Centerer backgroundColor={themeBgAppDarker} />}
124+
{isListPage
125+
? <ListPlaceholder />
126+
: isLoading
127+
? <ShowLoading />
128+
: isError
129+
? <ShowError error={error} />
130+
: !!data?.conversation
131+
? <ViewChatLink conversation={data.conversation} storedAt={data.storedAt} expiresAt={data.expiresAt} />
132+
: <Centerer backgroundColor={themeBgAppDarker} />}
106133

107134
</>;
108135
}

0 commit comments

Comments
 (0)