diff --git a/components/ModList.tsx b/components/ModList.tsx index 9e886de..41989ed 100644 --- a/components/ModList.tsx +++ b/components/ModList.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ import { format } from "date-fns"; import React, { useEffect, useRef, useState } from "react"; import MiniSearch from "minisearch"; @@ -28,6 +29,7 @@ type ModWithCounts = Mod & { const ModList: React.FC = ({ mods, files, counts }) => { const [includeTranslations, setIncludeTranslations] = useState(true); const [sortBy, setSortBy] = useState("unique_downloads"); + const [sortAsc, setSortAsc] = useState(false); const [filter, setFilter] = useState(""); const [category, setCategory] = useState("All"); const [filterResults, setFilterResults] = useState>(new Set()); @@ -60,15 +62,17 @@ const ModList: React.FC = ({ mods, files, counts }) => { const aVal = a[sortBy]; const bVal = b[sortBy]; if (typeof aVal === "number" && typeof bVal === "number") { - return bVal - aVal; + return sortAsc ? aVal - bVal : bVal - aVal; } else if ( typeof aVal === "string" && typeof bVal === "string" && ["first_upload_at", "last_update_at"].includes(sortBy) ) { - return new Date(bVal).getTime() - new Date(aVal).getTime(); + const aTime = new Date(aVal).getTime(); + const bTime = new Date(bVal).getTime(); + return sortAsc ? aTime - bTime : bTime - aTime; } else if (typeof aVal === "string" && typeof bVal === "string") { - return aVal.localeCompare(bVal); + return sortAsc ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal); } return 0; }); @@ -129,6 +133,38 @@ const ModList: React.FC = ({ mods, files, counts }) => { +
+ + +
diff --git a/public/img/arrow-disabled.svg b/public/img/arrow-disabled.svg new file mode 100644 index 0000000..1043633 --- /dev/null +++ b/public/img/arrow-disabled.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/arrow-selected.svg b/public/img/arrow-selected.svg new file mode 100644 index 0000000..634c4a5 --- /dev/null +++ b/public/img/arrow-selected.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/ModList.module.css b/styles/ModList.module.css index b658b29..af24a51 100644 --- a/styles/ModList.module.css +++ b/styles/ModList.module.css @@ -56,7 +56,13 @@ } .sort-by { - min-width: 175px; + min-width: 119px; +} + +.sort-asc { + margin-left: 8px; + min-width: 50px; + max-width: 50px; } .category { @@ -71,3 +77,33 @@ .include-translations input { margin-right: 8px; } + +.sort-direction { + display: flex; + flex-direction: row; + margin-left: 8px; +} + +.sort-direction button { + width: 24px; + height: 20px; + display: block; + outline: none; + border: 0; + background-color: transparent; + cursor: pointer; + overflow: hidden; +} + +.sort-direction button img { + width: 100%; + height: 100%; +} + +.asc { + transform: rotate(-90deg); +} + +.desc { + transform: rotate(90deg); +}