From 6eacd0edc123e721afe49b923cc2db25910f332b Mon Sep 17 00:00:00 2001 From: Holly Cummins Date: Wed, 13 Mar 2024 18:40:53 +0000 Subject: [PATCH] Remove knowledge of default sorting order from parent component --- src/components/extensions-list.js | 7 ++++--- src/components/sortings/sortings.js | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/extensions-list.js b/src/components/extensions-list.js index 6bd7dcb899c4..6776b61d444c 100644 --- a/src/components/extensions-list.js +++ b/src/components/extensions-list.js @@ -3,7 +3,6 @@ import { useState } from "react" import Filters from "./filters/filters" import ExtensionCard from "./extension-card" import styled from "styled-components" -import { timestampExtensionComparator } from "./sortings/timestamp-extension-comparator" import Sortings from "./sortings/sortings" const FilterableList = styled.div` @@ -57,7 +56,7 @@ const ExtensionsList = ({ extensions, categories, downloadData }) => { const allExtensions = extensions.filter(extension => !extension.isSuperseded) const [filteredExtensions, setExtensions] = useState(allExtensions) - const [extensionComparator, setExtensionComparator] = useState(() => timestampExtensionComparator) + const [extensionComparator, setExtensionComparator] = useState(() => undefined) if (allExtensions) { // Exclude unlisted extensions from the count, even though we sometimes show them if there's a direct search for it @@ -65,7 +64,9 @@ const ExtensionsList = ({ extensions, categories, downloadData }) => { extension => !extension.metadata.unlisted ).length - filteredExtensions.sort(extensionComparator) + if (extensionComparator) { + filteredExtensions.sort(extensionComparator) + } const countMessage = extensionCount === filteredExtensions.length diff --git a/src/components/sortings/sortings.js b/src/components/sortings/sortings.js index c6622f19a045..34128e8eb1c6 100644 --- a/src/components/sortings/sortings.js +++ b/src/components/sortings/sortings.js @@ -77,14 +77,14 @@ const colourStyles = { const key = "sort" const downloads = "downloads" - +const time = "time" const sortings = [ - { label: "Most recently released", value: "time", comparator: timestampExtensionComparator }, + { label: "Most recently released", value: time, comparator: timestampExtensionComparator }, { label: "Alphabetical", value: "alpha", comparator: alphabeticalExtensionComparator }, { label: "Downloads", value: downloads, comparator: downloadsExtensionComparator }] const Sortings = ({ sorterAction, downloadData }) => { - const [sort, setSort] = useQueryParamString(key, undefined, true) + const [sort, setSort] = useQueryParamString(key, time, true) const applySort = (entry) => { // We need to wrap our comparator functions in functions or they get called, which goes very badly @@ -100,10 +100,8 @@ const Sortings = ({ sorterAction, downloadData }) => { applySort(selected) } - const formattedDate = downloadData?.date ? format.format(new Date(Number(downloadData.date))) : "" - return ( {sort === downloads &&