@@ -70,13 +70,14 @@ export const Content = () => {
70
70
} ;
71
71
} ) ;
72
72
73
- // Add this new state to cache display values
73
+ // Add view type to cached display data
74
74
const [ cachedDisplayData , setCachedDisplayData ] = useState ( {
75
75
displayName : '' ,
76
76
path : '' ,
77
+ view : undefined as ViewVariant | undefined ,
77
78
} ) ;
78
79
79
- // Update this useEffect to also cache display data when data loads
80
+ // Update this useEffect to also cache display data and view when data loads
80
81
useEffect ( ( ) => {
81
82
if ( prevContentIdRef . current && prevContentIdRef . current !== selectedContentId ) {
82
83
clearCachedVersionSelector ( prevContentIdRef . current ) ;
@@ -91,20 +92,40 @@ export const Content = () => {
91
92
92
93
// Cache display data when it's available
93
94
if ( data . json ?. displayName || data . json ?. _path ) {
94
- setCachedDisplayData ( {
95
- displayName : data . json . displayName || '' ,
96
- path : data . json . _path || '' ,
97
- } ) ;
95
+ setCachedDisplayData ( ( prev ) => ( {
96
+ displayName : data . json ?. displayName || '' ,
97
+ path : data . json ?. _path || '' ,
98
+ view : prev . view , // Keep existing view
99
+ } ) ) ;
98
100
}
99
101
}
100
102
101
103
prevContentIdRef . current = selectedContentId ;
102
104
} , [ selectedContentId , data ?. versions , data ?. json ] ) ;
103
105
106
+ // Update view selector effect to store the selected view in cache
104
107
useEffect ( ( ) => {
105
- setSelectedView ( getDefaultView ( isWebpage , hasAttachment ) ) ;
108
+ const newView = getDefaultView ( isWebpage , hasAttachment ) ;
109
+ setSelectedView ( newView ) ;
110
+
111
+ // Cache the view
112
+ setCachedDisplayData ( ( prev ) => ( {
113
+ ...prev ,
114
+ view : newView ,
115
+ } ) ) ;
106
116
} , [ isWebpage , hasAttachment , selectedContentId ] ) ;
107
117
118
+ // Add handler to update cached view
119
+ const handleViewChange = ( view : ViewVariant ) => {
120
+ setSelectedView ( view ) ;
121
+
122
+ // Update cached view
123
+ setCachedDisplayData ( ( prev ) => ( {
124
+ ...prev ,
125
+ view,
126
+ } ) ) ;
127
+ } ;
128
+
108
129
const htmlPath = `${ xpArchiveConfig . basePath } /html/${ selectedContentId } /${ selectedLocale } /${
109
130
data ?. json . _versionKey
110
131
} `;
@@ -197,7 +218,7 @@ export const Content = () => {
197
218
< div className = { style . viewSelectorWrapper } >
198
219
< ViewSelector
199
220
selectedView = { selectedView }
200
- setSelectedView = { setSelectedView }
221
+ setSelectedView = { handleViewChange }
201
222
hasAttachment = { hasAttachment }
202
223
isWebpage = { isWebpage }
203
224
/>
0 commit comments