Skip to content

Commit

Permalink
second round of feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
avertrees committed Dec 11, 2024
1 parent f7adce1 commit 6981a26
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
7 changes: 3 additions & 4 deletions app/collections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { redirect } from "next/navigation";

export type CollectionsProps = {
params: { slug: string };
searchParams: { page: string; sort: string; collection_keyword: string };
searchParams: { page: string; sort: string; collection_keywords: string };
};

export const metadata: Metadata = {
Expand All @@ -18,10 +18,10 @@ export const metadata: Metadata = {

export default async function Collections({ searchParams }: CollectionsProps) {
const data = await getCollectionsData({
keyword: searchParams.collection_keyword,
keyword: searchParams.collection_keywords,
sortID: searchParams.sort,
pageNum: searchParams.page,
}); // TODO: create model for APICollectionsData from API to clean up the data before it's sent down to the components.
});

// Repo API returns 404s within the data.
if (
Expand All @@ -33,7 +33,6 @@ export default async function Collections({ searchParams }: CollectionsProps) {

return (
<Suspense>
{/* pass entire Repo API Response */}
<CollectionsPage data={data} params={searchParams} />
</Suspense>
);
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/pages/collectionsPage/collectionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ export function CollectionsPage({ data, params }) {
setTimeout(() => {
setIsLoaded(true);
headingRef.current?.focus();
}, 2000);
}, 1000);
};

const handleSearchSubmit = async (e: SyntheticEvent) => {
e.preventDefault();
// something is so weird about state here.
// change the values in the object passed down to createCollectionsQueryStringFromObject to be currentPage and currentSort and tell me if it works for you....
setCurrentPage(Number(DEFAULT_PAGE_NUM));
setCurrentSort(DEFAULT_COLLECTION_SORT);
const queryString = createCollectionsQueryStringFromObject({
collection_keywords: currentCollectionKeywords,
sort: currentSort,
page: currentPage,
sort: DEFAULT_COLLECTION_SORT,
page: DEFAULT_PAGE_NUM,
});
updateURL(queryString);
};
Expand All @@ -82,7 +84,6 @@ export function CollectionsPage({ data, params }) {
setcurrentCollectionKeywords(target.value);
};

// pagination
const onPageChange = async (pageNumber: number) => {
setCurrentPage(pageNumber);
const queryString = createCollectionsQueryStringFromObject({
Expand All @@ -93,7 +94,6 @@ export function CollectionsPage({ data, params }) {
updateURL(queryString);
};

// sort
const onMenuClick = async (id) => {
setCurrentSort(id);
const queryString = createCollectionsQueryStringFromObject({
Expand Down
5 changes: 0 additions & 5 deletions app/src/components/results/noResultsFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import {
Flex,
Heading,
Text,
Link,
List,
} from "@nypl/design-system-react-components";
import Image from "next/image";
import useBreakpoints from "@/src/hooks/useBreakpoints";
import { useFeedbackContext } from "@/src/context/FeedbackProvider";

export default function NoResultsFound({ searchTerm }) {
console.log("searchTerm is: ", searchTerm);
const headingText = `No Results for "${searchTerm}"`;
return (
<Flex
Expand Down
25 changes: 11 additions & 14 deletions app/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,25 @@ export function displayResults(

export const createQueryStringFromObject = (paramObj) => {
const params = new URLSearchParams();
Object.keys(paramObj).map((name, value) => {
params.set(
name.toString(),
name === "page" ? paramObj[name].toString() : paramObj[name]
);
Object.keys(paramObj).forEach((name) => {
params.set(name.toString(), paramObj[name]);
});
return params.toString();
};

export const createCollectionsQueryStringFromObject = (paramObj) => {
const newParams = {};
Object.keys(paramObj).map((key) => {
if (
!(
paramObj[key] === DEFAULT_SEARCH_TERM ||
paramObj[key] === DEFAULT_PAGE_NUM ||
paramObj[key] === DEFAULT_PAGE_NUM.toString() ||
paramObj[key] === DEFAULT_COLLECTION_SORT
)
) {
const defaultValues = [
DEFAULT_SEARCH_TERM,
DEFAULT_PAGE_NUM,
DEFAULT_PAGE_NUM.toString(),
DEFAULT_COLLECTION_SORT,
];
Object.keys(paramObj).forEach((key) => {
if (!defaultValues.includes(paramObj[key])) {
newParams[key] = paramObj[key];
}
});

return createQueryStringFromObject(newParams);
};

0 comments on commit 6981a26

Please sign in to comment.