@@ -5,7 +5,8 @@ import { CustomNameCellRenderer } from './CustomNameCellRenderer';
55import { CustomLocationCellRenderer } from './CustomLocationCellRenderer' ;
66import { CustomAuthorCellRenderer } from './CustomAuthorCellRenderer' ;
77import { GraphTable } from './GraphTable' ;
8- import { GridViewIcon , ListViewIcon , QuestionMarkIcon } from '../Common/CustomIcons' ;
8+ import { TemplatesSection } from './TemplatesSection' ;
9+ import { GridViewIcon , ListViewIcon } from '../Common/CustomIcons' ;
910import { openFile , saveHomePageSettings } from '../../functions/utility' ;
1011import { FormattedMessage } from 'react-intl' ;
1112import { Tooltip } from '../Common/Tooltip' ;
@@ -71,21 +72,23 @@ export const RecentPage = ({ setIsDisabled, recentPageViewMode }: RecentPage) =>
7172 useEffect ( ( ) => {
7273 if ( initialized || recentPageViewMode !== viewMode ) {
7374 setInitialized ( true ) ;
74- updateSettings ( { recentPageViewMode : viewMode } ) ;
75+ const mergedSettings = { ...settings , recentPageViewMode : viewMode } ;
76+ updateSettings ( mergedSettings ) ;
7577
7678 // Send settings to Dynamo to save
77- saveHomePageSettings ( { ... settings , recentPageViewMode : viewMode } ) ;
79+ saveHomePageSettings ( mergedSettings ) ;
7880 }
7981 // eslint-disable-next-line react-hooks/exhaustive-deps
8082 } , [ viewMode ] ) ;
8183
8284 useEffect ( ( ) => {
8385 if ( templatesInitialized || ( settings ?. templatesPageViewMode && settings . templatesPageViewMode !== templatesViewMode ) ) {
8486 setTemplatesInitialized ( true ) ;
85- updateSettings ( { templatesPageViewMode : templatesViewMode } ) ;
87+ const mergedSettings = { ...settings , templatesPageViewMode : templatesViewMode } ;
88+ updateSettings ( mergedSettings ) ;
8689
8790 // Send settings to Dynamo to save
88- saveHomePageSettings ( { ... settings , templatesPageViewMode : templatesViewMode } ) ;
91+ saveHomePageSettings ( mergedSettings ) ;
8992 }
9093 // eslint-disable-next-line react-hooks/exhaustive-deps
9194 } , [ templatesViewMode ] ) ;
@@ -127,23 +130,6 @@ export const RecentPage = ({ setIsDisabled, recentPageViewMode }: RecentPage) =>
127130 openFile ( contextData ) ;
128131 } ;
129132
130- // Handles mouse click over each template row
131- const handleTemplateRowClick = ( row : Row ) => {
132- // freezes the UI
133- setIsDisabled ( true ) ;
134-
135- const contextData = row . original . ContextData ;
136- openFile ( contextData ) ;
137- } ;
138-
139- // Map templates to match Graph structure for table view (templates use 'date' instead of 'DateModified')
140- const templatesForTable = templates . map ( template => ( {
141- ...template ,
142- DateModified : template . date || template . DateModified || '' ,
143- Author : template . Author || '' ,
144- Description : template . Description || ''
145- } ) ) ;
146-
147133 return (
148134 < div data-testid = "page-recent" >
149135 { /* Recent Section */ }
@@ -183,53 +169,14 @@ export const RecentPage = ({ setIsDisabled, recentPageViewMode }: RecentPage) =>
183169 ) }
184170 </ div >
185171
186- { /* Templates Section */ }
187- < div className = 'drop-shadow-2xl' style = { { display : 'flex' , alignItems : 'center' } } >
188- < p className = 'title-paragraph' style = { { display : 'inline-block' , width : 'fit-content' } } >
189- < FormattedMessage id = "title.text.templates" />
190- </ p >
191- < Tooltip content = { < FormattedMessage id = "tooltip.text.templates" /> } position = "right" >
192- < QuestionMarkIcon />
193- </ Tooltip >
194- </ div >
195- < div style = { { display : 'flex' , alignItems : 'center' , marginBottom :'10px' } } >
196- < button
197- className = { `viewmode-button ${ templatesViewMode === 'grid' ? 'active' : '' } ` }
198- onClick = { ( ) => setTemplatesViewMode ( 'grid' ) }
199- disabled = { templatesViewMode === 'grid' }
200- data-testid = "templates-view-toggle-grid" >
201- < Tooltip content = { < FormattedMessage id = "tooltip.text.grid.view.button" /> } >
202- < GridViewIcon />
203- </ Tooltip >
204- </ button >
205- < button
206- className = { `viewmode-button ${ templatesViewMode === 'list' ? 'active' : '' } ` }
207- onClick = { ( ) => setTemplatesViewMode ( 'list' ) }
208- disabled = { templatesViewMode === 'list' }
209- data-testid = "templates-view-toggle-list" >
210- < Tooltip content = { < FormattedMessage id = "tooltip.text.list.view.button" /> } >
211- < ListViewIcon />
212- </ Tooltip >
213- </ button >
214- </ div >
215- < div style = { { marginRight : '20px' , paddingBottom : '35px' } } >
216- { templatesViewMode === 'list' && (
217- < GraphTable columns = { columns } data = { templatesForTable } onRowClick = { handleTemplateRowClick } />
218- ) }
219- { templatesViewMode === 'grid' && (
220- < div className = "main-graph-grid" id = "templatesContainer" >
221- { templates . map ( template => (
222- < GraphGridItem
223- key = { template . id }
224- { ...template }
225- DateModified = { template . date || template . DateModified || '' }
226- Description = { template . Description || '' }
227- setIsDisabled = { setIsDisabled }
228- />
229- ) ) }
230- </ div >
231- ) }
232- </ div >
172+ < TemplatesSection
173+ columns = { columns }
174+ templates = { templates }
175+ templatesViewMode = { templatesViewMode }
176+ setTemplatesViewMode = { setTemplatesViewMode }
177+ onRowClick = { handleRowClick }
178+ setIsDisabled = { setIsDisabled }
179+ />
233180 </ div >
234181 ) ;
235182} ;
0 commit comments