Skip to content

Commit

Permalink
Merge pull request #358 from HoomanDgtl/main
Browse files Browse the repository at this point in the history
fix: modal sort in filter
  • Loading branch information
HoomanDgtl committed Aug 30, 2024
2 parents 7e0b809 + 4448e7b commit 1255524
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/components/gpu-table/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { clsx as classNames } from "clsx";
import CheckBox from "./checkbox";
import { modifyModel, type Gpus } from "./gpu-table";
import { onTop } from "../pricing-page/gpus/sort";

export const defaultFilters = {
modal: [],
Expand Down Expand Up @@ -82,7 +83,7 @@ export default function Filter({
const [options, setOptions] = React.useState<Options[]>(data);

React.useEffect(() => {
const modal = res?.models?.map((model) => model.model);
const modal = onTop(res)?.map((model) => model.model);
const ram = res?.models?.map((model) => model.ram);
const interfaceTypes = res?.models?.map((model) => model.interface);

Expand Down
18 changes: 8 additions & 10 deletions src/components/pricing-page/gpus/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { clsx as classNames } from "clsx";
import CheckBox from "./checkbox";
import { modifyModel, type Gpus } from "./gpu-table";
import { onTop } from "./sort";

export const defaultFilters = {
modal: [],
Expand All @@ -32,7 +33,7 @@ interface Options {
options: { name: string; value: string }[];
}

export const availabilitySort = () => { };
export const availabilitySort = () => {};

export default function Filter({
setFilteredData,
Expand Down Expand Up @@ -82,7 +83,7 @@ export default function Filter({
const [options, setOptions] = React.useState<Options[]>(data);

React.useEffect(() => {
const modal = res?.models?.map((model) => model.model);
const modal = onTop(res)?.map((model) => model.model);
const ram = res?.models?.map((model) => model.ram);
const interfaceTypes = res?.models?.map((model) => model.interface);

Expand Down Expand Up @@ -120,6 +121,8 @@ export default function Filter({
filters.ram.length > 0 ||
filters.interface.length > 0
) {
console.log("filtering");

const filtered = res?.models
?.filter(
(model) =>
Expand All @@ -143,7 +146,7 @@ export default function Filter({
return (
<div className="w-full">
<p className="pb-3 text-sm font-medium">Filtering Options</p>
<div className="rounded-md border shadow-sm w-full bg-background2">
<div className="w-full rounded-md border bg-background2 shadow-sm">
{options?.map((item, index) => (
<Disclosure
as={"div"}
Expand Down Expand Up @@ -180,10 +183,7 @@ export default function Filter({
if (e.target.checked) {
setFilters((prev) => ({
...prev,
[item.value]: [
...prev[item.value],
option.value,
],
[item.value]: [...prev[item.value], option.value],
}));
} else {
setFilters((prev) => ({
Expand All @@ -194,9 +194,7 @@ export default function Filter({
}));
}
}}
checked={filters?.[item.value]?.includes(
option.value,
)}
checked={filters?.[item.value]?.includes(option.value)}
/>
</div>
))}
Expand Down
30 changes: 15 additions & 15 deletions src/components/pricing-page/gpus/sort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ const publishingOptions = [
{ title: "Highest Price" },
];

export const onTop = (res?: Gpus) => {
const onTop = ["h100", "a100"];
const filtered = res?.models
?.filter((model) => onTop?.includes(model?.model))
.sort((a, b) => onTop.indexOf(a?.model) - onTop.indexOf(b?.model));
const rest = res?.models
?.filter((model) => !onTop?.includes(model.model))
.sort((a, b) => b?.availability?.available - a?.availability?.available);

return [...(filtered ?? []), ...(rest ?? [])]?.filter(
(model) => model !== undefined,
);
};

export default function Sort({
setFilteredData,
res,
Expand All @@ -21,20 +35,6 @@ export default function Sort({
}) {
const [selected, setSelected] = useState(publishingOptions[0]);

const onTop = () => {
const onTop = ["h100", "a100"];
const filtered = res?.models
?.filter((model) => onTop?.includes(model?.model))
.sort((a, b) => onTop.indexOf(a?.model) - onTop.indexOf(b?.model));
const rest = res?.models
?.filter((model) => !onTop?.includes(model.model))
.sort((a, b) => b?.availability?.available - a?.availability?.available);

return [...(filtered ?? []), ...(rest ?? [])]?.filter(
(model) => model !== undefined,
);
};

useEffect(() => {
const sortData = (sortType: string) => {
switch (sortType) {
Expand All @@ -47,7 +47,7 @@ export default function Sort({
(a, b) => b.availability.available - a.availability.available,
),
)
: setFilteredData(onTop());
: setFilteredData(onTop(res));
break;
case "Lowest Price":
setFilteredData((prev) =>
Expand Down

0 comments on commit 1255524

Please sign in to comment.