fix softlocking library

This commit is contained in:
Boof2015
2026-07-07 12:47:52 -04:00
parent 31f81282e0
commit 5f02e3e222
6 changed files with 15 additions and 28 deletions
+1 -1
View File
@@ -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 },
});
};
+2 -2
View File
@@ -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();
+2 -2
View File
@@ -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();
+3 -3
View File
@@ -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));
}
+3 -3
View File
@@ -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;
}
+4 -17
View File
@@ -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;