3
3
import React , { useMemo } from "react" ;
4
4
import styles from "./library-hero.module.scss" ;
5
5
import { 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" ;
8
12
import { clsx } from "clsx" ;
9
13
import { getLocalizedSecondaryFont } from "@/libs/theme/fonts" ;
10
14
import { LibrariesDictionaryModel } from "@/features/localization/models/libraries-dictionary.model" ;
11
15
import { 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" ;
12
19
13
20
interface LibraryHeroComponentProps {
14
21
languageCode : string ;
15
22
query : string ;
16
23
categoryOptions : { id : string ; name : string } [ ] ;
24
+ algorithmOptions : { value : string ; label : string } [ ] ;
25
+ supportOptions : { value : string ; label : string } [ ] ;
17
26
dictionary : LibrariesDictionaryModel ;
18
27
}
19
28
20
29
export const LibraryHeroComponent : React . FC < LibraryHeroComponentProps > = ( {
21
30
languageCode,
22
31
query,
23
32
categoryOptions,
33
+ algorithmOptions,
34
+ supportOptions,
24
35
dictionary,
25
36
} ) => {
26
- const searchParams = useSearchParams ( ) ;
27
37
const pathname = usePathname ( ) ;
28
38
const { replace } = useRouter ( ) ;
29
39
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 ;
37
60
}
38
-
39
61
replace ( `${ pathname } ?${ params . toString ( ) } ` ) ;
40
62
} ;
41
63
42
64
const options = useMemo ( ( ) => {
43
65
return [
44
66
{
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 ] ,
47
88
} ,
48
- ...categoryOptions . map ( ( categoryOption ) => {
49
- return {
50
- value : categoryOption . id ,
51
- label : categoryOption . name ,
52
- } ;
53
- } ) ,
54
- ] ;
89
+ ] as GroupBase < DebuggerPickerOptionModel > [ ] ;
55
90
} , [
56
91
categoryOptions ,
57
92
dictionary . filterPicker . defaultValue . label ,
58
93
dictionary . filterPicker . defaultValue . value ,
94
+ algorithmOptions ,
95
+ supportOptions
59
96
] ) ;
60
97
61
98
return (
@@ -67,7 +104,7 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
67
104
< h1
68
105
className = { clsx (
69
106
styles . heroTitle ,
70
- getLocalizedSecondaryFont ( languageCode ) ,
107
+ getLocalizedSecondaryFont ( languageCode )
71
108
) }
72
109
>
73
110
{ dictionary . title }
@@ -80,7 +117,9 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
80
117
languageCode = { languageCode }
81
118
options = { options }
82
119
selectedOptionCode = {
83
- options . filter ( ( option ) => option . value === query ) [ 0 ]
120
+ options
121
+ . flatMap ( ( group ) => group . options )
122
+ . filter ( ( option ) => option . value === query ) [ 0 ]
84
123
}
85
124
handleSelection = { handleSelection }
86
125
placeholder = { null }
0 commit comments