Move types up

This commit is contained in:
jeffvli
2022-10-26 16:21:51 -07:00
parent 6763f4439d
commit 8f82d001f0
7 changed files with 111 additions and 248 deletions
@@ -10,10 +10,10 @@ import {
RiSkipBackFill, RiSkipBackFill,
RiSkipForwardFill, RiSkipForwardFill,
} from 'react-icons/ri'; } from 'react-icons/ri';
import { PlaybackType, PlayerStatus } from '../../../../types'; import { Text } from '@/renderer/components';
import { Text } from '../../../components'; import { usePlayerStore } from '@/renderer/store';
import { usePlayerStore } from '../../../store'; import { Font } from '@/renderer/styles';
import { Font } from '../../../styles'; import { PlaybackType, PlayerStatus } from '@/renderer/types';
import { useCenterControls } from '../hooks/use-center-controls'; import { useCenterControls } from '../hooks/use-center-controls';
import { PlayerButton } from './player-button'; import { PlayerButton } from './player-button';
import { Slider } from './slider'; import { Slider } from './slider';
@@ -1,5 +1,5 @@
import { useCallback } from 'react'; import { useCallback } from 'react';
import { PlaybackType, PlayerStatus } from '../../../../types'; import { PlaybackType, PlayerStatus } from '@/renderer/types';
import { usePlayerStore } from '../../../store'; import { usePlayerStore } from '../../../store';
import { mpvPlayer } from '../utils/mpvPlayer'; import { mpvPlayer } from '../utils/mpvPlayer';
@@ -1,17 +1,8 @@
import { api } from '@/renderer/api'; import { api } from '@/renderer/api';
import { Item, Play } from '../../../../types'; import { LibraryItem, Play } from '@/renderer/types';
import { useAuthStore, usePlayerStore } from '../../../store'; import { useAuthStore, usePlayerStore } from '../../../store';
import { mpvPlayer } from '../utils/mpvPlayer'; import { mpvPlayer } from '../utils/mpvPlayer';
const getEndpointByItemType = (item: Item) => {
switch (item) {
case Item.ALBUM:
return api.albums.getAlbumDetail;
default:
return api.albums.getAlbumDetail;
}
};
export const usePlayQueueHandler = () => { export const usePlayQueueHandler = () => {
const serverId = useAuthStore((state) => state.currentServer?.id) || ''; const serverId = useAuthStore((state) => state.currentServer?.id) || '';
const addToQueue = usePlayerStore((state) => state.addToQueue); const addToQueue = usePlayerStore((state) => state.addToQueue);
@@ -19,9 +10,8 @@ export const usePlayQueueHandler = () => {
const handlePlayQueueAdd = async (options: { const handlePlayQueueAdd = async (options: {
byData?: any[]; byData?: any[];
byItemType?: { byItemType?: {
endpoint: (params: Record<string, any>) => any;
id: number; id: number;
type: Item; type: LibraryItem;
}; };
play: Play; play: Play;
}) => { }) => {
@@ -35,44 +25,54 @@ export const usePlayQueueHandler = () => {
// localStorage.getItem('authentication') || '{}' // localStorage.getItem('authentication') || '{}'
// ); // );
if (deviceId) { if (!deviceId) return;
const endpoint = getEndpointByItemType(options.byItemType.type);
const { data } = await endpoint({ let songs = null;
if (options.byItemType.type === LibraryItem.ALBUM) {
const { data } = await api.albums.getAlbumDetail({
albumId: options.byItemType.id, albumId: options.byItemType.id,
serverId, serverId,
}); });
const songs = data.songs?.map((song) => { songs = data.songs;
// const auth = getServerFolderAuth( }
// state.serverUrl,
// song.serverFolderId
// );
// if (auth) { // const endpoint = getEndpointByItemType(options.byItemType.type);
// const streamUrl =
// auth.type === 'jellyfin'
// ? getJellyfinStreamUrl(auth, song, deviceId)
// : getSubsonicStreamUrl(auth, song, deviceId);
// return { // const { data } = await endpoint({
// ...song, // albumId: options.byItemType.id,
// streamUrl, // serverId,
// }; // });
// }
return song; // const songs = data.songs?.map((song) => {
}); // const auth = getServerFolderAuth(
// state.serverUrl,
// song.serverFolderId
// );
const playerData = addToQueue(songs || [], options.play); // if (auth) {
// const streamUrl =
// auth.type === 'jellyfin'
// ? getJellyfinStreamUrl(auth, song, deviceId)
// : getSubsonicStreamUrl(auth, song, deviceId);
console.log('playerData', playerData); // return {
// ...song,
// streamUrl,
// };
// }
if (options.play === Play.NEXT || options.play === Play.LAST) { // return song;
mpvPlayer.setQueueNext(playerData); // });
} else {
mpvPlayer.setQueue(playerData); if (!songs) return;
}
const playerData = addToQueue(songs, options.play);
if (options.play === Play.NEXT || options.play === Play.LAST) {
mpvPlayer.setQueueNext(playerData);
} else {
mpvPlayer.setQueue(playerData);
} }
} }
}; };
@@ -4,7 +4,7 @@ import {
PlaybackStyle, PlaybackStyle,
PlaybackType, PlaybackType,
PlayerRepeat, PlayerRepeat,
} from '../../../../types'; } from '@/renderer/types';
import { PlayerState } from '../../../store'; import { PlayerState } from '../../../store';
export interface WebSettings { export interface WebSettings {
+1 -1
View File
@@ -14,7 +14,7 @@ import {
PlayerRepeat, PlayerRepeat,
PlayerStatus, PlayerStatus,
UniqueId, UniqueId,
} from '../../types'; } from '@/renderer/types';
type QueueSong = Song & UniqueId; type QueueSong = Song & UniqueId;
+65
View File
@@ -8,3 +8,68 @@ export interface CardRow {
route: AppRoute | string; route: AppRoute | string;
}; };
} }
export enum LibraryItem {
ALBUM = 'album',
ALBUM_ARTIST = 'albumArtist',
ARTIST = 'artist',
PLAYLIST = 'playlist',
SONG = 'song',
}
export enum Platform {
LINUX = 'linux',
MACOS = 'macos',
WEB = 'web',
WINDOWS = 'windows',
}
export enum ServerType {
JELLYFIN = 'jellyfin',
SUBSONIC = 'subsonic',
}
export enum PlayerStatus {
PAUSED = 'paused',
PLAYING = 'playing',
}
export enum PlayerRepeat {
ALL = 'all',
NONE = 'none',
ONE = 'one',
}
export enum Play {
LAST = 'last',
NEXT = 'next',
NOW = 'now',
}
export enum CrossfadeStyle {
CONSTANT_POWER = 'constantPower',
CONSTANT_POWER_SLOW_CUT = 'constantPowerSlowCut',
CONSTANT_POWER_SLOW_FADE = 'constantPowerSlowFade',
DIPPED = 'dipped',
EQUALPOWER = 'equalPower',
LINEAR = 'linear',
}
export enum PlaybackStyle {
CROSSFADE = 'crossfade',
GAPLESS = 'gapless',
}
export enum PlaybackType {
LOCAL = 'local',
WEB = 'web',
}
export interface UniqueId {
uniqueId: string;
}
export enum SortOrder {
ASC = 'asc',
DESC = 'desc',
}
-202
View File
@@ -1,202 +0,0 @@
export enum Platform {
LINUX = 'linux',
MACOS = 'macos',
WEB = 'web',
WINDOWS = 'windows',
}
export enum ServerType {
JELLYFIN = 'jellyfin',
SUBSONIC = 'subsonic',
}
export enum Item {
ALBUM = 'album',
ALBUM_ARTIST = 'albumArtist',
ARTIST = 'artist',
FOLDER = 'folder',
GENRE = 'genre',
PLAYLIST = 'playlist',
SONG = 'song',
}
export enum PlayerStatus {
PAUSED = 'paused',
PLAYING = 'playing',
}
export enum PlayerRepeat {
ALL = 'all',
NONE = 'none',
ONE = 'one',
}
export enum Play {
LAST = 'last',
NEXT = 'next',
NOW = 'now',
}
export enum CrossfadeStyle {
CONSTANT_POWER = 'constantPower',
CONSTANT_POWER_SLOW_CUT = 'constantPowerSlowCut',
CONSTANT_POWER_SLOW_FADE = 'constantPowerSlowFade',
DIPPED = 'dipped',
EQUALPOWER = 'equalPower',
LINEAR = 'linear',
}
export enum PlaybackStyle {
CROSSFADE = 'crossfade',
GAPLESS = 'gapless',
}
export enum PlaybackType {
LOCAL = 'local',
WEB = 'web',
}
export type APIEndpoints =
| 'getPlaylist'
| 'getPlaylists'
| 'getStarred'
| 'getAlbum'
| 'getAlbums'
| 'getRandomSongs'
| 'getArtist'
| 'getArtists'
| 'getArtistInfo'
| 'getArtistSongs'
| 'startScan'
| 'getScanStatus'
| 'star'
| 'unstar'
| 'batchStar'
| 'batchUnstar'
| 'setRating'
| 'getSimilarSongs'
| 'updatePlaylistSongs'
| 'updatePlaylistSongsLg'
| 'deletePlaylist'
| 'createPlaylist'
| 'updatePlaylist'
| 'updatePlaylistSongsLg'
| 'deletePlaylist'
| 'createPlaylist'
| 'updatePlaylist'
| 'clearPlaylist'
| 'getGenres'
| 'getSearch'
| 'scrobble'
| 'getIndexes'
| 'getMusicFolders'
| 'getMusicDirectory'
| 'getMusicDirectorySongs'
| 'getDownloadUrl'
| 'getSongs'
| 'getTopSongs'
| 'getSongsByGenre'
| 'getLyrics';
export interface APIResult {
data: Album[] | Artist[] | Genre[] | Song[];
totalRecordCount?: number;
}
interface RelatedItem {
deleted?: boolean;
id: string;
name: string;
remoteId?: string;
}
export interface Album {
albumArtist: AlbumArtist;
averageRating: number;
container: string;
createdAt: string;
date: string;
deleted: boolean;
genres: RelatedItem[];
id: number;
imageUrl: string;
name: string;
rating: number;
remoteCreatedAt: string;
remoteId: string;
serverFolderId: number;
serverType: ServerType | string;
songCount: number;
songs: Song[];
updatedAt: string;
year: number;
}
export interface AlbumArtist {
biography?: string;
createdAt: string;
deleted: boolean;
id: number;
name: string;
remoteCreatedAt: string;
remoteId: string;
serverId: number;
updatedAt: string;
}
export interface Artist {
biography?: string;
createdAt: string;
deleted: boolean;
id: number;
name: string;
remoteCreatedAt: string;
remoteId: string;
serverId: number;
updatedAt: string;
}
export interface Genre {
id: string;
name: string;
}
export interface Song {
album: RelatedItem;
artistName: null;
artists: RelatedItem[];
bitRate: number;
container: string;
createdAt: string;
date: string;
deleted: boolean;
disc: number;
duration: number;
genres: RelatedItem[];
id: number;
imageUrl: string;
name: string;
remoteCreatedAt: string;
remoteId: string;
serverFolderId: number;
serverId: number;
streamUrl: string;
track: number;
updatedAt: string;
year: number;
}
export interface ServerFolderAuth {
id: number;
locked: boolean;
serverId: number;
token: string;
type: string;
url: string;
userId: string;
username: string;
}
export interface UniqueId {
uniqueId: string;
}