Add most recent albums
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
import React from 'react';
|
||||
import { createStackNavigator } from '@react-navigation/stack';
|
||||
import { RootStackParamList } from './types';
|
||||
import Albums from './components/Albums';
|
||||
import Album from './components/Album';
|
||||
|
||||
const Stack = createStackNavigator<RootStackParamList>();
|
||||
|
||||
function AlbumStack() {
|
||||
return (
|
||||
<Stack.Navigator>
|
||||
<Stack.Screen name="Albums" component={Albums} />
|
||||
<Stack.Screen name="Album" component={Album} />
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
export default AlbumStack;
|
||||
20
src/screens/Music/index.tsx
Normal file
20
src/screens/Music/index.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { createStackNavigator } from '@react-navigation/stack';
|
||||
import { StackParams } from './types';
|
||||
import Albums from './stacks/Albums';
|
||||
import Album from './stacks/Album';
|
||||
import RecentAlbums from './stacks/RecentAlbums';
|
||||
|
||||
const Stack = createStackNavigator<StackParams>();
|
||||
|
||||
function MusicStack() {
|
||||
return (
|
||||
<Stack.Navigator initialRouteName="RecentAlbums">
|
||||
<Stack.Screen name="RecentAlbums" component={RecentAlbums} options={{ headerTitle: 'Recent Albums' }} />
|
||||
<Stack.Screen name="Albums" component={Albums} />
|
||||
<Stack.Screen name="Album" component={Album} />
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
export default MusicStack;
|
||||
@@ -1,43 +1,22 @@
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
import { useGetImage } from 'utility/JellyfinApi';
|
||||
import { Album, NavigationProp } from '../types';
|
||||
import { Text, SafeAreaView, FlatList, Dimensions } from 'react-native';
|
||||
import styled from 'styled-components/native';
|
||||
import { Text, SafeAreaView, FlatList } from 'react-native';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import FastImage from 'react-native-fast-image';
|
||||
import { differenceInDays } from 'date-fns';
|
||||
import { useTypedSelector } from 'store';
|
||||
import { fetchAllAlbums } from 'store/music/actions';
|
||||
import { ALBUM_CACHE_AMOUNT_OF_DAYS } from 'CONSTANTS';
|
||||
import TouchableHandler from 'components/TouchableHandler';
|
||||
|
||||
const Screen = Dimensions.get('screen');
|
||||
|
||||
const Container = styled.View`
|
||||
/* flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
flex: 1; */
|
||||
padding: 10px;
|
||||
background-color: #f6f6f6;
|
||||
`;
|
||||
|
||||
const AlbumItem = styled.View`
|
||||
width: ${Screen.width / 2 - 10}px;
|
||||
padding: 10px;
|
||||
`;
|
||||
|
||||
const AlbumImage = styled(FastImage)`
|
||||
border-radius: 10px;
|
||||
width: ${Screen.width / 2 - 40}px;
|
||||
height: ${Screen.width / 2 - 40}px;
|
||||
background-color: #fefefe;
|
||||
margin-bottom: 5px;
|
||||
`;
|
||||
import ListContainer from './components/ListContainer';
|
||||
import AlbumImage, { AlbumItem } from './components/AlbumImage';
|
||||
import { useAlbumsByArtist } from 'store/music/selectors';
|
||||
|
||||
const Albums: React.FC = () => {
|
||||
// Retrieve data from store
|
||||
const { ids, entities: albums } = useTypedSelector((state) => state.music.albums);
|
||||
const { entities: albums } = useTypedSelector((state) => state.music.albums);
|
||||
const ids = useAlbumsByArtist();
|
||||
const isLoading = useTypedSelector((state) => state.music.albums.isLoading);
|
||||
const lastRefreshed = useTypedSelector((state) => state.music.lastRefreshed);
|
||||
|
||||
@@ -60,7 +39,7 @@ const Albums: React.FC = () => {
|
||||
|
||||
return (
|
||||
<SafeAreaView>
|
||||
<Container>
|
||||
<ListContainer>
|
||||
<FlatList
|
||||
data={ids as string[]}
|
||||
refreshing={isLoading}
|
||||
@@ -77,7 +56,7 @@ const Albums: React.FC = () => {
|
||||
</TouchableHandler>
|
||||
)}
|
||||
/>
|
||||
</Container>
|
||||
</ListContainer>
|
||||
</SafeAreaView>
|
||||
);
|
||||
};
|
||||
73
src/screens/Music/stacks/RecentAlbums.tsx
Normal file
73
src/screens/Music/stacks/RecentAlbums.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
import { useGetImage } from 'utility/JellyfinApi';
|
||||
import { Album, NavigationProp } from '../types';
|
||||
import { Text, SafeAreaView, FlatList, View } from 'react-native';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { useTypedSelector } from 'store';
|
||||
import { fetchRecentAlbums } from 'store/music/actions';
|
||||
import TouchableHandler from 'components/TouchableHandler';
|
||||
import ListContainer from './components/ListContainer';
|
||||
import AlbumImage, { AlbumItem } from './components/AlbumImage';
|
||||
import { useRecentAlbums } from 'store/music/selectors';
|
||||
import { Header } from 'components/Typography';
|
||||
import ListButton from 'components/ListButton';
|
||||
|
||||
const NavigationHeader: React.FC = () => {
|
||||
const navigation = useNavigation();
|
||||
const handleAllAlbumsClick = useCallback(() => { navigation.navigate('Albums'); }, [navigation]);
|
||||
|
||||
return (
|
||||
<ListContainer>
|
||||
<ListButton onPress={handleAllAlbumsClick}>All Albums</ListButton>
|
||||
<Header>Recent Albums</Header>
|
||||
</ListContainer>
|
||||
);
|
||||
};
|
||||
|
||||
const RecentAlbums: React.FC = () => {
|
||||
// Retrieve data from store
|
||||
const { entities: albums } = useTypedSelector((state) => state.music.albums);
|
||||
const recentAlbums = useRecentAlbums(24);
|
||||
const isLoading = useTypedSelector((state) => state.music.albums.isLoading);
|
||||
|
||||
// Initialise helpers
|
||||
const dispatch = useDispatch();
|
||||
const navigation = useNavigation<NavigationProp>();
|
||||
const getImage = useGetImage();
|
||||
|
||||
// Set callbacks
|
||||
const retrieveData = useCallback(() => dispatch(fetchRecentAlbums()), [dispatch]);
|
||||
const selectAlbum = useCallback((id: string) => navigation.navigate('Album', { id, album: albums[id] as Album }), [navigation, albums]);
|
||||
|
||||
console.log(recentAlbums.map((d) => albums[d]?.DateCreated));
|
||||
|
||||
// Retrieve data on mount
|
||||
useEffect(() => { retrieveData(); }, []);
|
||||
|
||||
return (
|
||||
<SafeAreaView>
|
||||
<ListContainer>
|
||||
<FlatList
|
||||
data={recentAlbums as string[]}
|
||||
refreshing={isLoading}
|
||||
onRefresh={retrieveData}
|
||||
numColumns={2}
|
||||
keyExtractor={d => d}
|
||||
ListHeaderComponent={NavigationHeader}
|
||||
renderItem={({ item }) => (
|
||||
<TouchableHandler id={item} onPress={selectAlbum}>
|
||||
<AlbumItem>
|
||||
<AlbumImage source={{ uri: getImage(item) }} />
|
||||
<Text>{albums[item]?.Name}</Text>
|
||||
<Text style={{ opacity: 0.5 }}>{albums[item]?.AlbumArtist}</Text>
|
||||
</AlbumItem>
|
||||
</TouchableHandler>
|
||||
)}
|
||||
/>
|
||||
</ListContainer>
|
||||
</SafeAreaView>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecentAlbums;
|
||||
20
src/screens/Music/stacks/components/AlbumImage.ts
Normal file
20
src/screens/Music/stacks/components/AlbumImage.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import styled from 'styled-components/native';
|
||||
import FastImage from 'react-native-fast-image';
|
||||
import { Dimensions } from 'react-native';
|
||||
|
||||
const Screen = Dimensions.get('screen');
|
||||
|
||||
export const AlbumItem = styled.View`
|
||||
width: ${Screen.width / 2 - 10}px;
|
||||
padding: 10px;
|
||||
`;
|
||||
|
||||
const AlbumImage = styled(FastImage)`
|
||||
border-radius: 10px;
|
||||
width: ${Screen.width / 2 - 40}px;
|
||||
height: ${Screen.width / 2 - 40}px;
|
||||
background-color: #fefefe;
|
||||
margin-bottom: 5px;
|
||||
`;
|
||||
|
||||
export default AlbumImage;
|
||||
8
src/screens/Music/stacks/components/ListContainer.ts
Normal file
8
src/screens/Music/stacks/components/ListContainer.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import styled from 'styled-components/native';
|
||||
|
||||
const ListContainer = styled.View`
|
||||
padding: 10px;
|
||||
background-color: #f6f6f6;
|
||||
`;
|
||||
|
||||
export default ListContainer;
|
||||
@@ -40,6 +40,7 @@ export interface Album {
|
||||
ImageTags: ImageTags;
|
||||
BackdropImageTags: any[];
|
||||
LocationType: string;
|
||||
DateCreated: string;
|
||||
}
|
||||
|
||||
export interface AlbumTrack {
|
||||
@@ -68,6 +69,7 @@ export interface AlbumTrack {
|
||||
export type StackParams = {
|
||||
Albums: undefined;
|
||||
Album: { id: string, album: Album };
|
||||
RecentAlbums: undefined;
|
||||
};
|
||||
|
||||
export type NavigationProp = StackNavigationProp<StackParams>;
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { createBottomTabNavigator, BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
|
||||
import Player from './Player';
|
||||
import Albums from './Albums';
|
||||
import Music from './Music';
|
||||
import Settings from './Settings';
|
||||
import { createStackNavigator, StackNavigationProp } from '@react-navigation/stack';
|
||||
import SetJellyfinServer from './modals/SetJellyfinServer';
|
||||
@@ -12,15 +12,15 @@ const Tab = createBottomTabNavigator();
|
||||
|
||||
type Screens = {
|
||||
NowPlaying: undefined;
|
||||
Albums: undefined;
|
||||
Music: undefined;
|
||||
Settings: undefined;
|
||||
}
|
||||
|
||||
function Screens() {
|
||||
return (
|
||||
<Tab.Navigator>
|
||||
<Tab.Screen name="NowPlaying" component={Player} />
|
||||
<Tab.Screen name="Albums" component={Albums} />
|
||||
<Tab.Screen name="NowPlaying" component={Player} options={{ tabBarLabel: 'Now Playing' }} />
|
||||
<Tab.Screen name="Music" component={Music} />
|
||||
<Tab.Screen name="Settings" component={Settings} />
|
||||
</Tab.Navigator>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user