mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 04:30:54 +02:00
fix softlocking library
This commit is contained in:
@@ -434,7 +434,7 @@ export default function HomeScreen() {
|
|||||||
const openAlbum = (album: Album) => {
|
const openAlbum = (album: Album) => {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/library/album/[key]',
|
pathname: '/library/album/[key]',
|
||||||
params: { key: album.identity_key, from: 'home' },
|
params: { key: album.identity_key },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ function DiscHeader({ disc }: { disc: number }) {
|
|||||||
|
|
||||||
export default function AlbumScreen() {
|
export default function AlbumScreen() {
|
||||||
const colors = useColors();
|
const colors = useColors();
|
||||||
const { key, from } = useLocalSearchParams<{ key: string; from?: string }>();
|
const { key } = useLocalSearchParams<{ key: string }>();
|
||||||
const albums = useLibraryStore((s) => s.albums);
|
const albums = useLibraryStore((s) => s.albums);
|
||||||
const allTracks = useLibraryStore((s) => s.tracks);
|
const allTracks = useLibraryStore((s) => s.tracks);
|
||||||
const currentPath = usePlayerStore((s) => s.currentTrack?.path);
|
const currentPath = usePlayerStore((s) => s.currentTrack?.path);
|
||||||
const handleBack = useLibraryDetailBack(from);
|
const handleBack = useLibraryDetailBack();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const { scrollY, heroFaded, collapsed, onScroll, scrollEventThrottle, expandedHeight, onHeroBlockLayout } =
|
const { scrollY, heroFaded, collapsed, onScroll, scrollEventThrottle, expandedHeight, onHeroBlockLayout } =
|
||||||
useDetailCollapse();
|
useDetailCollapse();
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ export default function ArtistScreen() {
|
|||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const colors = useColors();
|
const colors = useColors();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { name = 'Artist', from } = useLocalSearchParams<{ name: string; from?: string }>();
|
const { name = 'Artist' } = useLocalSearchParams<{ name: string }>();
|
||||||
const handleBack = useLibraryDetailBack(from);
|
const handleBack = useLibraryDetailBack();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const { scrollY, heroFaded, collapsed, onScroll, scrollEventThrottle, expandedHeight, onHeroBlockLayout } =
|
const { scrollY, heroFaded, collapsed, onScroll, scrollEventThrottle, expandedHeight, onHeroBlockLayout } =
|
||||||
useDetailCollapse();
|
useDetailCollapse();
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ export default function PlaylistScreen() {
|
|||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const colors = useColors();
|
const colors = useColors();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { id, from } = useLocalSearchParams<{ id: string; from?: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const handleBack = useLibraryDetailBack(from);
|
const handleBack = useLibraryDetailBack();
|
||||||
const isFavorites = id === 'favorites';
|
const isFavorites = id === 'favorites';
|
||||||
const playlistId = isFavorites ? null : Number(id);
|
const playlistId = isFavorites ? null : Number(id);
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ export default function PlaylistScreen() {
|
|||||||
void (async () => {
|
void (async () => {
|
||||||
try {
|
try {
|
||||||
await deletePlaylist(target.id);
|
await deletePlaylist(target.id);
|
||||||
router.back();
|
handleBack();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Alert.alert('Delete failed', errorMessage(err));
|
Alert.alert('Delete failed', errorMessage(err));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -901,7 +901,7 @@ function QuickSearchPanel({
|
|||||||
if (result.kind === 'album') {
|
if (result.kind === 'album') {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/library/album/[key]',
|
pathname: '/library/album/[key]',
|
||||||
params: { key: result.album.identity_key, from: 'search' },
|
params: { key: result.album.identity_key },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -909,7 +909,7 @@ function QuickSearchPanel({
|
|||||||
if (result.kind === 'artist') {
|
if (result.kind === 'artist') {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/library/artist/[name]',
|
pathname: '/library/artist/[name]',
|
||||||
params: { name: result.artist.artist, from: 'search' },
|
params: { name: result.artist.artist },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -917,7 +917,7 @@ function QuickSearchPanel({
|
|||||||
if (result.kind === 'playlist') {
|
if (result.kind === 'playlist') {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/library/playlist/[id]',
|
pathname: '/library/playlist/[id]',
|
||||||
params: { id: result.playlist.id, from: 'search' },
|
params: { id: result.playlist.id },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,22 @@ import { useCallback } from 'react';
|
|||||||
import { BackHandler } from 'react-native';
|
import { BackHandler } from 'react-native';
|
||||||
import { useFocusEffect, useRouter } from 'expo-router';
|
import { useFocusEffect, useRouter } from 'expo-router';
|
||||||
|
|
||||||
type LibraryDetailSource = 'home' | 'search';
|
export function useLibraryDetailBack() {
|
||||||
|
|
||||||
function shouldReturnToLibraryRoot(from: string | string[] | undefined): from is LibraryDetailSource {
|
|
||||||
return from === 'home' || from === 'search';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useLibraryDetailBack(from?: string | string[]) {
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const returnToLibraryRoot = shouldReturnToLibraryRoot(from);
|
|
||||||
|
|
||||||
const handleBack = useCallback(() => {
|
const handleBack = useCallback(() => {
|
||||||
if (returnToLibraryRoot) {
|
router.dismissTo('/library');
|
||||||
router.replace('/library');
|
}, [router]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
router.back();
|
|
||||||
}, [returnToLibraryRoot, router]);
|
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
if (!returnToLibraryRoot) return;
|
|
||||||
|
|
||||||
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
||||||
handleBack();
|
handleBack();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => subscription.remove();
|
return () => subscription.remove();
|
||||||
}, [handleBack, returnToLibraryRoot])
|
}, [handleBack])
|
||||||
);
|
);
|
||||||
|
|
||||||
return handleBack;
|
return handleBack;
|
||||||
|
|||||||
Reference in New Issue
Block a user