@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
import Head from 'next/head' ;
3
3
import { useQuery } from '@tanstack/react-query' ;
4
4
5
- import { Box , Typography } from '@mui/joy' ;
5
+ import { Box , Card , CardContent , Typography } from '@mui/joy' ;
6
6
7
7
import { createConversationFromJsonV1 } from '~/modules/trade/trade.client' ;
8
8
@@ -20,6 +20,9 @@ import { AppChatLinkMenuItems } from './AppChatLinkMenuItems';
20
20
import { ViewChatLink } from './ViewChatLink' ;
21
21
22
22
23
+ const SPECIAL_LIST_PAGE_ID = 'list' ;
24
+
25
+
23
26
const Centerer = ( props : { backgroundColor : string , children ?: React . ReactNode } ) =>
24
27
< Box sx = { {
25
28
backgroundColor : props . backgroundColor ,
@@ -29,6 +32,21 @@ const Centerer = (props: { backgroundColor: string, children?: React.ReactNode }
29
32
{ props . children }
30
33
</ Box > ;
31
34
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
+
32
50
const ShowLoading = ( ) =>
33
51
< Centerer backgroundColor = { themeBgAppDarker } >
34
52
< LogoProgress showProgress = { true } />
@@ -48,7 +66,10 @@ const ShowError = (props: { error: any }) =>
48
66
* Note: we don't have react-query for the Node functions, so we use the immediate API here,
49
67
* and wrap it in a react-query hook
50
68
*/
51
- async function fetchStoredChatV1 ( objectId : string ) {
69
+ async function fetchStoredChatV1 ( objectId : string | null ) {
70
+ if ( ! objectId )
71
+ throw new Error ( 'No Stored Chat' ) ;
72
+
52
73
// fetch
53
74
const result = await apiAsyncNode . trade . storageGet . query ( { objectId } ) ;
54
75
if ( result . type === 'error' )
@@ -68,13 +89,17 @@ async function fetchStoredChatV1(objectId: string) {
68
89
}
69
90
70
91
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 ;
72
97
73
98
// external state
74
99
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 ) ,
78
103
refetchOnWindowFocus : false ,
79
104
staleTime : 1000 * 60 * 60 * 24 , // 24 hours
80
105
} ) ;
@@ -96,13 +121,15 @@ export function AppChatLink(props: { linkId: string }) {
96
121
< title > { capitalizeFirstLetter ( pageTitle ) } · { Brand . Title . Base } 🚀</ title >
97
122
</ Head >
98
123
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 } /> }
106
133
107
134
</ > ;
108
135
}
0 commit comments