File tree 3 files changed +30
-2
lines changed
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,15 @@ function UserItems({userID, items}: any){
64
64
return bDate . getTime ( ) - aDate . getTime ( )
65
65
} )
66
66
}
67
+
68
+ if ( filteredItems . length === 0 ) {
69
+ return (
70
+ < div className = { 'pt-2 pl-8' } >
71
+ No items yet
72
+ </ div >
73
+ )
74
+ }
75
+
67
76
return (
68
77
< div className = { 'pt-2' } >
69
78
{ filteredItems . map ( ( item : any ) => {
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ import UserUses from '../../frontend/user-uses';
11
11
export default function Home ( ) {
12
12
const [ reflect , setReflectClient ] = useState < Reflect < M > | null > ( null ) ;
13
13
const [ _ , setOnline ] = useState ( false ) ;
14
+ const [ clientUserID , setClientUserID ] = useState < string | null > ( null ) ;
15
+
16
+ const LOCAL_STORAGE_KEY = 'uses.userID'
14
17
15
18
const logSink = process . env . NEXT_PUBLIC_DATADOG_CLIENT_TOKEN
16
19
? new DataDogBrowserLogSink ( )
@@ -22,7 +25,7 @@ export default function Home() {
22
25
23
26
( async ( ) => {
24
27
logger . info ?.( `Connecting to worker at ${ workerWsURI } ` ) ;
25
- const userID = nanoid ( ) ;
28
+ const userID = clientUserID ? clientUserID : nanoid ( ) ;
26
29
const r = new Reflect < M > ( {
27
30
socketOrigin : workerWsURI ,
28
31
onOnlineChange : setOnline ,
@@ -47,6 +50,12 @@ export default function Home() {
47
50
} ) ( ) ;
48
51
} , [ ] ) ;
49
52
53
+ useEffect ( ( ) => {
54
+ const userID = localStorage . getItem ( LOCAL_STORAGE_KEY )
55
+ if ( userID != null ) setClientUserID ( userID )
56
+ } , [ ] )
57
+
58
+
50
59
if ( ! reflect ) {
51
60
return null ;
52
61
}
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export default function Home() {
12
12
const [ reflect , setReflectClient ] = useState < Reflect < M > | null > ( null ) ;
13
13
const [ _ , setOnline ] = useState ( false ) ;
14
14
15
+ const [ clientUserID , setClientUserID ] = useState < string | null > ( null ) ;
16
+
17
+ const LOCAL_STORAGE_KEY = 'uses.userID'
18
+
15
19
const logSink = process . env . NEXT_PUBLIC_DATADOG_CLIENT_TOKEN
16
20
? new DataDogBrowserLogSink ( )
17
21
: consoleLogSink ;
@@ -22,7 +26,7 @@ export default function Home() {
22
26
23
27
( async ( ) => {
24
28
logger . info ?.( `Connecting to worker at ${ workerWsURI } ` ) ;
25
- const userID = nanoid ( ) ;
29
+ const userID = clientUserID ? clientUserID : nanoid ( ) ;
26
30
const r = new Reflect < M > ( {
27
31
socketOrigin : workerWsURI ,
28
32
onOnlineChange : setOnline ,
@@ -47,6 +51,12 @@ export default function Home() {
47
51
} ) ( ) ;
48
52
} , [ ] ) ;
49
53
54
+ useEffect ( ( ) => {
55
+ const userID = localStorage . getItem ( LOCAL_STORAGE_KEY )
56
+ if ( userID != null ) setClientUserID ( userID )
57
+ } , [ ] )
58
+
59
+
50
60
if ( ! reflect ) {
51
61
return null ;
52
62
}
You can’t perform that action at this time.
0 commit comments