so I do need it this way

This commit is contained in:
Violet Caulfield
2024-10-15 16:54:08 -05:00
parent 7e68daad41
commit be045fafde
4 changed files with 59 additions and 51 deletions
@@ -2,6 +2,14 @@ import React, { useState } from "react";
import _ from "lodash";
import { serverUrlMutation } from "../../../api/mutators/storage";
import { Button, SafeAreaView, TextInput, useColorScheme, View } from "react-native";
import { Jellyfin } from "@jellyfin/sdk";
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useMutation } from "@tanstack/react-query";
import { client } from "../../../api/queries";
import { AsyncStorageKeys } from "../../../enums/async-storage-keys";
import { JellifyServer } from "../../../types/JellifyServer";
import { serverMutation } from "../../../api/mutators/functions/storage";
export default function ServerAddress(): React.JSX.Element {
@@ -9,6 +17,32 @@ export default function ServerAddress(): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
const useServerMutation = useMutation({
mutationFn: serverMutation,
onSuccess: (publicSystemInfoResponse, serverUrl, context) => {
if (!!!publicSystemInfoResponse.data.Version)
throw new Error("Jellyfin instance did not respond");
console.debug("REMOVE THIS::onSuccess variable", serverUrl);
console.log(`Connected to Jellyfin ${publicSystemInfoResponse.data.Version!}`);
// TODO: Store these along side address
// TODO: Rename url to address
let jellifyServer: JellifyServer = {
url: serverUrl,
name: publicSystemInfoResponse.data.ServerName!,
version: publicSystemInfoResponse.data.Version!,
startUpComplete: publicSystemInfoResponse.data.StartupWizardCompleted!
}
return AsyncStorage.setItem(AsyncStorageKeys.ServerUrl, JSON.stringify(jellifyServer));
},
onError: async (error: Error) => {
console.error("An error occurred connecting to the Jellyfin instance", error);
return await AsyncStorage.setItem(AsyncStorageKeys.ServerUrl, "");
}
});
return (
<View>
<TextInput
@@ -1,6 +1,9 @@
import React from "react";
import { Button, TextInput, useColorScheme, View } from "react-native";
import { clearServer } from "../../../api/mutators/storage";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useMutation } from "@tanstack/react-query";
import { AsyncStorageKeys } from "../../../enums/async-storage-keys";
export default function ServerAuthentication(): React.JSX.Element {
@@ -9,6 +12,12 @@ export default function ServerAuthentication(): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
const clearServer = useMutation({
mutationFn: async () => {
return await AsyncStorage.setItem(AsyncStorageKeys.ServerUrl, "");
}
})
return (
<View>
<Button