Browse Source

Fix column to use lowercase data

NowPlayingView, ListView, and PlaylistView now properly sort by
lowercase, or if a non-string, by that datatype instead
master
jeffvli 3 years ago
parent
commit
40cf38a714
  1. 14
      src/api/api.ts
  2. 20
      src/components/viewtypes/ListViewTable.tsx
  3. 9
      src/redux/playQueueSlice.ts

14
src/api/api.ts

@ -141,15 +141,11 @@ export const getPlaylists = async (sortBy: string) => {
return a.changed > b.changed ? -1 : a.changed < b.changed ? 1 : 0; return a.changed > b.changed ? -1 : a.changed < b.changed ? 1 : 0;
}) })
: sortBy === 'name' : sortBy === 'name'
? data.playlists?.playlist.sort((a: any, b: any) => { ? _.orderBy(
if (a.name < b.name) { data.playlists.playlist || [],
return -1; [(entry) => entry.name.toLowerCase()],
} 'asc'
if (a.name > b.name) { )
return 1;
}
return 0;
})
: data.playlists?.playlist; : data.playlists?.playlist;
return (newData || []).map((playlist: any) => ({ return (newData || []).map((playlist: any) => ({

20
src/components/viewtypes/ListViewTable.tsx

@ -134,13 +134,25 @@ const ListViewTable = ({
useEffect(() => { useEffect(() => {
if (!nowPlaying) { if (!nowPlaying) {
if (sortColumn && sortType) { if (sortColumn && sortType) {
const actualSortColumn = columns.find((c: any) => c.id === sortColumn); // Since the column title(id) won't always match the actual column dataKey, we need to match it
const normalizedSortColumn = columns.find(
(c: any) => c.id === sortColumn
);
const sortColumnDataKey = const sortColumnDataKey =
actualSortColumn.dataKey === 'combinedtitle' normalizedSortColumn.dataKey === 'combinedtitle'
? 'title' ? 'title'
: actualSortColumn.dataKey; : normalizedSortColumn.dataKey;
const sortData = _.orderBy(data, sortColumnDataKey, sortType); const sortData = _.orderBy(
data,
[
(entry: any) =>
typeof entry[sortColumnDataKey] === 'string'
? entry[sortColumnDataKey].toLowerCase()
: entry[sortColumnDataKey],
],
sortType
);
setSortedData(sortData); setSortedData(sortData);
} else { } else {
setSortedData(data); setSortedData(data);

9
src/redux/playQueueSlice.ts

@ -1,5 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import _ from 'lodash'; import _ from 'lodash';
import { nanoid } from 'nanoid/non-secure';
import arrayMove from 'array-move'; import arrayMove from 'array-move';
import { import {
areConsecutive, areConsecutive,
@ -243,7 +244,12 @@ const playQueueSlice = createSlice({
if (action.payload.columnDataKey !== '') { if (action.payload.columnDataKey !== '') {
state.sortedEntry = _.orderBy( state.sortedEntry = _.orderBy(
state.entry, state.entry,
action.payload.columnDataKey, [
(entry: any) =>
typeof entry[action.payload.columnDataKey] === 'string'
? entry[action.payload.columnDataKey].toLowerCase()
: entry[action.payload.columnDataKey],
],
action.payload.sortType action.payload.sortType
); );
} else { } else {
@ -251,7 +257,6 @@ const playQueueSlice = createSlice({
} }
const currentEntry = entrySelect(state); const currentEntry = entrySelect(state);
const newCurrentSongIndex = getCurrentEntryIndexByUID( const newCurrentSongIndex = getCurrentEntryIndexByUID(
action.payload.columnDataKey !== '' action.payload.columnDataKey !== ''
? state.sortedEntry ? state.sortedEntry

Loading…
Cancel
Save