From f46cb97e7ffcbb31ac25bdcdd8b8a36bc3d8eb86 Mon Sep 17 00:00:00 2001 From: Simon Eklundh Date: Sat, 28 Sep 2024 10:42:02 +0200 Subject: [PATCH 1/2] working prototype --- app/(auth)/(tabs)/(home)/_layout.tsx | 12 ------ app/(auth)/(tabs)/(home)/index.tsx | 58 +++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/_layout.tsx b/app/(auth)/(tabs)/(home)/_layout.tsx index 298edae5..a53cfcd3 100644 --- a/app/(auth)/(tabs)/(home)/_layout.tsx +++ b/app/(auth)/(tabs)/(home)/_layout.tsx @@ -18,18 +18,6 @@ export default function IndexLayout() { headerBlurEffect: "prominent", headerTransparent: Platform.OS === "ios" ? true : false, headerShadowVisible: false, - headerLeft: () => ( - { - router.push("/(auth)/downloads"); - }} - > - - - ), headerRight: () => ( diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index c665059d..592fd541 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -6,7 +6,7 @@ import { Loader } from "@/components/Loader"; import { MediaListSection } from "@/components/medialists/MediaListSection"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { useSettings } from "@/utils/atoms/settings"; -import { Ionicons } from "@expo/vector-icons"; +import { Feather, Ionicons } from "@expo/vector-icons"; import { Api } from "@jellyfin/sdk"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { @@ -16,16 +16,19 @@ import { getUserLibraryApi, getUserViewsApi, } from "@jellyfin/sdk/lib/utils/api"; +import AsyncStorage from "@react-native-async-storage/async-storage"; import NetInfo from "@react-native-community/netinfo"; import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { useRouter } from "expo-router"; +import { useNavigation, useRouter } from "expo-router"; import { useAtom } from "jotai"; import { useCallback, useEffect, useMemo, useState } from "react"; import { ActivityIndicator, + Platform, RefreshControl, SafeAreaView, ScrollView, + TouchableOpacity, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; @@ -60,6 +63,7 @@ export default function index() { const [isConnected, setIsConnected] = useState(null); const [loadingRetry, setLoadingRetry] = useState(false); + const navigation = useNavigation(); const checkConnection = useCallback(async () => { setLoadingRetry(true); @@ -68,6 +72,56 @@ export default function index() { setLoadingRetry(false); }, []); + useEffect(() => { + try { + // we check for downloaded files and turn the downloads button green if there are downloads + AsyncStorage.getItem("downloaded_files").then((value) => { + let downloadButtonColor = "white"; + if (value) { + const files = JSON.parse(value) as BaseItemDto[]; + if (files.length > 0) { + downloadButtonColor = "green"; + } else { + downloadButtonColor = "white"; + } + } else { + downloadButtonColor = "white"; + } + console.log("color: ", downloadButtonColor); + navigation.setOptions({ + headerLeft: () => ( + { + router.push("/(auth)/downloads"); + }} + > + + + ), + }); + }); + } catch (error) { + console.log(error); + navigation.setOptions({ + headerLeft: () => ( + { + router.push("/(auth)/downloads"); + }} + > + + + ), + }); + } + }, [navigation.getState()]); + useEffect(() => { const unsubscribe = NetInfo.addEventListener((state) => { if (state.isConnected == false || state.isInternetReachable === false) From 0e8f6dc0cccde93f4e96129b36eadbce1b1eac9d Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Thu, 3 Oct 2024 20:02:14 +0200 Subject: [PATCH 2/2] fix: use hook and purple color --- app/(auth)/(tabs)/(home)/index.tsx | 68 +++++++++--------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index d4a56945..62d89b07 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -5,6 +5,7 @@ import { ScrollingCollectionList } from "@/components/home/ScrollingCollectionLi import { Loader } from "@/components/Loader"; import { MediaListSection } from "@/components/medialists/MediaListSection"; import { TAB_HEIGHT } from "@/constants/Values"; +import { useDownload } from "@/providers/DownloadProvider"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { useSettings } from "@/utils/atoms/settings"; import { Feather, Ionicons } from "@expo/vector-icons"; @@ -72,55 +73,26 @@ export default function index() { setLoadingRetry(false); }, []); + const { downloadedFiles } = useDownload(); + useEffect(() => { - try { - // we check for downloaded files and turn the downloads button green if there are downloads - AsyncStorage.getItem("downloaded_files").then((value) => { - let downloadButtonColor = "white"; - if (value) { - const files = JSON.parse(value) as BaseItemDto[]; - if (files.length > 0) { - downloadButtonColor = "green"; - } else { - downloadButtonColor = "white"; - } - } else { - downloadButtonColor = "white"; - } - console.log("color: ", downloadButtonColor); - navigation.setOptions({ - headerLeft: () => ( - { - router.push("/(auth)/downloads"); - }} - > - - - ), - }); - }); - } catch (error) { - console.log(error); - navigation.setOptions({ - headerLeft: () => ( - { - router.push("/(auth)/downloads"); - }} - > - - - ), - }); - } - }, [navigation.getState()]); + const color = + downloadedFiles && downloadedFiles?.length > 0 ? "#9334E9" : "white"; + navigation.setOptions({ + headerLeft: () => ( + { + router.push("/(auth)/downloads"); + }} + > + + + ), + }); + }, [downloadedFiles, navigation]); useEffect(() => { const unsubscribe = NetInfo.addEventListener((state) => {