fix: use hook and purple color

This commit is contained in:
Fredrik Burmester
2024-10-03 20:02:14 +02:00
parent bc3bdbf4c5
commit 0e8f6dc0cc

View File

@@ -5,6 +5,7 @@ import { ScrollingCollectionList } from "@/components/home/ScrollingCollectionLi
import { Loader } from "@/components/Loader"; import { Loader } from "@/components/Loader";
import { MediaListSection } from "@/components/medialists/MediaListSection"; import { MediaListSection } from "@/components/medialists/MediaListSection";
import { TAB_HEIGHT } from "@/constants/Values"; import { TAB_HEIGHT } from "@/constants/Values";
import { useDownload } from "@/providers/DownloadProvider";
import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
import { useSettings } from "@/utils/atoms/settings"; import { useSettings } from "@/utils/atoms/settings";
import { Feather, Ionicons } from "@expo/vector-icons"; import { Feather, Ionicons } from "@expo/vector-icons";
@@ -72,55 +73,26 @@ export default function index() {
setLoadingRetry(false); setLoadingRetry(false);
}, []); }, []);
const { downloadedFiles } = useDownload();
useEffect(() => { useEffect(() => {
try { const color =
// we check for downloaded files and turn the downloads button green if there are downloads downloadedFiles && downloadedFiles?.length > 0 ? "#9334E9" : "white";
AsyncStorage.getItem("downloaded_files").then((value) => { navigation.setOptions({
let downloadButtonColor = "white"; headerLeft: () => (
if (value) { <TouchableOpacity
const files = JSON.parse(value) as BaseItemDto[]; style={{
if (files.length > 0) { marginRight: Platform.OS === "android" ? 17 : 0,
downloadButtonColor = "green"; }}
} else { onPress={() => {
downloadButtonColor = "white"; router.push("/(auth)/downloads");
} }}
} else { >
downloadButtonColor = "white"; <Feather name="download" color={color} size={22} />
} </TouchableOpacity>
console.log("color: ", downloadButtonColor); ),
navigation.setOptions({ });
headerLeft: () => ( }, [downloadedFiles, navigation]);
<TouchableOpacity
style={{
marginRight: Platform.OS === "android" ? 17 : 0,
}}
onPress={() => {
router.push("/(auth)/downloads");
}}
>
<Feather name="download" color={downloadButtonColor} size={22} />
</TouchableOpacity>
),
});
});
} catch (error) {
console.log(error);
navigation.setOptions({
headerLeft: () => (
<TouchableOpacity
style={{
marginRight: Platform.OS === "android" ? 17 : 0,
}}
onPress={() => {
router.push("/(auth)/downloads");
}}
>
<Feather name="download" color={"white"} size={22} />
</TouchableOpacity>
),
});
}
}, [navigation.getState()]);
useEffect(() => { useEffect(() => {
const unsubscribe = NetInfo.addEventListener((state) => { const unsubscribe = NetInfo.addEventListener((state) => {