mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-29 09:29:29 +01:00
pick from dict better than find from array
This commit is contained in:
parent
c068eac3e5
commit
15b3100107
@ -1,13 +1,14 @@
|
|||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { useAtomValue } from 'jotai/utils';
|
import { useAtomValue } from 'jotai/utils';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { GestureResponderEvent, Image, Pressable, Text, useWindowDimensions, View } from 'react-native';
|
import { ActivityIndicator, GestureResponderEvent, Image, Pressable, Text, useWindowDimensions, View } from 'react-native';
|
||||||
import { useCurrentTrackId, useSetQueue } from '../../hooks/player';
|
import { useCurrentTrackId, useSetQueue } from '../../hooks/player';
|
||||||
import { albumAtomFamily } from '../../state/music';
|
import { albumAtomFamily } from '../../state/music';
|
||||||
import colors from '../../styles/colors';
|
import colors from '../../styles/colors';
|
||||||
import text from '../../styles/text';
|
import text from '../../styles/text';
|
||||||
import AlbumArt from './AlbumArt';
|
import AlbumArt from './AlbumArt';
|
||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
|
import GradientBackground from './GradientBackground';
|
||||||
import GradientScrollView from './GradientScrollView';
|
import GradientScrollView from './GradientScrollView';
|
||||||
|
|
||||||
const SongItem: React.FC<{
|
const SongItem: React.FC<{
|
||||||
@ -153,6 +154,21 @@ const AlbumDetails: React.FC<{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AlbumViewFallback = () => {
|
||||||
|
const layout = useWindowDimensions();
|
||||||
|
|
||||||
|
const coverSize = layout.width - layout.width / 2.5;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GradientBackground style={{
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingTop: coverSize / 8 + coverSize / 2 - 18,
|
||||||
|
}}>
|
||||||
|
<ActivityIndicator size='large' color={colors.accent} />
|
||||||
|
</GradientBackground>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const AlbumView: React.FC<{
|
const AlbumView: React.FC<{
|
||||||
id: string,
|
id: string,
|
||||||
title: string;
|
title: string;
|
||||||
@ -164,8 +180,9 @@ const AlbumView: React.FC<{
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Suspense fallback={<Text>Loading...</Text>}>
|
<React.Suspense fallback={<AlbumViewFallback />}>
|
||||||
<AlbumDetails id={id} />
|
<AlbumDetails id={id} />
|
||||||
|
{/* <AlbumViewFallback /> */}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions, ViewStyle } from 'react-native';
|
||||||
import LinearGradient from 'react-native-linear-gradient';
|
import LinearGradient from 'react-native-linear-gradient';
|
||||||
import colors from '../../styles/colors';
|
import colors from '../../styles/colors';
|
||||||
|
|
||||||
@ -7,7 +7,8 @@ const GradientBackground: React.FC<{
|
|||||||
height?: number | string;
|
height?: number | string;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
position?: 'relative' | 'absolute';
|
position?: 'relative' | 'absolute';
|
||||||
}> = ({ height, width, position }) => {
|
style?: ViewStyle;
|
||||||
|
}> = ({ height, width, position, style, children }) => {
|
||||||
const layout = useWindowDimensions();
|
const layout = useWindowDimensions();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -15,11 +16,14 @@ const GradientBackground: React.FC<{
|
|||||||
colors={[colors.gradient.high, colors.gradient.low]}
|
colors={[colors.gradient.high, colors.gradient.low]}
|
||||||
locations={[0.01,0.7]}
|
locations={[0.01,0.7]}
|
||||||
style={{
|
style={{
|
||||||
|
...style,
|
||||||
width: width || '100%',
|
width: width || '100%',
|
||||||
height: height || layout.height,
|
height: height || layout.height,
|
||||||
position: position || 'absolute',
|
position: position || 'absolute',
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
|
{children}
|
||||||
|
</LinearGradient>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -61,8 +61,10 @@ const AlbumsList = () => {
|
|||||||
const updating = useAtomValue(albumsUpdatingAtom);
|
const updating = useAtomValue(albumsUpdatingAtom);
|
||||||
const updateAlbums = useUpdateAlbums();
|
const updateAlbums = useUpdateAlbums();
|
||||||
|
|
||||||
|
const albumsList = Object.values(albums);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (albums.length === 0) {
|
if (albumsList.length === 0) {
|
||||||
updateAlbums();
|
updateAlbums();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -70,7 +72,7 @@ const AlbumsList = () => {
|
|||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<GradientFlatList
|
<GradientFlatList
|
||||||
data={albums}
|
data={albumsList}
|
||||||
renderItem={AlbumListRenderItem}
|
renderItem={AlbumListRenderItem}
|
||||||
keyExtractor={item => item.id}
|
keyExtractor={item => item.id}
|
||||||
numColumns={3}
|
numColumns={3}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { atom, useAtom } from 'jotai';
|
|||||||
import { atomFamily, useAtomValue, useUpdateAtom } from 'jotai/utils';
|
import { atomFamily, useAtomValue, useUpdateAtom } from 'jotai/utils';
|
||||||
import { Album, AlbumArt, AlbumWithSongs, Artist, ArtistArt, ArtistInfo, Song } from '../models/music';
|
import { Album, AlbumArt, AlbumWithSongs, Artist, ArtistArt, ArtistInfo, Song } from '../models/music';
|
||||||
import { SubsonicApiClient } from '../subsonic/api';
|
import { SubsonicApiClient } from '../subsonic/api';
|
||||||
import { AlbumID3Element, ArtistID3Element, ArtistInfo2Element, ChildElement } from '../subsonic/elements';
|
import { AlbumID3Element, ArtistInfo2Element, ChildElement } from '../subsonic/elements';
|
||||||
import { GetArtistResponse } from '../subsonic/responses';
|
import { GetArtistResponse } from '../subsonic/responses';
|
||||||
import { activeServerAtom } from './settings';
|
import { activeServerAtom } from './settings';
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export const useUpdateArtists = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const albumsAtom = atom<Album[]>([]);
|
export const albumsAtom = atom<Record<string, Album>>({});
|
||||||
export const albumsUpdatingAtom = atom(false);
|
export const albumsUpdatingAtom = atom(false);
|
||||||
|
|
||||||
export const useUpdateAlbums = () => {
|
export const useUpdateAlbums = () => {
|
||||||
@ -57,7 +57,11 @@ export const useUpdateAlbums = () => {
|
|||||||
const client = new SubsonicApiClient(server);
|
const client = new SubsonicApiClient(server);
|
||||||
const response = await client.getAlbumList2({ type: 'alphabeticalByArtist', size: 500 });
|
const response = await client.getAlbumList2({ type: 'alphabeticalByArtist', size: 500 });
|
||||||
|
|
||||||
setAlbums(response.data.albums.map(a => mapAlbumID3(a, client)));
|
setAlbums(response.data.albums.reduce((acc, next) => {
|
||||||
|
const album = mapAlbumID3(next, client);
|
||||||
|
acc[album.id] = album;
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, Album>));
|
||||||
setUpdating(false);
|
setUpdating(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +84,7 @@ export const albumArtAtomFamily = atomFamily((id: string) => atom<AlbumArt | und
|
|||||||
}
|
}
|
||||||
|
|
||||||
const albums = get(albumsAtom);
|
const albums = get(albumsAtom);
|
||||||
const album = albums.find(a => a.id === id);
|
const album = id in albums ? albums[id] : undefined;
|
||||||
if (!album) {
|
if (!album) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ const paragraph: TextStyle = {
|
|||||||
|
|
||||||
const header: TextStyle = {
|
const header: TextStyle = {
|
||||||
...paragraph,
|
...paragraph,
|
||||||
fontSize: 19,
|
fontSize: 18,
|
||||||
fontFamily: fontSemiBold,
|
fontFamily: fontSemiBold,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user