Skip to content

Commit 2551267

Browse files
committed
[Docs Site] Load filters from search params in ModelCatalog
1 parent b1d1d54 commit 2551267

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

src/components/ModelCatalog.tsx

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import ModelInfo from "./models/ModelInfo";
33
import ModelBadges from "./models/ModelBadges";
44
import { authorData } from "./models/data";
@@ -19,6 +19,22 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
1919
capabilities: [],
2020
});
2121

22+
useEffect(() => {
23+
const params = new URLSearchParams(window.location.search);
24+
25+
const search = params.get("search") ?? "";
26+
const authors = params.getAll("authors");
27+
const tasks = params.getAll("tasks");
28+
const capabilities = params.getAll("capabilities");
29+
30+
setFilters({
31+
search,
32+
authors,
33+
tasks,
34+
capabilities,
35+
});
36+
}, []);
37+
2238
const mapped = models.map((model) => ({
2339
model: {
2440
...model,
@@ -43,21 +59,21 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
4359
const authors = [...new Set(models.map((model) => model.name.split("/")[1]))];
4460
const capabilities = [
4561
...new Set(
46-
models
47-
.map((model) =>
48-
model.properties
49-
.flatMap(({ property_id, value }) => {
50-
if (property_id === "lora" && value === "true") {
51-
return "LoRA";
52-
}
62+
models.flatMap((model) =>
63+
model.properties
64+
.flatMap(({ property_id, value }) => {
65+
if (property_id === "lora" && value === "true") {
66+
return "LoRA";
67+
}
68+
69+
if (property_id === "function_calling" && value === "true") {
70+
return "Function calling";
71+
}
5372

54-
if (property_id === "function_calling" && value === "true") {
55-
return "Function calling";
56-
}
57-
})
58-
.filter((p) => Boolean(p)),
59-
)
60-
.flat(),
73+
return [];
74+
})
75+
.filter((p) => Boolean(p)),
76+
),
6177
),
6278
];
6379

@@ -102,7 +118,7 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
102118

103119
<div className="!mb-8 hidden md:block">
104120
<span className="text-sm font-bold uppercase text-gray-600 dark:text-gray-200">
105-
Model Types
121+
Tasks
106122
</span>
107123

108124
{tasks.map((task) => (
@@ -111,7 +127,8 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
111127
type="checkbox"
112128
className="mr-2"
113129
value={task}
114-
onClick={(e) => {
130+
checked={filters.tasks.includes(task)}
131+
onChange={(e) => {
115132
const target = e.target as HTMLInputElement;
116133

117134
if (target.checked) {
@@ -142,8 +159,9 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
142159
<input
143160
type="checkbox"
144161
value={capability}
162+
checked={filters.capabilities.includes(capability)}
145163
className="mr-2"
146-
onClick={(e) => {
164+
onChange={(e) => {
147165
const target = e.target as HTMLInputElement;
148166

149167
if (target.checked) {
@@ -177,7 +195,8 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
177195
type="checkbox"
178196
className="mr-2"
179197
value={author}
180-
onClick={(e) => {
198+
checked={filters.authors.includes(author)}
199+
onChange={(e) => {
181200
const target = e.target as HTMLInputElement;
182201

183202
if (target.checked) {

src/components/models/ModelBadges.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ModelBadges = ({ model }: { model: WorkersAIModelsSchema }) => {
3333
<ul className="m-0 flex list-none items-center gap-2 p-0 text-xs">
3434
{badges.map((badge) => (
3535
<li key={badge.text}>
36-
<span className="sl-badge gray">{badge.text}</span>
36+
<span className="sl-badge default">{badge.text}</span>
3737
</li>
3838
))}
3939
</ul>

0 commit comments

Comments
 (0)