Skip to content

Commit 6eacd0e

Browse files
committed
Remove knowledge of default sorting order from parent component
1 parent ef1515c commit 6eacd0e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/components/extensions-list.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useState } from "react"
33
import Filters from "./filters/filters"
44
import ExtensionCard from "./extension-card"
55
import styled from "styled-components"
6-
import { timestampExtensionComparator } from "./sortings/timestamp-extension-comparator"
76
import Sortings from "./sortings/sortings"
87

98
const FilterableList = styled.div`
@@ -57,15 +56,17 @@ const ExtensionsList = ({ extensions, categories, downloadData }) => {
5756
const allExtensions = extensions.filter(extension => !extension.isSuperseded)
5857

5958
const [filteredExtensions, setExtensions] = useState(allExtensions)
60-
const [extensionComparator, setExtensionComparator] = useState(() => timestampExtensionComparator)
59+
const [extensionComparator, setExtensionComparator] = useState(() => undefined)
6160

6261
if (allExtensions) {
6362
// Exclude unlisted extensions from the count, even though we sometimes show them if there's a direct search for it
6463
const extensionCount = allExtensions.filter(
6564
extension => !extension.metadata.unlisted
6665
).length
6766

68-
filteredExtensions.sort(extensionComparator)
67+
if (extensionComparator) {
68+
filteredExtensions.sort(extensionComparator)
69+
}
6970

7071
const countMessage =
7172
extensionCount === filteredExtensions.length

src/components/sortings/sortings.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ const colourStyles = {
7777

7878
const key = "sort"
7979
const downloads = "downloads"
80-
80+
const time = "time"
8181
const sortings = [
82-
{ label: "Most recently released", value: "time", comparator: timestampExtensionComparator },
82+
{ label: "Most recently released", value: time, comparator: timestampExtensionComparator },
8383
{ label: "Alphabetical", value: "alpha", comparator: alphabeticalExtensionComparator },
8484
{ label: "Downloads", value: downloads, comparator: downloadsExtensionComparator }]
8585

8686
const Sortings = ({ sorterAction, downloadData }) => {
87-
const [sort, setSort] = useQueryParamString(key, undefined, true)
87+
const [sort, setSort] = useQueryParamString(key, time, true)
8888

8989
const applySort = (entry) => {
9090
// 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 }) => {
100100
applySort(selected)
101101
}
102102

103-
104103
const formattedDate = downloadData?.date ? format.format(new Date(Number(downloadData.date))) : ""
105104

106-
107105
return (
108106
<SortBar className="sortings">
109107
{sort === downloads &&

0 commit comments

Comments
 (0)