@@ -13,6 +13,7 @@ export default function DynamicSpreadsheet() {
1313 nome_immagine : string ;
1414 metodi : string [ ] ;
1515 targets : string [ ] ;
16+ formati : string [ ]
1617 } ;
1718
1819 type TmpRow = {
@@ -23,6 +24,7 @@ export default function DynamicSpreadsheet() {
2324 nome_immagine : string ;
2425 metodi : string ;
2526 targets : string ;
27+ formati : string
2628 } ;
2729
2830 const spreadshettPath = import . meta. env . PUBLIC_SPREADSHEET_URL ;
@@ -32,9 +34,11 @@ export default function DynamicSpreadsheet() {
3234 const [ filters , setFilters ] = useState < {
3335 metodo : string [ ] ;
3436 target : string [ ] ;
37+ formato : string [ ] ;
3538 } > ( {
3639 metodo : [ ] ,
3740 target : [ ] ,
41+ formato : [ ]
3842 } ) ;
3943
4044 const [ metodi , setMetodi ] = useState ( [
@@ -48,6 +52,12 @@ export default function DynamicSpreadsheet() {
4852 { name : 'Primaria' , selected : false , color : '#2af3d2' } ,
4953 { name : 'Secondaria' , selected : false , color : '#fd1919' } ,
5054 ] ) ;
55+
56+ const [ formati , setFormati ] = useState ( [
57+ { name : 'blog' , selected : false , color : '#59f2ba' } ,
58+ { name : 'webinar' , selected : false , color : '#d6f259' } ,
59+ ] ) ;
60+
5161 const handleFilterSelection = ( { filter, value } ) => {
5262 setFilters ( ( prevFilters ) => {
5363 const updatedFilterValues = prevFilters [ filter ] ?. includes ( value )
@@ -68,13 +78,17 @@ export default function DynamicSpreadsheet() {
6878 setTarget ( ( prevTargets ) =>
6979 prevTargets . map ( ( item ) => ( item . name === value ? { ...item , selected : ! item . selected } : item ) )
7080 ) ;
81+ } else if ( filter === 'formato' ) {
82+ setFormati ( ( prevFormato ) => prevFormato . map ( item => ( item . name === value ? { ...item , selected : ! item . selected } : item ) ) )
7183 }
7284 } ;
7385
7486 const filteredRows = rows . filter ( ( row : Row ) => {
7587 const metodiMatch = filters . metodo . length === 0 || filters . metodo . every ( ( metodo ) => row . metodi . includes ( metodo ) ) ;
7688 const targetMatch = filters . target . length === 0 || filters . target . every ( ( target ) => row . targets . includes ( target ) ) ;
77- return metodiMatch && targetMatch ;
89+ const formatiMatch = filters . formato . length === 0 || filters . formato . every ( ( formato ) => row . formati . includes ( formato ) )
90+
91+ return metodiMatch && targetMatch && formatiMatch ;
7892 } ) ;
7993
8094 useEffect ( ( ) => {
@@ -102,6 +116,7 @@ export default function DynamicSpreadsheet() {
102116 ...tmp ,
103117 metodi : tmp . metodi . split ( ',' ) . map ( ( metodo ) => metodo . trim ( ) ) ,
104118 targets : tmp . targets . split ( ',' ) . map ( ( target ) => target . trim ( ) ) ,
119+ formati : tmp . formati ? tmp . formati . split ( ',' ) . map ( ( formato ) => formato . trim ( ) ) : [ ] ,
105120 } ) ) ;
106121
107122 setRows ( splittedRecords ) ;
@@ -115,18 +130,29 @@ export default function DynamicSpreadsheet() {
115130 } , [ ] ) ;
116131
117132 // getColor set for each filter
118- const getColor = ( category : 'metodo' | 'target' , name : string ) => {
119- const list = category === 'metodo' ? metodi : target ;
133+ const getColor = ( category : 'metodo' | 'target' | 'formato' , name : string ) => {
134+ let list ;
135+
136+ if ( category === 'metodo' ) {
137+ list = metodi ;
138+ } else if ( category === 'target' ) {
139+ list = target ;
140+ } else if ( category === 'formato' ) {
141+ list = formati ;
142+ } else {
143+ return 'black' ;
144+ }
145+
120146 const item = list . find ( ( item ) => item . name === name ) ;
121147 return item ? item . color : 'black' ;
122148 } ;
123149
150+
124151 return (
125152 < div className = "" >
126153 < div className = 'prose-page' >
127154 < div className = "flex justify-start items-center gap-4" >
128155 < p className = "font-semibold" > Filtri:</ p >
129-
130156 < IconSelect
131157 options = { metodi }
132158 icon = "codicon:symbol-method"
@@ -139,6 +165,12 @@ export default function DynamicSpreadsheet() {
139165 filter = "target"
140166 onFilterSelection = { handleFilterSelection }
141167 />
168+ < IconSelect
169+ options = { formati }
170+ icon = "pepicons-pop:label"
171+ filter = "formato"
172+ onFilterSelection = { handleFilterSelection }
173+ />
142174 </ div >
143175 < div className = "flex gap-4 not-prose" >
144176 { metodi . map (
@@ -175,11 +207,29 @@ export default function DynamicSpreadsheet() {
175207 </ button >
176208 )
177209 ) }
210+ { formati . map (
211+ ( f ) =>
212+ f . selected && (
213+ < button
214+ key = { f . name }
215+ onClick = { ( ) => handleFilterSelection ( { filter : 'formato' , value : f . name } ) }
216+ className = "flex items-center border rounded-full border-black px-2 ease-in-out duration-300 capitalize hover:bg-red-100"
217+ >
218+ < Icon
219+ icon = "material-symbols:close"
220+ className = "text-red-500 hover:text-red-600 duration-300 transition-colors"
221+ />
222+ { f . name }
223+ </ button >
224+ )
225+ ) }
178226 </ div >
179227 </ div >
228+
180229 < hr className = "my-6 " />
181230 { rows . length > 0 ? (
182231 < div className = "flex flex-col md:flex-row flex-wrap justify-center items-center md:items-stretch gap-4" >
232+
183233 { filteredRows . map ( ( row , index ) => (
184234 < a
185235 className = "flex flex-col items-center border px-6 py-4 rounded-xl hover:bg-[#f3f0f0c2] max-w-[300px]"
@@ -203,6 +253,11 @@ export default function DynamicSpreadsheet() {
203253 row . targets . map ( ( target ) => (
204254 < Filter key = { `${ row . nome } -${ target } ` } name = { target } color = { getColor ( 'target' , target ) } />
205255 ) ) }
256+ { row . formati &&
257+ row . formati . length > 0 &&
258+ row . formati . map ( ( formato ) => (
259+ < Filter key = { `${ row . nome } -${ formato } ` } name = { formato } color = { getColor ( 'formato' , formato ) } />
260+ ) ) }
206261 </ div >
207262 </ div >
208263 </ a >
0 commit comments