Skip to content

Commit 0c7b025

Browse files
committed
add support group for options in libraries
1 parent 4d49b47 commit 0c7b025

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

src/app/[language]/libraries/page.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default function Libraries({
4040
searchParams?: {
4141
programming_language?: string;
4242
algorithm?: keyof LibraryModel["support"];
43+
support?: keyof LibraryModel["support"]
4344
};
4445
}) {
4546
const librariesDictionary = getLibrariesDictionary(languageCode);
@@ -49,10 +50,15 @@ export default function Libraries({
4950
encoding: "utf-8",
5051
});
5152

52-
const programmingLanguage = searchParams?.programming_language ?? "" ;
53+
const programmingLanguage = searchParams?.programming_language;
5354
const algorithm = searchParams?.algorithm;
54-
const query = programmingLanguage !== "" ? programmingLanguage : algorithm ?? "";
55+
const support = searchParams?.support;
56+
const query = programmingLanguage ?? algorithm ?? support ?? "";
5557
const dictionary = JSON.parse(source) as LibraryDictionaryModel;
58+
const allOptions = Object.keys(Object.values(dictionary)[0].libs[0].support);
59+
const indexAlgorithmStart = allOptions.findIndex(
60+
(option) => option == "hs256"
61+
);
5662

5763
const categoryOptions: { id: string; name: string }[] = Object.values(
5864
dictionary
@@ -61,21 +67,30 @@ export default function Libraries({
6167
name: library.name,
6268
}));
6369

64-
const algorithmOptions: { value: string; label: string}[] = Object.keys(Object.values(
65-
dictionary
66-
)[0].libs[0].support).map(key => ({
67-
value: key,
68-
label: key.toUpperCase()
69-
}))
70+
const supportOptions: { value: string; label: string }[] = allOptions
71+
.slice(0, indexAlgorithmStart)
72+
.map((key) => ({
73+
value: key,
74+
label: key.toUpperCase(),
75+
}));
7076

71-
const categories: LibraryCategoryModel[] = dictionary[programmingLanguage]
77+
const algorithmOptions: { value: string; label: string }[] = allOptions
78+
.slice(indexAlgorithmStart)
79+
.map((key) => ({
80+
value: key,
81+
label: key.toUpperCase(),
82+
}));
83+
84+
const categories: LibraryCategoryModel[] = programmingLanguage
7285
? [dictionary[programmingLanguage]]
7386
: Object.values(dictionary);
7487

75-
const filteredCategories = algorithm
88+
const categoryToFilter = algorithm ?? support
89+
90+
const filteredCategories = categoryToFilter
7691
? categories.map((category) => {
7792
const filteredLibs = category.libs.filter(
78-
(lib) => lib.support[algorithm]
93+
(lib) => lib.support[categoryToFilter]
7994
);
8095
return {
8196
...category,
@@ -190,6 +205,7 @@ export default function Libraries({
190205
query={query || librariesDictionary.filterPicker.defaultValue.value}
191206
categoryOptions={categoryOptions}
192207
algorithmOptions={algorithmOptions}
208+
supportOptions={supportOptions}
193209
dictionary={librariesDictionary}
194210
/>
195211
<LibraryResultsComponent

src/features/libraries/components/library-hero/library-hero.component.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { usePathname, useRouter } from "next/navigation";
77
import {
88
LIBRARIES_FILTER_ALGORITHM_KEY,
99
LIBRARIES_FILTER_PROGRAMMING_LANGUAGE_KEY,
10+
LIBRARIES_FILTER_SUPPORT_KEY,
1011
} from "@/libs/config/project.constants";
1112
import { clsx } from "clsx";
1213
import { getLocalizedSecondaryFont } from "@/libs/theme/fonts";
@@ -21,6 +22,7 @@ interface LibraryHeroComponentProps {
2122
query: string;
2223
categoryOptions: { id: string; name: string }[];
2324
algorithmOptions: { value: string; label: string }[];
25+
supportOptions: { value: string; label: string }[];
2426
dictionary: LibrariesDictionaryModel;
2527
}
2628

@@ -29,6 +31,7 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
2931
query,
3032
categoryOptions,
3133
algorithmOptions,
34+
supportOptions,
3235
dictionary,
3336
}) => {
3437
const pathname = usePathname();
@@ -49,6 +52,9 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
4952
case "Algorithm":
5053
params.set(LIBRARIES_FILTER_ALGORITHM_KEY, selection);
5154
break;
55+
case "Support":
56+
params.set(LIBRARIES_FILTER_SUPPORT_KEY, selection);
57+
break;
5258
default:
5359
break;
5460
}
@@ -72,6 +78,10 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
7278
}),
7379
],
7480
},
81+
{
82+
label: "Support",
83+
options: [...supportOptions],
84+
},
7585
{
7686
label: "Algorithm",
7787
options: [...algorithmOptions],
@@ -82,6 +92,7 @@ export const LibraryHeroComponent: React.FC<LibraryHeroComponentProps> = ({
8292
dictionary.filterPicker.defaultValue.label,
8393
dictionary.filterPicker.defaultValue.value,
8494
algorithmOptions,
95+
supportOptions
8596
]);
8697

8798
return (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type LibraryFilterLabel = "ProgrammingLanguage" | "Algorithm"
1+
export type LibraryFilterLabel = "ProgrammingLanguage" | "Algorithm" | "Support"

src/libs/config/project.constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export const BASE_URL = "https://jwt.io";
22
export const LIBRARIES_FILTER_QUERY_PARAM_KEY = "filter";
33
export const LIBRARIES_FILTER_DEFAULT_VALUE = "all";
4-
export const LIBRARIES_FILTER_PROGRAMMING_LANGUAGE_KEY = "programming_language"
5-
export const LIBRARIES_FILTER_ALGORITHM_KEY = "algorithm"
4+
export const LIBRARIES_FILTER_PROGRAMMING_LANGUAGE_KEY = "programming_language";
5+
export const LIBRARIES_FILTER_ALGORITHM_KEY = "algorithm";
6+
export const LIBRARIES_FILTER_SUPPORT_KEY = "support";
67
export enum SupportedTokenHashParamValues {
78
TOKEN = "token",
89
ACCESS_TOKEN = "access_token",

0 commit comments

Comments
 (0)