Skip to content

Commit

Permalink
frontend: add creation date sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Dec 20, 2024
1 parent 3b3c6a9 commit e4f7b7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 5 additions & 3 deletions zettelkasten-front/src/pages/cards/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function SearchPage({
cards,
setCards,
}: SearchPageProps) {
const [sortBy, setSortBy] = useState("sortNewOld");
const [sortBy, setSortBy] = useState("sortCreatedNewOld");
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage, setItemsPerPage] = useState(20);
const { partialCards } = usePartialCardContext();
Expand Down Expand Up @@ -221,8 +221,10 @@ export function SearchPage({
children={"Search"}
/>
<select value={sortBy} onChange={handleSortChange}>
<option value="sortNewOld">Newest</option>
<option value="sortOldNew">Oldest</option>
<option value="sortCreatedNewOld">Creation Date (Newest)</option>
<option value="sortCreatedOldNew">Creation Date (Oldest)</option>
<option value="sortNewOld">Last Updated (Newest)</option>
<option value="sortOldNew">Last Updated (Oldest)</option>
<option value="sortBigSmall">A to Z</option>
<option value="sortSmallBig">Z to A</option>
</select>
Expand Down
17 changes: 10 additions & 7 deletions zettelkasten-front/src/utils/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ export function sortCards(cards, value) {
});
} else if (value === "sortNewOld") {
temp.sort((a, b) => {
return (
new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
);
return new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime();
});
} else if (value === "sortOldNew") {
temp.sort((a, b) => {
return (
new Date(a.updated_at).getTime() - new Date(b.updated_at).getTime()
);
return new Date(a.updated_at).getTime() - new Date(b.updated_at).getTime();
});
} else if (value === "sortCreatedNewOld") {
temp.sort((a, b) => {
return new Date(b.created_at).getTime() - new Date(a.created_at).getTime();
});
} else if (value === "sortCreatedOldNew") {
temp.sort((a, b) => {
return new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
});
} else {
}
return temp;
}
Expand Down

0 comments on commit e4f7b7e

Please sign in to comment.