File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { blockMapState, pagesState } from '@/stores';
3
3
import { pageIO , pageListIO } from '@/socket' ;
4
4
import { BlockMap , Page } from '@/schemes' ;
5
5
import { useEffect } from 'react' ;
6
- import { pageUserCountState , lastUpdateState } from '@/stores/page' ;
6
+ import { pageUserCountState , lastUpdateState , pageState } from '@/stores/page' ;
7
7
8
8
const doSomeThing = ( ) => { } ;
9
9
@@ -12,11 +12,21 @@ const useSocket = () => {
12
12
const setPages = useSetRecoilState ( pagesState ) ;
13
13
const setPageUserCount = useSetRecoilState ( pageUserCountState ) ;
14
14
const setLastUpdate = useSetRecoilState ( lastUpdateState ) ;
15
+ const setPage = useSetRecoilState ( pageState ) ;
15
16
16
17
useEffect ( ( ) => {
17
- pageListIO . on ( 'PageListUpdate' , ( pages : Page [ ] ) => {
18
- setPages ( pages ) ;
19
- } ) ;
18
+ pageListIO . on (
19
+ 'PageListUpdate' ,
20
+ ( { currentPageId, pages } : { currentPageId : string ; pages : Page [ ] } ) => {
21
+ setPages ( pages ) ;
22
+ const currentPage = pages . find ( ( page ) => page . id === currentPageId ) ;
23
+ if ( currentPage ) {
24
+ setPage ( currentPage ) ;
25
+ } else if ( pages ?. [ 0 ] ) {
26
+ setPage ( pages ?. [ 0 ] ) ;
27
+ }
28
+ } ,
29
+ ) ;
20
30
21
31
pageListIO . on ( 'allUserCount' , ( count : number ) => {
22
32
console . log ( `allUserCount: ${ count } ` ) ;
You can’t perform that action at this time.
0 commit comments