mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-19 12:14:47 +02:00
fix back routing error
This commit is contained in:
@@ -407,7 +407,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 },
|
params: { key: album.identity_key, from: 'home' },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { View, Pressable, StyleSheet } from 'react-native';
|
import { BackHandler, View, Pressable, StyleSheet } from 'react-native';
|
||||||
import { Image } from 'expo-image';
|
import { Image } from 'expo-image';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
import { FlashList } from '@shopify/flash-list';
|
import { FlashList } from '@shopify/flash-list';
|
||||||
import { useLocalSearchParams, useRouter } from 'expo-router';
|
import { useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router';
|
||||||
import { Screen } from '@/components/Screen';
|
import { Screen } from '@/components/Screen';
|
||||||
import { Text } from '@/components/Text';
|
import { Text } from '@/components/Text';
|
||||||
import { AstraLogo } from '@/components/AstraLogo';
|
import { AstraLogo } from '@/components/AstraLogo';
|
||||||
@@ -20,10 +20,11 @@ import type { DbTrack } from '@/types/library';
|
|||||||
|
|
||||||
export default function AlbumScreen() {
|
export default function AlbumScreen() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { key } = useLocalSearchParams<{ key: string }>();
|
const { key, from } = useLocalSearchParams<{ key: string; from?: 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 openedFromHome = from === 'home';
|
||||||
|
|
||||||
const album = albums.find((entry) => entry.identity_key === key);
|
const album = albums.find((entry) => entry.identity_key === key);
|
||||||
// Store tracks are ordered artist/album/disc/track, so the filtered slice
|
// Store tracks are ordered artist/album/disc/track, so the filtered slice
|
||||||
@@ -40,9 +41,30 @@ export default function AlbumScreen() {
|
|||||||
void playTracks(tracks.map(dbTrackToTrack), index);
|
void playTracks(tracks.map(dbTrackToTrack), index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBack = useCallback(() => {
|
||||||
|
if (openedFromHome) {
|
||||||
|
router.replace('/library');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
router.back();
|
||||||
|
}, [openedFromHome, router]);
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (!openedFromHome) return;
|
||||||
|
|
||||||
|
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
||||||
|
handleBack();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => subscription.remove();
|
||||||
|
}, [handleBack, openedFromHome])
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen>
|
<Screen>
|
||||||
<Pressable style={styles.back} onPress={() => router.back()} hitSlop={8}>
|
<Pressable style={styles.back} onPress={handleBack} hitSlop={8}>
|
||||||
<Ionicons name="chevron-back" size={22} color={colors.textSecondary} />
|
<Ionicons name="chevron-back" size={22} color={colors.textSecondary} />
|
||||||
<Text variant="body" color={colors.textSecondary}>
|
<Text variant="body" color={colors.textSecondary}>
|
||||||
Library
|
Library
|
||||||
|
|||||||
Reference in New Issue
Block a user