mirror of
https://github.com/Jellify-Music/App.git
synced 2026-05-05 02:09:32 -05:00
testing if we can change the server after it's been selected during the login flow
This commit is contained in:
+18
-8
@@ -8,32 +8,42 @@ import { client } from "../queries";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api"
|
||||
import { JellyfinCredentials } from "../types/jellyfin-credentials";
|
||||
import { mutateServerCredentials } from "./functions/storage";
|
||||
import { JellifyServer } from "../../types/JellifyServer";
|
||||
|
||||
export const serverUrlMutation = useMutation({
|
||||
mutationFn: async (serverUrl: string | undefined) => {
|
||||
mutationFn: async (serverUrl: string) => {
|
||||
|
||||
console.log("Mutating server URL");
|
||||
|
||||
if (!!!serverUrl)
|
||||
throw Error("Server URL was empty")
|
||||
throw Error("Server URL is empty")
|
||||
|
||||
let jellyfin = new Jellyfin(client);
|
||||
let api = jellyfin.createApi(serverUrl);
|
||||
|
||||
console.log(`Created API client for ${api.basePath}`)
|
||||
return await getSystemApi(api).getPublicSystemInfo()
|
||||
},
|
||||
onSuccess: (publicSystemInfoResponse, serverUrl, context) => {
|
||||
if (!!!publicSystemInfoResponse.data.Version)
|
||||
throw new Error("Unable to connect to Jellyfin Server");
|
||||
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
|
||||
publicSystemInfoResponse.data.ServerName;
|
||||
publicSystemInfoResponse.data.StartupWizardCompleted;
|
||||
publicSystemInfoResponse.data.Version;
|
||||
|
||||
return AsyncStorage.setItem(AsyncStorageKeys.ServerUrl, serverUrl!);
|
||||
|
||||
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: (error: Error) => {
|
||||
console.error("An error occurred connecting to the Jellyfin instance", error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { client } from "../../../api/queries";
|
||||
import { AsyncStorageKeys } from "../../../enums/async-storage-keys";
|
||||
import { Button, TextField, View } from "react-native-ui-lib";
|
||||
import { JellifyServer } from "../../../types/JellifyServer";
|
||||
import { serverUrlMutation } from "../../../api/mutators/storage";
|
||||
|
||||
export default function ServerAddress(): React.JSX.Element {
|
||||
|
||||
@@ -15,43 +16,6 @@ export default function ServerAddress(): React.JSX.Element {
|
||||
|
||||
const [storeUrl, setStoreUrl] = useState("");
|
||||
|
||||
const serverUrlMutation = useMutation({
|
||||
mutationFn: async (serverUrl: string) => {
|
||||
|
||||
console.log("Mutating server URL");
|
||||
|
||||
if (!!!serverUrl)
|
||||
throw Error("Server URL is empty")
|
||||
|
||||
let jellyfin = new Jellyfin(client);
|
||||
let api = jellyfin.createApi(serverUrl);
|
||||
|
||||
console.log(`Created API client for ${api.basePath}`)
|
||||
return await getSystemApi(api).getPublicSystemInfo()
|
||||
},
|
||||
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: (error: Error) => {
|
||||
console.error("An error occurred connecting to the Jellyfin instance", error);
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<View useSafeArea>
|
||||
<TextField
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from "react";
|
||||
import { View, TextInput, Button } from "react-native";
|
||||
import { authenticateWithCredentials } from "../../../api/mutators/auth";
|
||||
import { View, TextField, Button, ActionBar } from "react-native-ui-lib";
|
||||
|
||||
|
||||
export default function ServerAuthentication(): React.JSX.Element {
|
||||
@@ -9,18 +8,25 @@ export default function ServerAuthentication(): React.JSX.Element {
|
||||
|
||||
return (
|
||||
<View>
|
||||
<TextInput
|
||||
<ActionBar
|
||||
actions={[
|
||||
{
|
||||
label: 'Change Server',
|
||||
onPress: () => console.log("change server requested")
|
||||
}
|
||||
]}/>
|
||||
<TextField
|
||||
placeholder="Username"
|
||||
value={username}
|
||||
onChangeText={(value) => setUsername(value)}
|
||||
/>
|
||||
<TextInput
|
||||
<TextField
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChangeText={(value) => setPassword(value)}
|
||||
secureTextEntry
|
||||
/>
|
||||
<Button title="Sign in" onPress={() => console.log("sign in pressed")} />
|
||||
<Button label="Sign in" onPress={() => console.log("sign in pressed")} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user