@@ -11,6 +11,9 @@ import ThemePreview from '../components/Themes/ThemePreview';
11
11
import { InfoIcon } from 'lucide-react' ;
12
12
13
13
import { useTranslation } from 'react-i18next' ;
14
+ import ThemeModal from '@/components/Themes/ThemeModal' ;
15
+ import { useEffect } from 'react' ;
16
+ import { Theme } from '@/interfaces/Theme' ;
14
17
15
18
/**
16
19
* Displays themes for users to search, browse and rate.
@@ -26,6 +29,8 @@ const Themes: React.FC = () => {
26
29
( ) => searchParams . get ( 'searchQuery' ) || ''
27
30
) ;
28
31
32
+ const [ focusedTheme , setFocusedTheme ] = useState < null | Theme > ( null )
33
+
29
34
// id of themes being selected to be preview (and applied to the interactive chatbot)
30
35
const [ previewIds , setPreviewIds ] = useState < string [ ] > ( [ ] ) ;
31
36
@@ -41,7 +46,47 @@ const Themes: React.FC = () => {
41
46
searchQuery
42
47
) ;
43
48
44
- console . log ( themes ) ;
49
+ useEffect ( ( ) => {
50
+ //to update the current focused theme based on url and fetched themes
51
+ const focusedThemeId = searchParams . get ( 'theme' ) || '' ;
52
+ if ( focusedThemeId == '' ) {
53
+ return ;
54
+ }
55
+ const focusedThemeObject = themes . find ( theme => theme . id === focusedThemeId ) ;
56
+ if ( ! focusedThemeObject ) {
57
+ return
58
+ }
59
+ setFocusedTheme ( focusedThemeObject )
60
+
61
+ } , [ themes ] )
62
+
63
+ /**
64
+ * Handles the closinf of modal and cleanup of url
65
+ *
66
+ */
67
+ const modalCloseHandler = ( ) => {
68
+ //first update the search params
69
+ setSearchParams ( params => {
70
+ params . delete ( 'theme' )
71
+ return params ;
72
+ } )
73
+ return null ;
74
+ }
75
+
76
+ /**
77
+ * Handles opening of the modal for a theme, and updates the url accordingly
78
+ *
79
+ * @param theme the theme to focus on
80
+ */
81
+ const modalOpenHandler = ( theme : Theme ) => {
82
+ setSearchParams ( params => {
83
+ params . set ( 'theme' , theme . id )
84
+ return params ;
85
+ } )
86
+ return theme
87
+ }
88
+
89
+
45
90
/**
46
91
* Handles setting of search query when user hits enter.
47
92
*
@@ -75,6 +120,7 @@ const Themes: React.FC = () => {
75
120
return < div > Error: { error . message } </ div > ;
76
121
}
77
122
123
+
78
124
return (
79
125
// 92vh comes from 100vh - 8vh (the height of the navbar)
80
126
< div className = "bg-accent-950 flex h-[92vh] w-full" >
@@ -107,11 +153,17 @@ const Themes: React.FC = () => {
107
153
isPreviewed = { previewIds . includes ( theme . id ) }
108
154
onPreview = { ( ) => onPreview ( theme . id ) }
109
155
isLoading = { loading }
156
+ onViewDetails = { ( theme ) => ( setFocusedTheme ( modalOpenHandler ( theme ) ) ) }
110
157
/>
111
158
) ;
112
159
} ) }
113
160
</ div >
114
161
</ div >
162
+ < ThemeModal
163
+ isOpen = { focusedTheme !== null }
164
+ onClose = { ( ) => ( setFocusedTheme ( modalCloseHandler ( ) ) ) }
165
+ theme = { focusedTheme as Theme }
166
+ />
115
167
{ /* Drawer Section */ }
116
168
< ThemePreview
117
169
setPreviewIds = { setPreviewIds }
0 commit comments