Browse Source

Remove "Entry" type in favor of Song

master
jeffvli 3 years ago
committed by Jeff
parent
commit
ee8dcba5e5
  1. 6
      src/components/search/SearchView.tsx
  2. 3
      src/redux/miscSlice.ts
  3. 11
      src/redux/multiSelectSlice.ts
  4. 69
      src/redux/playQueueSlice.ts
  5. 21
      src/redux/playlistSlice.ts

6
src/components/search/SearchView.tsx

@ -9,7 +9,7 @@ import useRouterQuery from '../../hooks/useRouterQuery';
import GenericPage from '../layout/GenericPage';
import GenericPageHeader from '../layout/GenericPageHeader';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { Entry, fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice';
import { fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice';
import { setStatus } from '../../redux/playerSlice';
import {
StyledButton,
@ -19,7 +19,7 @@ import {
StyledNavItem,
} from '../shared/styled';
import { apiController } from '../../api/controller';
import { Album, Artist, Item } from '../../types';
import { Album, Artist, Item, Song } from '../../types';
import useListClickHandler from '../../hooks/useListClickHandler';
import ListViewType from '../viewtypes/ListViewType';
@ -39,7 +39,7 @@ const SearchView = () => {
const [nav, setNav] = useState<'songs' | 'albums' | 'artists'>('songs');
const [artistData, setArtistData] = useState<Artist[]>([]);
const [albumData, setAlbumData] = useState<Album[]>([]);
const [songData, setSongData] = useState<Entry[]>([]);
const [songData, setSongData] = useState<Song[]>([]);
useEffect(() => {
if (folder.applied.search) {

3
src/redux/miscSlice.ts

@ -2,7 +2,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import settings from 'electron-settings';
import { mockSettings } from '../shared/mockSettings';
import { getImageCachePath, getSongCachePath } from '../shared/utils';
import { Entry } from './playQueueSlice';
const parsedSettings: any = process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync();
@ -41,7 +40,7 @@ export interface ContextMenu {
yPos?: number;
rowId?: string;
type?: string;
details?: Entry;
details?: any;
disabledOptions?: ContextMenuOptions[];
}

11
src/redux/multiSelectSlice.ts

@ -1,5 +1,4 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { Entry } from './playQueueSlice';
interface MultiSelect {
lastSelected: Record<string, unknown>;
@ -31,8 +30,8 @@ const multiSelectSlice = createSlice({
name: 'multiSelect',
initialState,
reducers: {
/* updateSelected: (state, action: PayloadAction<Entry[]>) => {
const newSelected: Entry[] = [];
/* updateSelected: (state, action: PayloadAction<any>) => {
const newSelected: any = [];
state.selected.map((entry: Entry) => {
const matchedEntry = action.payload.find(
(item: Entry) => item.uniqueId === entry.uniqueId
@ -65,7 +64,7 @@ const multiSelectSlice = createSlice({
state.currentMouseOverIndex = action.payload.index;
},
setSelected: (state, action: PayloadAction<Entry[]>) => {
setSelected: (state, action: PayloadAction<any>) => {
state.selected = action.payload;
},
@ -81,8 +80,8 @@ const multiSelectSlice = createSlice({
state.selected.push(action.payload);
},
appendSelected: (state, action: PayloadAction<Entry[]>) => {
action.payload.forEach((entry: Entry) => {
appendSelected: (state, action: PayloadAction<any>) => {
action.payload.forEach((entry: any) => {
const alreadySelected = state.selected.find((item) => item.uniqueId === entry.uniqueId);
if (!alreadySelected) {

69
src/redux/playQueueSlice.ts

@ -10,39 +10,10 @@ import {
moveSelectedUp,
} from '../shared/utils';
import { mockSettings } from '../shared/mockSettings';
import { Song } from '../types';
const parsedSettings = process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync();
export interface Entry {
id: string;
album: string;
albumId: string;
artist: string;
bitRate: number;
contentType: string;
coverArt: string;
created: string;
duration: string;
genre: string;
index: number;
isDir: boolean;
isVideo: boolean;
parent: string;
path: string;
playCount: number;
size: number;
starred?: string;
streamUrl: string;
suffix: string;
title: string;
track: number;
type: string;
year: number;
userRating?: number;
uniqueId: string;
rowIndex: number;
}
export interface PlayQueue {
player1: {
src: string;
@ -82,9 +53,9 @@ export interface PlayQueue {
sortType: 'asc' | 'desc';
displayQueue: boolean;
showDebugWindow: boolean;
entry: Entry[];
shuffledEntry: Entry[];
sortedEntry: Entry[];
entry: Song[];
shuffledEntry: Song[];
sortedEntry: Song[];
}
const initialState: PlayQueue = {
@ -132,6 +103,7 @@ const initialState: PlayQueue = {
const resetPlayerDefaults = (state: PlayQueue) => {
state.isFading = false;
state.current = undefined;
state.currentIndex = 0;
state.currentSongId = '';
state.currentPlayer = 1;
@ -600,7 +572,7 @@ const playQueueSlice = createSlice({
}
},
setPlayerIndex: (state, action: PayloadAction<Entry>) => {
setPlayerIndex: (state, action: PayloadAction<Song>) => {
const currentEntry = entrySelect(state);
const findIndex = getCurrentEntryIndexByUID(state[currentEntry], action.payload.uniqueId);
@ -669,7 +641,7 @@ const playQueueSlice = createSlice({
}
},
setCurrentIndex: (state, action: PayloadAction<Entry>) => {
setCurrentIndex: (state, action: PayloadAction<Song>) => {
const currentEntry = entrySelect(state);
const findIndex = getCurrentEntryIndexByUID(state[currentEntry], action.payload.uniqueId);
@ -683,7 +655,7 @@ const playQueueSlice = createSlice({
setPlayQueue: (
state,
action: PayloadAction<{
entries: Entry[];
entries: Song[];
}>
) => {
// Used with gridview where you just want to set the entry queue directly
@ -710,7 +682,7 @@ const playQueueSlice = createSlice({
setPlayQueueByRowClick: (
state,
action: PayloadAction<{
entries: Entry[];
entries: Song[];
currentIndex: number;
currentSongId: string;
uniqueSongId: string;
@ -741,6 +713,8 @@ const playQueueSlice = createSlice({
filteredFromCurrentToEnd
);
const current = entries.find((entry) => entry.uniqueId === action.payload.uniqueSongId);
state.entry = entries;
if (state.shuffle) {
@ -759,10 +733,6 @@ const playQueueSlice = createSlice({
state.currentIndex = 0;
state.player1.index = 0;
const current = action.payload.entries.find(
(entry) => entry.uniqueId === action.payload.uniqueSongId
);
state.current = current;
state.currentSongId = action.payload.currentSongId;
state.currentSongUniqueId = action.payload.uniqueSongId;
@ -771,7 +741,7 @@ const playQueueSlice = createSlice({
return entry.uniqueId === action.payload.uniqueSongId;
});
state.current = action.payload.entries[currentIndex];
state.current = current;
state.currentIndex = currentIndex;
state.player1.index = currentIndex;
state.currentSongId = action.payload.currentSongId;
@ -781,7 +751,7 @@ const playQueueSlice = createSlice({
appendPlayQueue: (
state,
action: PayloadAction<{ entries: Entry[]; type: 'next' | 'later' }>
action: PayloadAction<{ entries: Song[]; type: 'next' | 'later' }>
) => {
const isEmptyQueue = state.entry.length < 1;
// We'll need to update the uniqueId otherwise selecting a song with duplicates
@ -831,7 +801,7 @@ const playQueueSlice = createSlice({
}
},
removeFromPlayQueue: (state, action: PayloadAction<{ entries: Entry[] }>) => {
removeFromPlayQueue: (state, action: PayloadAction<{ entries: Song[] }>) => {
const uniqueIds = _.map(action.payload.entries, 'uniqueId');
state.entry = state.entry.filter((entry) => !uniqueIds.includes(entry.uniqueId));
@ -892,6 +862,7 @@ const playQueueSlice = createSlice({
clearPlayQueue: (state) => {
state.entry = [];
state.shuffledEntry = [];
state.current = undefined;
resetPlayerDefaults(state);
},
@ -907,7 +878,7 @@ const playQueueSlice = createSlice({
state.isFading = action.payload;
},
moveToIndex: (state, action: PayloadAction<Entry[]>) => {
moveToIndex: (state, action: PayloadAction<Song[]>) => {
const currentEntry = entrySelect(state);
// Set the modified entries into the redux state
@ -929,7 +900,7 @@ const playQueueSlice = createSlice({
state.currentIndex = newCurrentSongIndex;
},
moveToTop: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveToTop: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
const currentEntry = entrySelect(state);
const newQueue = moveSelectedToTop(state[currentEntry], action.payload.selectedEntries);
state[currentEntry] = newQueue;
@ -947,7 +918,7 @@ const playQueueSlice = createSlice({
state.currentIndex = newCurrentSongIndex;
},
moveToBottom: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveToBottom: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
const currentEntry = entrySelect(state);
const newQueue = moveSelectedToBottom(state[currentEntry], action.payload.selectedEntries);
state[currentEntry] = newQueue;
@ -965,7 +936,7 @@ const playQueueSlice = createSlice({
state.currentIndex = newCurrentSongIndex;
},
moveUp: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveUp: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
const currentEntry = entrySelect(state);
state[currentEntry] = moveSelectedUp(state[currentEntry], action.payload.selectedEntries);
@ -985,7 +956,7 @@ const playQueueSlice = createSlice({
state.currentIndex = newCurrentSongIndex;
},
moveDown: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveDown: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
const currentEntry = entrySelect(state);
state[currentEntry] = moveSelectedDown(state[currentEntry], action.payload.selectedEntries);

21
src/redux/playlistSlice.ts

@ -6,8 +6,7 @@ import {
moveSelectedToTop,
moveSelectedUp,
} from '../shared/utils';
import { Sort } from '../types';
import { Entry } from './playQueueSlice';
import { Sort, Song } from '../types';
export interface Playlist {
active: {
@ -18,8 +17,8 @@ export interface Playlist {
sort: Sort;
};
};
entry: Entry[];
sortedEntry: Entry[];
entry: Song[];
sortedEntry: Song[];
}
const initialState: Playlist = {
@ -55,7 +54,7 @@ const playlistSlice = createSlice({
}
},
setPlaylistData: (state, action: PayloadAction<Entry[]>) => {
setPlaylistData: (state, action: PayloadAction<Song[]>) => {
state.entry = action.payload;
},
@ -79,28 +78,28 @@ const playlistSlice = createSlice({
}
},
removeFromPlaylist: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
removeFromPlaylist: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
const uniqueIds = _.map(action.payload.selectedEntries, 'uniqueId');
state.entry = state.entry.filter((entry) => !uniqueIds.includes(entry.uniqueId));
},
moveToIndex: (state, action: PayloadAction<Entry[]>) => {
moveToIndex: (state, action: PayloadAction<Song[]>) => {
state.entry = action.payload;
},
moveUp: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveUp: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
state.entry = moveSelectedUp(state.entry, action.payload.selectedEntries);
},
moveDown: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveDown: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
state.entry = moveSelectedDown(state.entry, action.payload.selectedEntries);
},
moveToTop: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveToTop: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
state.entry = moveSelectedToTop(state.entry, action.payload.selectedEntries);
},
moveToBottom: (state, action: PayloadAction<{ selectedEntries: Entry[] }>) => {
moveToBottom: (state, action: PayloadAction<{ selectedEntries: Song[] }>) => {
state.entry = moveSelectedToBottom(state.entry, action.payload.selectedEntries);
},

Loading…
Cancel
Save