Skip to content

Commit

Permalink
Fix sorting on RSC
Browse files Browse the repository at this point in the history
  • Loading branch information
switz committed Dec 13, 2023
1 parent bfd910e commit b772b95
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/app/queries.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sortSources } from '@/redux/modules/tapes';
import { Artist, Tape } from '@/types';
import ky from 'ky-universal';
import { API_DOMAIN } from '../lib/constants';
import { Artist, Tape } from '@/types';

export const fetchArtists = async (): Promise<Artist[]> => {
const parsed = await ky(`${API_DOMAIN}/api/v2/artists`, {
Expand All @@ -25,5 +26,7 @@ export const fetchShow = async (
cache: 'no-cache',
}).json()) as Tape;

parsed.sources = sortSources(parsed.sources);

return parsed;
};
46 changes: 23 additions & 23 deletions src/redux/modules/tapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,27 @@ const getEtreeId = (s = '') =>

// tapes: TODO: GD sort (charlie miller, sbd + etree id, weighted average), sbd + etree id, weighted avg, asc, desc
// for now, hardcode sort: sbd, charlie miller, etree id, weighted average
const sortTapes = (data = {}) => {
const sortedTapes =
data && data.sources
? [...data.sources].sort(
firstBy((t) => t.is_soundboard, 'desc')
// Charlie for GD, Pete for JRAD
.thenBy((t) =>
export const sortSources = (sources) => {
const sortedSources = sources
? [...sources].sort(
firstBy((t) => t.is_soundboard, 'desc')
// Charlie for GD, Pete for JRAD
.thenBy(
(t) =>
/(charlie miller)|(peter costello)/i.test(
[t.taper, t.transferrer, t.source].join(''),
'desc'
)
)
.thenBy(
(t1, t2) => getEtreeId(t1.upstream_identifier) - getEtreeId(t2.upstream_identifier),
'desc'
)
.thenBy((t) => t.avg_rating_weighted, 'desc')
)
: [];
[t.taper, t.transferrer, t.source].join('')
),
'desc'
)
.thenBy(
(t1, t2) => getEtreeId(t1.upstream_identifier) - getEtreeId(t2.upstream_identifier),
'desc'
)
.thenBy((t) => t.avg_rating_weighted, 'desc')
)
: [];

return {
...(data || {}),
sources: sortedTapes.reverse(),
};
return sortedSources;
};

export function requestTapes(artistSlug, year, showDate) {
Expand All @@ -101,7 +98,10 @@ export function receiveTapes(artistSlug, year, showDate, data) {
artistSlug,
year,
showDate,
data: sortTapes(data),
data: {
...data,
sources: sortSources(data.sources),
},
};
}

Expand Down

0 comments on commit b772b95

Please sign in to comment.