@@ -3,11 +3,24 @@ import { useLanguage } from '@/intl/client';
3
3
import { t } from '@/intl/translate' ;
4
4
import { Icon } from '@gitbook/icons' ;
5
5
import { useEffect , useState } from 'react' ;
6
+ import { create } from 'zustand' ;
6
7
import { useVisitedPages } from '../Insights' ;
7
8
import { usePageContext } from '../PageContext' ;
8
9
import { Loading } from '../primitives' ;
9
10
import { streamLinkPageSummary } from './server-actions/streamLinkPageSummary' ;
10
- import { useSummaries } from './summariesStore' ;
11
+
12
+ const useSummaries = create < {
13
+ cache : Map < string , string > ;
14
+ setSummary : ( key : string , summary : string ) => void ;
15
+ } > ( ( set ) => ( {
16
+ cache : new Map ( ) ,
17
+ setSummary : ( key , summary ) =>
18
+ set ( ( state ) => {
19
+ const newCache = new Map ( state . cache ) ;
20
+ newCache . set ( key , summary ) ;
21
+ return { cache : newCache } ;
22
+ } ) ,
23
+ } ) ) ;
11
24
12
25
/**
13
26
* Get a unique cache key for a page summary
@@ -33,8 +46,12 @@ export function AIPageLinkSummary(props: {
33
46
const visitedPages = useVisitedPages ( ( state ) => state . pages ) ;
34
47
const [ summary , setSummary ] = useState ( '' ) ;
35
48
const cacheKey = getCacheKey ( targetSpaceId , targetPageId ) ;
36
- const cachedSummary = useSummaries ( ( state ) => state . cache . get ( cacheKey ) ?? '' ) ;
37
- const setCachedSummary = useSummaries ( ( state ) => state . setSummary ) ;
49
+ const { cachedSummary, setCachedSummary } = useSummaries ( ( state ) => {
50
+ return {
51
+ cachedSummary : state . cache . get ( cacheKey ) ?? '' ,
52
+ setCachedSummary : state . setSummary ,
53
+ } ;
54
+ } ) ;
38
55
39
56
useEffect ( ( ) => {
40
57
let canceled = false ;
0 commit comments