Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: add sort dropdown #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "_updated_at",
},
{
label: "Least recent",
value: "-_updated_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