33import React , { useMemo } from "react" ;
44import styles from "./library-hero.module.scss" ;
55import { BoxComponent } from "@/features/common/components/box/box.component" ;
6- import { usePathname , useRouter , useSearchParams } from "next/navigation" ;
7- import { LIBRARIES_FILTER_QUERY_PARAM_KEY } from "@/libs/config/project.constants" ;
6+ import { usePathname , useRouter } from "next/navigation" ;
7+ import {
8+ LIBRARIES_FILTER_ALGORITHM_KEY ,
9+ LIBRARIES_FILTER_PROGRAMMING_LANGUAGE_KEY ,
10+ LIBRARIES_FILTER_SUPPORT_KEY ,
11+ } from "@/libs/config/project.constants" ;
812import { clsx } from "clsx" ;
913import { getLocalizedSecondaryFont } from "@/libs/theme/fonts" ;
1014import { LibrariesDictionaryModel } from "@/features/localization/models/libraries-dictionary.model" ;
1115import { DebuggerPickerComponent } from "@/features/common/components/debugger-picker/debugger-picker.component" ;
16+ import { LibraryFilterLabel } from "../../models/library-filters.model" ;
17+ import { DebuggerPickerOptionModel } from "@/features/common/models/debugger-picker-option.model" ;
18+ import { GroupBase } from "react-select" ;
1219
1320interface LibraryHeroComponentProps {
1421 languageCode : string ;
1522 query : string ;
1623 categoryOptions : { id : string ; name : string } [ ] ;
24+ algorithmOptions : { value : string ; label : string } [ ] ;
25+ supportOptions : { value : string ; label : string } [ ] ;
1726 dictionary : LibrariesDictionaryModel ;
1827}
1928
2029export const LibraryHeroComponent : React . FC < LibraryHeroComponentProps > = ( {
2130 languageCode,
2231 query,
2332 categoryOptions,
33+ algorithmOptions,
34+ supportOptions,
2435 dictionary,
2536} ) => {
26- const searchParams = useSearchParams ( ) ;
2737 const pathname = usePathname ( ) ;
2838 const { replace } = useRouter ( ) ;
2939
30- const handleSelection = ( selection : string ) => {
31- const params = new URLSearchParams ( searchParams ) ;
32-
33- if ( selection ) {
34- params . set ( LIBRARIES_FILTER_QUERY_PARAM_KEY , selection ) ;
35- } else {
36- params . delete ( LIBRARIES_FILTER_QUERY_PARAM_KEY ) ;
40+ const handleSelection = (
41+ selection : string ,
42+ parentLabel ?: LibraryFilterLabel
43+ ) => {
44+ if ( ! parentLabel ) {
45+ return ;
46+ }
47+ const params = new URLSearchParams ( "" ) ;
48+ switch ( parentLabel ) {
49+ case "ProgrammingLanguage" :
50+ params . set ( LIBRARIES_FILTER_PROGRAMMING_LANGUAGE_KEY , selection ) ;
51+ break ;
52+ case "Algorithm" :
53+ params . set ( LIBRARIES_FILTER_ALGORITHM_KEY , selection ) ;
54+ break ;
55+ case "Support" :
56+ params . set ( LIBRARIES_FILTER_SUPPORT_KEY , selection ) ;
57+ break ;
58+ default :
59+ break ;
3760 }
38-
3961 replace ( `${ pathname } ?${ params . toString ( ) } ` ) ;
4062 } ;
4163
4264 const options = useMemo ( ( ) => {
4365 return [
4466 {
45- value : dictionary . filterPicker . defaultValue . value ,
46- label : dictionary . filterPicker . defaultValue . label ,
67+ label : "ProgrammingLanguage" ,
68+ options : [
69+ {
70+ value : dictionary . filterPicker . defaultValue . value ,
71+ label : dictionary . filterPicker . defaultValue . label ,
72+ } ,
73+ ...categoryOptions . map ( ( categoryOption ) => {
74+ return {
75+ value : categoryOption . id ,
76+ label : categoryOption . name ,
77+ } ;
78+ } ) ,
79+ ] ,
80+ } ,
81+ {
82+ label : "Support" ,
83+ options : [ ...supportOptions ] ,
84+ } ,
85+ {
86+ label : "Algorithm" ,
87+ options : [ ...algorithmOptions ] ,
4788 } ,
48- ...categoryOptions . map ( ( categoryOption ) => {
49- return {
50- value : categoryOption . id ,
51- label : categoryOption . name ,
52- } ;
53- } ) ,
54- ] ;
89+ ] as GroupBase < DebuggerPickerOptionModel > [ ] ;
5590 } , [
5691 categoryOptions ,
5792 dictionary . filterPicker . defaultValue . label ,
5893 dictionary . filterPicker . defaultValue . value ,
94+ algorithmOptions ,
95+ supportOptions
5996 ] ) ;
6097
6198 return (
@@ -67,7 +104,7 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
67104 < h1
68105 className = { clsx (
69106 styles . heroTitle ,
70- getLocalizedSecondaryFont ( languageCode ) ,
107+ getLocalizedSecondaryFont ( languageCode )
71108 ) }
72109 >
73110 { dictionary . title }
@@ -80,7 +117,9 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
80117 languageCode = { languageCode }
81118 options = { options }
82119 selectedOptionCode = {
83- options . filter ( ( option ) => option . value === query ) [ 0 ]
120+ options
121+ . flatMap ( ( group ) => group . options )
122+ . filter ( ( option ) => option . value === query ) [ 0 ]
84123 }
85124 handleSelection = { handleSelection }
86125 placeholder = { null }
0 commit comments