Skip to content

Commit 034075b

Browse files
committed
Simplify
1 parent 24fcf4f commit 034075b

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

Diff for: packages/gitbook/src/components/Adaptive/AIPageLinkSummary.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ import { useLanguage } from '@/intl/client';
33
import { t } from '@/intl/translate';
44
import { Icon } from '@gitbook/icons';
55
import { useEffect, useState } from 'react';
6+
import { create } from 'zustand';
67
import { useVisitedPages } from '../Insights';
78
import { usePageContext } from '../PageContext';
89
import { Loading } from '../primitives';
910
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+
}));
1124

1225
/**
1326
* Get a unique cache key for a page summary
@@ -33,8 +46,12 @@ export function AIPageLinkSummary(props: {
3346
const visitedPages = useVisitedPages((state) => state.pages);
3447
const [summary, setSummary] = useState('');
3548
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+
});
3855

3956
useEffect(() => {
4057
let canceled = false;

Diff for: packages/gitbook/src/components/Adaptive/summariesStore.ts

-16
This file was deleted.

0 commit comments

Comments
 (0)