@@ -17,104 +17,104 @@ import DesktopThemePreview from '../components/Themes/DesktopThemePreview';
17
17
* // todo: dynamically load themes as user scrolls instead of fetching wholesale from backend
18
18
*/
19
19
const Themes : React . FC = ( ) => {
20
- //search param hook to access URL
21
- const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
20
+ //search param hook to access URL
21
+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
22
22
23
- // search query for filtering themes to show
24
- const [ searchQuery , setSearchQuery ] = useState (
25
- ( ) => searchParams . get ( 'searchQuery' ) || ''
26
- ) ;
23
+ // search query for filtering themes to show
24
+ const [ searchQuery , setSearchQuery ] = useState (
25
+ ( ) => searchParams . get ( 'searchQuery' ) || ''
26
+ ) ;
27
27
28
- // id of themes being selected to be preview (and applied to the interactive chatbot)
29
- const [ previewIds , setPreviewIds ] = useState < string [ ] > ( [ ] ) ;
28
+ // id of themes being selected to be preview (and applied to the interactive chatbot)
29
+ const [ previewIds , setPreviewIds ] = useState < string [ ] > ( [ ] ) ;
30
30
31
- // theme data fetched from backend
31
+ // theme data fetched from backend
32
32
33
- const { themes, loading, error } = useFetchData (
34
- Endpoints . fetchApiThemes ,
35
- 30 ,
36
- 1 ,
37
- searchQuery
38
- ) ;
33
+ const { themes, loading, error } = useFetchData (
34
+ Endpoints . fetchApiThemes ,
35
+ 30 ,
36
+ 1 ,
37
+ searchQuery
38
+ ) ;
39
39
40
- console . log ( themes )
41
- /**
40
+ console . log ( themes )
41
+ /**
42
42
* Handles setting of search query when user hits enter.
43
43
*
44
44
* @param query query user inputted
45
45
*/
46
- const handleSearch = ( query : string ) => {
47
- if ( query === '' ) {
48
- searchParams . delete ( 'searchQuery' ) ;
49
- } else {
50
- searchParams . set ( 'searchQuery' , query ) ;
51
- }
52
- setSearchParams ( searchParams ) ;
53
- setSearchQuery ( query ) ;
54
- } ;
46
+ const handleSearch = ( query : string ) => {
47
+ if ( query === '' ) {
48
+ searchParams . delete ( 'searchQuery' ) ;
49
+ } else {
50
+ searchParams . set ( 'searchQuery' , query ) ;
51
+ }
52
+ setSearchParams ( searchParams ) ;
53
+ setSearchQuery ( query ) ;
54
+ } ;
55
55
56
- /**
56
+ /**
57
57
* Handles setting and unsetting of theme ids to preview.
58
58
*
59
59
* @param id id of theme to set or unset
60
60
*/
61
- const onPreview = ( id : string ) => {
62
- setPreviewIds ( ( prevPreviewId ) =>
63
- prevPreviewId . includes ( id )
64
- ? prevPreviewId . filter ( ( item ) => item !== id )
65
- : [ ...prevPreviewId , id ]
66
- ) ;
67
- } ;
61
+ const onPreview = ( id : string ) => {
62
+ setPreviewIds ( ( prevPreviewId ) =>
63
+ prevPreviewId . includes ( id )
64
+ ? prevPreviewId . filter ( ( item ) => item !== id )
65
+ : [ ...prevPreviewId , id ]
66
+ ) ;
67
+ } ;
68
68
69
- /**
69
+ /**
70
70
* Clears all preview ids.
71
71
*/
72
- const clearPreviewIds = ( ) => {
73
- setPreviewIds ( [ ] ) ;
74
- } ;
72
+ const clearPreviewIds = ( ) => {
73
+ setPreviewIds ( [ ] ) ;
74
+ } ;
75
75
76
- // todo: show a proper error message if themes are not able to be fetched
77
- if ( error ) {
78
- return < div > Error: { error . message } </ div > ;
79
- }
76
+ // todo: show a proper error message if themes are not able to be fetched
77
+ if ( error ) {
78
+ return < div > Error: { error . message } </ div > ;
79
+ }
80
80
81
- return (
82
- < div className = "bg-accent-950 flex h-screen w-full" >
83
- { /* Main Content Section */ }
84
- < div className = "overflow-y-scroll hide-scrollbar w-full flex flex-col" >
85
- < div className = "ml-14 mt-6 text-accent-50" >
86
- { /* Headers */ }
87
- < h1 className = "text-2xl font-semibold pb-3" > Select Theme(s)</ h1 >
88
- < h2 className = "text-accent-300 text-sm mb-2" >
89
- You can select multiple themes and combine them however you like.
90
- </ h2 >
91
- { /* TODO: this will be a button that opens a modal or redirects */ }
92
- < h2 className = "text-blue-500 text-sm" > How choosing multiple themes work (i)</ h2 >
93
- < div className = "mt-4" >
94
- < SearchBar onSearch = { handleSearch } /> </ div >
95
- </ div >
96
- < div className = "flex flex-col md:grid md:grid-cols-[repeat(auto-fill,270px)] justify-center" >
97
- { /* Card Content */ }
98
- { themes . map ( ( theme ) => {
99
- return (
100
- < ThemeCard
101
- key = { theme . id }
102
- theme = { theme }
103
- isPreviewed = { previewIds . includes ( theme . id ) }
104
- onPreview = { ( ) => onPreview ( theme . id ) }
105
- />
106
- ) ;
107
- } ) }
108
- </ div >
109
- </ div >
110
- { /* Drawer Section */ }
111
- < DesktopThemePreview
112
- setPreviewIds = { setPreviewIds }
113
- previewIds = { previewIds }
114
- clearPreviewIds = { clearPreviewIds }
115
- />
116
- </ div >
117
- ) ;
81
+ return (
82
+ < div className = "bg-accent-950 flex h-screen w-full" >
83
+ { /* Main Content Section */ }
84
+ < div className = "overflow-y-scroll hide-scrollbar w-full flex flex-col" >
85
+ < div className = "ml-14 mt-6 text-accent-50" >
86
+ { /* Headers */ }
87
+ < h1 className = "text-2xl font-semibold pb-3" > Select Theme(s)</ h1 >
88
+ < h2 className = "text-accent-300 text-sm mb-2" >
89
+ You can select multiple themes and combine them however you like.
90
+ </ h2 >
91
+ { /* TODO: this will be a button that opens a modal or redirects */ }
92
+ < h2 className = "text-blue-500 text-sm" > How choosing multiple themes work (i)</ h2 >
93
+ < div className = "mt-4" >
94
+ < SearchBar onSearch = { handleSearch } /> </ div >
95
+ </ div >
96
+ < div className = "flex flex-col md:grid md:grid-cols-[repeat(auto-fill,270px)] justify-center" >
97
+ { /* Card Content */ }
98
+ { themes . map ( ( theme ) => {
99
+ return (
100
+ < ThemeCard
101
+ key = { theme . id }
102
+ theme = { theme }
103
+ isPreviewed = { previewIds . includes ( theme . id ) }
104
+ onPreview = { ( ) => onPreview ( theme . id ) }
105
+ />
106
+ ) ;
107
+ } ) }
108
+ </ div >
109
+ </ div >
110
+ { /* Drawer Section */ }
111
+ < DesktopThemePreview
112
+ setPreviewIds = { setPreviewIds }
113
+ previewIds = { previewIds }
114
+ clearPreviewIds = { clearPreviewIds }
115
+ />
116
+ </ div >
117
+ ) ;
118
118
} ;
119
119
120
120
export default Themes ;
0 commit comments