Normalize types

This commit is contained in:
jeffvli
2022-08-20 02:06:00 -07:00
parent a087dbdea3
commit dd6b80795e
9 changed files with 93 additions and 89 deletions
@@ -154,14 +154,14 @@ export const AudioPlayer = forwardRef(
ref={player1Ref}
height={0}
muted={muted}
playing={currentPlayer === 1 && status === PlayerStatus.Playing}
playing={currentPlayer === 1 && status === PlayerStatus.PLAYING}
progressInterval={isTransitioning ? 10 : 250}
url={player1?.streamUrl}
volume={volume}
width={0}
onEnded={handleOnEnded}
onProgress={
playbackStyle === PlaybackStyle.Gapless
playbackStyle === PlaybackStyle.GAPLESS
? handleGapless1
: handleCrossfade1
}
@@ -170,14 +170,14 @@ export const AudioPlayer = forwardRef(
ref={player2Ref}
height={0}
muted={muted}
playing={currentPlayer === 2 && status === PlayerStatus.Playing}
playing={currentPlayer === 2 && status === PlayerStatus.PLAYING}
progressInterval={isTransitioning ? 10 : 250}
url={player2?.streamUrl}
volume={volume}
width={0}
onEnded={handleOnEnded}
onProgress={
playbackStyle === PlaybackStyle.Gapless
playbackStyle === PlaybackStyle.GAPLESS
? handleGapless2
: handleCrossfade2
}
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
import format from 'format-duration';
import { useTranslation } from 'react-i18next';
import {
RiPauseFill,
RiPauseLine,
RiPlayFill,
RiRewindFill,
RiSkipBackFill,
@@ -88,8 +88,8 @@ export const CenterControls = ({ playersRef }: CenterControlsProps) => {
useEffect(() => {
let interval: any;
if (status === PlayerStatus.Playing && !isSeeking) {
if (settings.type === PlaybackType.Web) {
if (status === PlayerStatus.PLAYING && !isSeeking) {
if (settings.type === PlaybackType.WEB) {
interval = setInterval(() => {
setCurrentTime(currentPlayerRef.getCurrentTime());
}, 1000);
@@ -119,15 +119,15 @@ export const CenterControls = ({ playersRef }: CenterControlsProps) => {
/>
<PlayerButton
icon={
status === PlayerStatus.Paused ? (
status === PlayerStatus.PAUSED ? (
<RiPlayFill size={20} />
) : (
<RiPauseFill size={20} />
<RiPauseLine size={20} stroke="20px" />
)
}
tooltip={{
label:
status === PlayerStatus.Paused
status === PlayerStatus.PAUSED
? `${t('player.play')}`
: `${t('player.pause')}`,
}}
@@ -67,7 +67,7 @@ export const LeftControls = () => {
to="/nowplaying"
weight={500}
>
{album || '—'}
{album?.name || '—'}
</Text>
</MetadataStack>
</LeftControlsContainer>
@@ -65,7 +65,7 @@ export const Playerbar = () => {
<RightControls />
</RightGridItem>
</PlayerbarControlsGrid>
{settings.type === PlaybackType.Web && (
{settings.type === PlaybackType.WEB && (
<AudioPlayer
ref={playersRef}
autoNext={autoNext}
@@ -16,12 +16,12 @@ export type PlayerSettings = PlayerState['settings'];
const DEFAULT_SETTINGS: WebSettings = {
player: {
crossfadeDuration: 5,
crossfadeStyle: CrossfadeStyle.EqualPower,
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
muted: false,
repeat: PlayerRepeat.All,
repeat: PlayerRepeat.ALL,
shuffle: false,
style: PlaybackStyle.Gapless,
type: isElectron() ? PlaybackType.Local : PlaybackType.Web,
style: PlaybackStyle.GAPLESS,
type: isElectron() ? PlaybackType.LOCAL : PlaybackType.WEB,
volume: 0.5,
},
};
+7 -7
View File
@@ -122,7 +122,7 @@ export const usePlayerStore = create<PlayerSlice>()(
index: 0,
player: 1,
song: {} as Song,
status: PlayerStatus.Paused,
status: PlayerStatus.PAUSED,
time: 0,
},
getPlayerData: () => {
@@ -171,14 +171,14 @@ export const usePlayerStore = create<PlayerSlice>()(
pause: () => {
set(
produce((state) => {
state.current.status = PlayerStatus.Paused;
state.current.status = PlayerStatus.PAUSED;
})
);
},
play: () => {
set(
produce((state) => {
state.current.status = PlayerStatus.Playing;
state.current.status = PlayerStatus.PLAYING;
})
);
},
@@ -228,12 +228,12 @@ export const usePlayerStore = create<PlayerSlice>()(
},
settings: {
crossfadeDuration: 5,
crossfadeStyle: CrossfadeStyle.EqualPower,
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
muted: false,
repeat: PlayerRepeat.None,
repeat: PlayerRepeat.NONE,
shuffle: false,
style: PlaybackStyle.Gapless,
type: PlaybackType.Local,
style: PlaybackStyle.GAPLESS,
type: PlaybackType.LOCAL,
volume: 50,
},
}))
+26 -5
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */
import meanBy from 'lodash/meanBy';
import { Rating, User } from '../types/types';
import { Item, Rating, User } from '../types/types';
import { getImageUrl } from '../utils';
const getSubsonicStreamUrl = (
@@ -71,12 +71,23 @@ const streamUrl = (
return '';
};
const relatedAlbum = (item: any) => {
return {
deleted: item.deleted,
id: item.id,
itemType: Item.ALBUM,
name: item.name,
remoteId: item.remoteId,
};
};
const relatedArtists = (items: any[]) => {
return (
items?.map((item: any) => {
return {
deleted: item.deleted,
id: item.id,
itemType: Item.ARTIST,
name: item.name,
remoteId: item.remoteId,
};
@@ -84,11 +95,21 @@ const relatedArtists = (items: any[]) => {
);
};
const relatedAlbumArtist = (item: any) => {
return {
deleted: item.deleted,
id: item.id,
itemType: item.ALBUMARTIST,
name: item.name,
remoteId: item.remoteId,
};
};
const relatedGenres = (genres: any[]) => {
return (
genres?.map((genre) => {
return {
id: genre.id,
itemType: Item.GENRE,
name: genre.name,
};
}) || []
@@ -128,8 +149,7 @@ const songs = (
const url = options.url ? options.url : item.server.serverUrls[0];
return {
album: item.album.name,
albumId: item.albumId,
album: item.album && relatedAlbum(item.album),
artistName: item.artistName,
artists: relatedArtists(item.artists),
bitRate: item.bitRate,
@@ -144,6 +164,7 @@ const songs = (
imageUrl:
primaryImage(item.images, serverType, url, item.remoteId) ||
options.imageUrl,
itemType: Item.SONG,
name: item.name,
remoteCreatedAt: item.remoteCreatedAt,
remoteId: item.remoteId,
@@ -181,8 +202,7 @@ const albums = (items: any[], user: User) => {
);
return {
albumArtist: item.albumArtist,
albumArtistId: item.albumArtistId,
albumArtist: item.albumArtist && relatedAlbumArtist(item.albumArtist),
averageRating,
createdAt: item.createdAt,
date: item.date,
@@ -190,6 +210,7 @@ const albums = (items: any[], user: User) => {
genres: relatedGenres(item.genres),
id: item.id,
imageUrl,
itemType: Item.ALBUM,
name: item.name,
rating,
remoteCreatedAt: item.remoteCreatedAt,
+10
View File
@@ -3,6 +3,16 @@ export enum SortOrder {
DESC = 'desc',
}
export enum Item {
ALBUM = 'album',
ALBUM_ARTIST = 'albumArtist',
ARTIST = 'artist',
FOLDER = 'folder',
GENRE = 'genre',
PLAYLIST = 'playlist',
SONG = 'song',
}
export enum AlbumFilter {
FAVORITED,
NOT_FAVORITED,
+34 -61
View File
@@ -1,17 +1,18 @@
export enum Platform {
Linux = 'linux',
MacOS = 'macos',
Web = 'web',
Windows = 'windows',
LINUX = 'linux',
MACOS = 'macos',
WEB = 'web',
WINDOWS = 'windows',
}
export enum ServerType {
Jellyfin = 'jellyfin',
Subsonic = 'subsonic',
JELLYFIN = 'jellyfin',
SUBSONIC = 'subsonic',
}
export enum Item {
ALBUM = 'album',
ALBUM_ARTIST = 'albumArtist',
ARTIST = 'artist',
FOLDER = 'folder',
GENRE = 'genre',
@@ -20,14 +21,14 @@ export enum Item {
}
export enum PlayerStatus {
Paused = 'paused',
Playing = 'playing',
PAUSED = 'paused',
PLAYING = 'playing',
}
export enum PlayerRepeat {
All = 'all',
None = 'none',
One = 'one',
ALL = 'all',
NONE = 'none',
ONE = 'one',
}
export enum Play {
@@ -37,22 +38,22 @@ export enum Play {
}
export enum CrossfadeStyle {
ConstantPower = 'constantPower',
ConstantPowerSlowCut = 'constantPowerSlowCut',
ConstantPowerSlowFade = 'constantPowerSlowFade',
Dipped = 'dipped',
EqualPower = 'equalPower',
Linear = 'linear',
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',
CROSSFADE = 'crossfade',
GAPLESS = 'gapless',
}
export enum PlaybackType {
Local = 'local',
Web = 'web',
LOCAL = 'local',
WEB = 'web',
}
export type APIEndpoints =
@@ -97,25 +98,26 @@ export type APIEndpoints =
| 'getSongsByGenre'
| 'getLyrics';
export interface GenericItem {
id: string;
title: string;
}
export interface APIResult {
data: Album[] | Artist[] | Genre[] | Song[];
totalRecordCount?: number;
}
interface RelatedItem {
deleted?: boolean;
id: string;
name: string;
remoteId?: string;
}
export interface Album {
albumArtist: Partial<AlbumArtist>;
albumArtistId: string;
albumArtist: AlbumArtist;
averageRating: number;
container: string;
createdAt: string;
date: string;
deleted: boolean;
genres: Genre[];
genres: RelatedItem[];
id: number;
imageUrl: string;
name: string;
@@ -154,27 +156,15 @@ export interface Artist {
updatedAt: string;
}
export interface ArtistInfo {
biography?: string;
externalUrl: GenericItem[];
imageUrl?: string;
similarArtist?: Artist[];
}
export interface Genre {
albumCount?: number;
id: string;
name: string;
songCount?: number;
type?: Item.GENRE;
uniqueId?: string;
}
export interface Song {
album: string;
albumId: number;
album: RelatedItem;
artistName: null;
artists: Partial<Artist>[];
artists: RelatedItem[];
bitRate: number;
container: string;
createdAt: string;
@@ -182,7 +172,7 @@ export interface Song {
deleted: boolean;
disc: number;
duration: number;
genres: Partial<Genre>[];
genres: RelatedItem[];
id: number;
imageUrl: string;
name: string;
@@ -196,23 +186,6 @@ export interface Song {
year: number;
}
export interface ScanStatus {
count: number | 'N/a';
scanning: boolean;
}
export interface Sort {
column?: string;
type: 'asc' | 'desc';
}
export interface Pagination {
activePage?: number;
pages?: number;
recordsPerPage: number;
serverSide?: boolean;
}
export interface ServerFolderAuth {
id: number;
locked: boolean;