Skip to content

Commit

Permalink
Make sorting by release date work
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Dec 17, 2023
1 parent 3901c3d commit b52434d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/routes/Setlist/SortChanger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SortChanger: React.FC<Props> = ({ onChange }: Props) => {
type="single"
defaultValue="title"
onValueChange={(value: SortType) => onChange(value)}>

<ToggleGroup.Item className={styles.item} value="title">
<NoteIcon />
Track
Expand All @@ -28,7 +28,7 @@ const SortChanger: React.FC<Props> = ({ onChange }: Props) => {
<TimeIcon />
Length
</ToggleGroup.Item>
<ToggleGroup.Item className={styles.item} value="release">
<ToggleGroup.Item className={styles.item} value="releaseDate">
<DateIcon />
Release
</ToggleGroup.Item>
Expand Down
38 changes: 24 additions & 14 deletions src/routes/Setlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SetlistPage: React.FC<Props> = ({ setlistId }: Props) => {
const setlistData = useSetlistRelease(setlistId);
const { state, download, payload } = useSetlistData(setlistData);
const [ sortType, setSortType ] = useState("title" as SortType);

const dialogManager = useDialogManager();

function SetlistButton(props: SetlistButtonProps) {
Expand All @@ -52,33 +52,43 @@ const SetlistPage: React.FC<Props> = ({ setlistId }: Props) => {
</Button>;
}
}

const newestSongRelease = setlistData.songs.reduce((prev, curr) =>
new Date(prev.releaseDate).getTime() > new Date(curr.releaseDate).getTime() ? prev : curr);

return <>
<div className={styles.banner} />
<div className={styles.main}>
<div className={styles.content}>
<SortChanger onChange={(s) => setSortType(s)} />

<GenericBoxSlim>
{sortArray(setlistData.songs, { by: "order", computed: {
order: i => {
const value = i[sortType];

if (typeof value === "string") {
return value.toLowerCase();
{sortArray(setlistData.songs, {
by: "order",
order: sortType === "releaseDate" ? "desc" : "asc",
computed: {
order: i => {
const value = i[sortType];

// Speical case for release date
if (sortType === "releaseDate" && typeof value === "string") {
return new Date(value).getTime();
}

// Make sure strings are in all lowercase for proper sorting
if (typeof value === "string") {
return value.toLowerCase();
}

return value;
}

return value;
}
}}).map(i =>
}).map(i =>
<SongEntry title={i.title} artist={i.artist} length={i.length}
newSong={isConsideredNewRelease(i.releaseDate, newestSongRelease.releaseDate)} key={i.title} />
)}
</GenericBoxSlim>

<div className={styles.content_spacer}></div>
<NewsSection categoryFilter="setlist_official" startingEntries={2} />
</div>
Expand Down

0 comments on commit b52434d

Please sign in to comment.