Skip to content

Commit

Permalink
fix: improve item rendering to use more unique key
Browse files Browse the repository at this point in the history
+ debounce search in static list
  • Loading branch information
sozonome committed Dec 18, 2021
1 parent 00bdc89 commit 6b1fbd0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/components/item/ItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { AiFillCheckCircle, AiFillCloseCircle } from "react-icons/ai";
import { FiExternalLink } from "react-icons/fi";
import { ImCopy } from "react-icons/im";

import { ListItem } from "components/models/list";
import { APIEntry } from "services/publicapis/list/types";

type APIDetailsProps = Omit<ListItem, "API" | "Description" | "Link">;
type APIDetailsProps = Omit<APIEntry, "API" | "Description" | "Link">;

const APIDetails = ({ Category, HTTPS, Cors, Auth }: APIDetailsProps) => {
return (
Expand Down Expand Up @@ -49,7 +49,7 @@ const APIDetails = ({ Category, HTTPS, Cors, Auth }: APIDetailsProps) => {
};

type ItemCardProps = {
value: ListItem;
value: APIEntry;
useAccordion?: boolean;
};

Expand Down
10 changes: 7 additions & 3 deletions src/components/item/ItemContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Grid } from "@chakra-ui/react";

import { ListItem } from "components/models/list";
import { APIEntry } from "services/publicapis/list/types";

import ItemCard from "./ItemCard";

type ItemContainerProps = {
entries: Array<ListItem>;
entries: Array<APIEntry>;
useAccordion?: boolean;
};

Expand All @@ -22,7 +22,11 @@ const ItemContainer = ({ entries, useAccordion }: ItemContainerProps) => {
gap={8}
>
{entries.map((entry) => (
<ItemCard value={entry} key={entry.API} useAccordion={useAccordion} />
<ItemCard
value={entry}
key={`${entry.API}-${entry.Link}`}
useAccordion={useAccordion}
/>
))}
</Grid>
);
Expand Down
16 changes: 0 additions & 16 deletions src/components/models/list.ts

This file was deleted.

11 changes: 8 additions & 3 deletions src/components/pages/all/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Button, FormControl, Input, Skeleton } from "@chakra-ui/react";
import chunk from "lodash/chunk";
import debounce from "lodash/debounce";
import Link from "next/link";
import { ChangeEvent, useCallback, useMemo, useState } from "react";
import { AiOutlineArrowLeft } from "react-icons/ai";
Expand Down Expand Up @@ -61,11 +62,15 @@ const APIListPage = ({ fallbackData }: APIListPageProps) => {
[currentPage]
);

// eslint-disable-next-line react-hooks/exhaustive-deps
const handleChangeKeyword = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
debounce((event: ChangeEvent<HTMLInputElement>) => {
setKeyword(event.target.value.toLowerCase());
},
[]
if (currentPage !== 0) {
setCurrentPage(0);
}
}, 200),
[currentPage]
);

const pageNavigationButtonsProps: PageNavigationButtonsProps = useMemo(
Expand Down

1 comment on commit 6b1fbd0

@vercel
Copy link

@vercel vercel bot commented on 6b1fbd0 Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.