@@ -10,146 +10,111 @@ import useFetchData from '../hooks/useFetchThemes';
10
10
import { Theme } from '../interfaces/Theme' ;
11
11
import { Endpoints } from '../constants/Endpoints' ;
12
12
import { useSearchParams } from 'react-router-dom' ;
13
+ import DesktopThemePreview from '../components/Themes/DesktopThemePreview' ;
13
14
14
15
/**
15
16
* Displays themes for users to search, browse and rate.
16
17
* // todo: dynamically load themes as user scrolls instead of fetching wholesale from backend
17
18
*/
18
19
const Themes : React . FC = ( ) => {
19
- //search param hook to access URL
20
- const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
20
+ //search param hook to access URL
21
+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
21
22
22
- // search query for filtering themes to show
23
- const [ searchQuery , setSearchQuery ] = useState (
24
- ( ) => searchParams . get ( 'searchQuery' ) || ''
25
- ) ;
23
+ // search query for filtering themes to show
24
+ const [ searchQuery , setSearchQuery ] = useState (
25
+ ( ) => searchParams . get ( 'searchQuery' ) || ''
26
+ ) ;
26
27
27
- // id of themes being selected to be preview (and applied to the interactive chatbot)
28
- 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 [ ] > ( [ ] ) ;
29
30
30
- // theme data fetched from backend
31
+ // theme data fetched from backend
31
32
32
- const { themes, loading, error } = useFetchData (
33
- Endpoints . fetchApiThemes ,
34
- 30 ,
35
- 1 ,
36
- searchQuery
37
- ) ;
38
- /**
33
+ const { themes, loading, error } = useFetchData (
34
+ Endpoints . fetchApiThemes ,
35
+ 30 ,
36
+ 1 ,
37
+ searchQuery
38
+ ) ;
39
+
40
+ console . log ( themes )
41
+ /**
39
42
* Handles setting of search query when user hits enter.
40
43
*
41
44
* @param query query user inputted
42
45
*/
43
- const handleSearch = ( query : string ) => {
44
- if ( query === '' ) {
45
- searchParams . delete ( 'searchQuery' ) ;
46
- } else {
47
- searchParams . set ( 'searchQuery' , query ) ;
48
- }
49
- setSearchParams ( searchParams ) ;
50
- setSearchQuery ( query ) ;
51
- } ;
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
+ } ;
52
55
53
- /**
56
+ /**
54
57
* Handles setting and unsetting of theme ids to preview.
55
58
*
56
59
* @param id id of theme to set or unset
57
60
*/
58
- const onPreview = ( id : string ) => {
59
- setPreviewIds ( ( prevPreviewId ) =>
60
- prevPreviewId . includes ( id )
61
- ? prevPreviewId . filter ( ( item ) => item !== id )
62
- : [ ...prevPreviewId , id ]
63
- ) ;
64
- } ;
61
+ const onPreview = ( id : string ) => {
62
+ setPreviewIds ( ( prevPreviewId ) =>
63
+ prevPreviewId . includes ( id )
64
+ ? prevPreviewId . filter ( ( item ) => item !== id )
65
+ : [ ...prevPreviewId , id ]
66
+ ) ;
67
+ } ;
65
68
66
- /**
69
+ /**
67
70
* Clears all preview ids.
68
71
*/
69
- const clearPreviewIds = ( ) => {
70
- setPreviewIds ( [ ] ) ;
71
- } ;
72
-
73
- // flow for interactive chatbot
74
- const flow = {
75
- start : {
76
- message : ( params : Params ) => {
77
- params . injectMessage (
78
- 'Hello 👋! Did you know? The order of specifying themes matters!'
79
- ) ;
80
- return 'Try previewing some themes below, or click on those on the left! 😊' ;
81
- } ,
82
- checkboxes : { items : [ 'Minimal Midnight' , 'Cyborg' , 'Terminal' ] } ,
83
- function : ( params : Params ) => {
84
- setPreviewIds (
85
- params . userInput . split ( ',' ) . map ( ( theme ) => {
86
- if ( theme === 'Minimal Midnight' ) {
87
- return 'minimal_midnight' ;
88
- } else if ( theme === 'Cyborg' ) {
89
- return 'cyborg' ;
90
- } else {
91
- return 'terminal' ;
92
- }
93
- } )
94
- ) ;
95
- } ,
96
- chatDisabled : true ,
97
- path : 'end' ,
98
- } ,
99
- end : {
100
- message : "What's next? 😊" ,
101
- options : [ 'Try Again' , 'Check Documentation' , 'Discord' ] ,
102
- path : ( params : Params ) => {
103
- if ( params . userInput === 'Try Again' ) {
104
- setPreviewIds ( [ ] ) ;
105
- } else if ( params . userInput === 'Discord' ) {
106
- window . open ( 'https://discord.gg/6R4DK4G5Zh' ) ;
107
- } else if ( params . userInput === 'Check Documentation' ) {
108
- window . open ( 'https://react-chatbotify.com' ) ;
109
- } else {
110
- setPreviewIds ( [ ] ) ;
111
- params . injectMessage (
112
- "Hmmm I'm not sure what you said, but let's try again!"
113
- ) ;
114
- }
115
- return 'start' ;
116
- } ,
117
- } ,
118
- } ;
72
+ const clearPreviewIds = ( ) => {
73
+ setPreviewIds ( [ ] ) ;
74
+ } ;
119
75
120
- // todo: show a proper error message if themes are not able to be fetched
121
- if ( error ) {
122
- return < div > Error: { error . message } </ div > ;
123
- }
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
+ }
124
80
125
- return (
126
- < div className = "bg-accent-950 flex h-screen w-full" >
127
- { /* Main Content Section */ }
128
- < div className = "mt-20 overflow-y-scroll hide-scrollbar w-full" >
129
- < div className = "text-accent-50" >
130
- { /* Headers */ }
131
- < h1 > Select Theme(s)</ h1 >
132
- < h2 >
133
- You can select multiple themes and combine them however you like.
134
- </ h2 >
135
- < h2 > How choosing multiple themes work (i)</ h2 >
136
- </ div >
137
- < div className = "w-full flex flex-col md:flex-row md:flex-wrap" >
138
- { /* Card Content */ }
139
- { themes . map ( ( theme ) => {
140
- return (
141
- < ThemeCard
142
- key = { theme . id }
143
- theme = { theme }
144
- isPreviewed = { previewIds . includes ( theme . id ) }
145
- onPreview = { ( ) => onPreview ( theme . id ) }
146
- />
147
- ) ;
148
- } ) }
149
- </ div >
150
- </ div >
151
- </ div >
152
- ) ;
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
+ ) ;
153
118
} ;
154
119
155
120
export default Themes ;
0 commit comments