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