Skip to content

Commit

Permalink
ui: add sort dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Dec 12, 2023
1 parent 6c8e678 commit 443d29d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
40 changes: 39 additions & 1 deletion ui/src/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from "react";
import { Select } from "antd";
import { DownOutlined } from "@ant-design/icons";

import { Result } from "@/types";
import ResultItem from "./ResultItem";
import SearchPagination from "./SearchPagination";
import { useRouter } from "next/navigation";
import { getSearchUrl } from "@/utils/utils";

interface SearchResultsProps {
results: Result[];
Expand All @@ -15,13 +19,47 @@ const SearchResults: React.FC<SearchResultsProps> = ({
count,
params,
}) => {
const router = useRouter();

const sortOptions = [
{
label: "Most recent",
value: "_created_at",
},
{
label: "Least recent",
value: "-_created_at",
},
];

const sortResults = (value: string) => {
router.push(
getSearchUrl({
...params,
page: 1,
ordering: value,
})
);
};

return (
<div>
<div className="mt-4 mb-6 flex justify-between align-center">
<p className="flex items-center">Found {count} results.</p>
<SearchPagination count={count} params={params} />
<div className="sort flex items-center">
{count > 0 && "Add sort here"}
{count > 0 && (
<Select
options={sortOptions}
placeholder="Sort by"
className="sort-dropdown"
onChange={sortResults}
>
<div>
Sort by <DownOutlined />
</div>
</Select>
)}
</div>
</div>
<ul className="border-0 border-t border-solid border-slate-200">
Expand Down
1 change: 0 additions & 1 deletion ui/src/components/search/YearFacet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const YearFacet: React.FC<YearFacetProps> = ({ data, params }) => {
return initial?.map((item) => ({
x: new Date(item?.key)?.getFullYear(),
y: item?.doc_count,
y0: 0
}));
};

Expand Down
8 changes: 8 additions & 0 deletions ui/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ a {
color: white !important;
}

.sort-dropdown {
width: 120px;
}

.sort-dropdown .ant-select-selection-placeholder {
color: #333;
}

.search-results-record-date {
color: #ccc;
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const queryTypes = [
"country",
"journal",
"publication_year__range",
"ordering"
] as const;

export type QueryType = (typeof queryTypes)[number];
Expand Down

0 comments on commit 443d29d

Please sign in to comment.