feat: quick connect

fixes #16
This commit is contained in:
Fredrik Burmester
2024-08-26 21:52:23 +02:00
parent 3047367ba6
commit e6d4414fd6
3 changed files with 137 additions and 12 deletions

View File

@@ -3,10 +3,9 @@ import { Input } from "@/components/common/Input";
import { Text } from "@/components/common/Text";
import { apiAtom, useJellyfin } from "@/providers/JellyfinProvider";
import { Ionicons } from "@expo/vector-icons";
import { AxiosError } from "axios";
import { useLocalSearchParams } from "expo-router";
import { useAtom } from "jotai";
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import {
Alert,
KeyboardAvoidingView,
@@ -22,7 +21,8 @@ const CredentialsSchema = z.object({
});
const Login: React.FC = () => {
const { setServer, login, removeServer } = useJellyfin();
const { setServer, login, removeServer, initiateQuickConnect } =
useJellyfin();
const [api] = useAtom(apiAtom);
const params = useLocalSearchParams();
@@ -87,6 +87,21 @@ const Login: React.FC = () => {
setServer({ address: url.trim() });
};
const handleQuickConnect = async () => {
try {
const code = await initiateQuickConnect();
if (code) {
Alert.alert("Quick Connect", `Enter code ${code} to login`, [
{
text: "Got It",
},
]);
}
} catch (error) {
Alert.alert("Error", "Failed to initiate Quick Connect");
}
};
if (api?.basePath) {
return (
<SafeAreaView style={{ flex: 1 }}>
@@ -162,13 +177,18 @@ const Login: React.FC = () => {
<Text className="text-red-600 mb-2">{error}</Text>
</View>
<Button
onPress={handleLogin}
loading={loading}
className="mt-auto mb-2"
>
Log in
</Button>
<View className="mt-auto mb-2">
<Button
color="black"
onPress={handleQuickConnect}
className="mb-2"
>
Use Quick Connect
</Button>
<Button onPress={handleLogin} loading={loading}>
Log in
</Button>
</View>
</View>
</KeyboardAvoidingView>
</SafeAreaView>