Skip to content

Commit e7df092

Browse files
committed
cache tittel og url
1 parent f6c1f2c commit e7df092

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

xp-archive/client/content/Content.tsx

+27-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export const Content = () => {
7070
};
7171
});
7272

73+
// Add this new state to cache display values
74+
const [cachedDisplayData, setCachedDisplayData] = useState({
75+
displayName: '',
76+
path: '',
77+
});
78+
79+
// Update this useEffect to also cache display data when data loads
7380
useEffect(() => {
7481
if (prevContentIdRef.current && prevContentIdRef.current !== selectedContentId) {
7582
clearCachedVersionSelector(prevContentIdRef.current);
@@ -81,10 +88,18 @@ export const Content = () => {
8188
versions: data.versions,
8289
isOpen: prev.isOpen,
8390
}));
91+
92+
// Cache display data when it's available
93+
if (data.json?.displayName || data.json?._path) {
94+
setCachedDisplayData({
95+
displayName: data.json.displayName || '',
96+
path: data.json._path || '',
97+
});
98+
}
8499
}
85100

86101
prevContentIdRef.current = selectedContentId;
87-
}, [selectedContentId, data?.versions]);
102+
}, [selectedContentId, data?.versions, data?.json]);
88103

89104
useEffect(() => {
90105
setSelectedView(getDefaultView(isWebpage, hasAttachment));
@@ -114,6 +129,15 @@ export const Content = () => {
114129
return 'Laster...';
115130
};
116131

132+
// Add helper functions to get title and URL with fallbacks
133+
const getDisplayName = () => {
134+
return data?.json.displayName || cachedDisplayData.displayName || 'Laster...';
135+
};
136+
137+
const getPath = () => {
138+
return data?.json._path || cachedDisplayData.path || '';
139+
};
140+
117141
if (!selectedContentId) {
118142
return <EmptyState />;
119143
}
@@ -195,10 +219,10 @@ export const Content = () => {
195219

196220
<div className={style.titleAndUrl}>
197221
<Heading size={'medium'} level={'2'}>
198-
{data?.json.displayName ?? ''}
222+
{getDisplayName()}
199223
</Heading>
200224
<div className={style.url}>
201-
<Detail>{data?.json._path ?? ''}</Detail>
225+
<Detail>{getPath()}</Detail>
202226
</div>
203227
</div>
204228
</div>

0 commit comments

Comments
 (0)