From 0e574ea18d1049ad290599479adff28fd093d8d8 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Fri, 3 Jan 2025 21:43:07 +0100 Subject: [PATCH] fix: alert prompt not working on android --- components/settings/QuickConnect.tsx | 128 +++++++++++++++++++-------- 1 file changed, 91 insertions(+), 37 deletions(-) diff --git a/components/settings/QuickConnect.tsx b/components/settings/QuickConnect.tsx index 226120bb..9efbec43 100644 --- a/components/settings/QuickConnect.tsx +++ b/components/settings/QuickConnect.tsx @@ -1,59 +1,113 @@ -import { Alert, View, ViewProps } from "react-native"; -import { Text } from "../common/Text"; -import { ListItem } from "../list/ListItem"; -import { Button } from "../Button"; -import { apiAtom, useJellyfin, userAtom } from "@/providers/JellyfinProvider"; -import { useAtom } from "jotai"; -import Constants from "expo-constants"; -import Application from "expo-application"; -import { ListGroup } from "../list/ListGroup"; +import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; +import { + BottomSheetBackdrop, + BottomSheetBackdropProps, + BottomSheetModal, + BottomSheetTextInput, + BottomSheetView, +} from "@gorhom/bottom-sheet"; import { getQuickConnectApi } from "@jellyfin/sdk/lib/utils/api"; import * as Haptics from "expo-haptics"; +import { useAtom } from "jotai"; +import React, { useCallback, useRef, useState } from "react"; +import { Alert, View, ViewProps } from "react-native"; +import { Button } from "../Button"; +import { Text } from "../common/Text"; +import { ListGroup } from "../list/ListGroup"; +import { ListItem } from "../list/ListItem"; interface Props extends ViewProps {} export const QuickConnect: React.FC = ({ ...props }) => { const [api] = useAtom(apiAtom); const [user] = useAtom(userAtom); + const [quickConnectCode, setQuickConnectCode] = useState(); + const bottomSheetModalRef = useRef(null); - const openQuickConnectAuthCodeInput = () => { - Alert.prompt( - "Quick connect", - "Enter the quick connect code", - async (text) => { - if (text) { - try { - const res = await getQuickConnectApi(api!).authorizeQuickConnect({ - code: text, - userId: user?.Id, - }); - if (res.status === 200) { - Haptics.notificationAsync( - Haptics.NotificationFeedbackType.Success - ); - Alert.alert("Success", "Quick connect authorized"); - } else { - Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); - Alert.alert("Error", "Invalid code"); - } - } catch (e) { - Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); - Alert.alert("Error", "Invalid code"); - } + const renderBackdrop = useCallback( + (props: BottomSheetBackdropProps) => ( + + ), + [] + ); + + const authorizeQuickConnect = useCallback(async () => { + if (quickConnectCode) { + try { + const res = await getQuickConnectApi(api!).authorizeQuickConnect({ + code: quickConnectCode, + userId: user?.Id, + }); + if (res.status === 200) { + Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); + Alert.alert("Success", "Quick connect authorized"); + setQuickConnectCode(undefined); + bottomSheetModalRef?.current?.close(); + } else { + Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); + Alert.alert("Error", "Invalid code"); } + } catch (e) { + Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); + Alert.alert("Error", "Invalid code"); } - ); - }; + } + }, [api, user, quickConnectCode]); return ( bottomSheetModalRef?.current?.present()} title="Authorize Quick Connect" textColor="blue" - > + /> + + + + + + + Quick Connect + + + + + + + + + + + ); };