cleaning up and praying that the auth screen doesn't crash this time

This commit is contained in:
Violet Caulfield
2024-10-17 17:56:41 -05:00
parent dd1289441c
commit f0f14ef39d
3 changed files with 26 additions and 16 deletions

View File

@@ -14,12 +14,13 @@ export default function Login(): React.JSX.Element {
const Stack = createStackNavigator();
return (
<Stack.Navigator screenOptions={{ cardStyle: { backgroundColor: useColorScheme() === 'dark' ? 'black' : 'white' }}}>
<Stack.Navigator>
{
(_.isUndefined(server) || _.isEmpty(server.url)) ? (
<Stack.Screen
name="ServerAddress"
options={{
headerShown: false,
title: "Connect to Jellyfin",
animationTypeForReplace: 'pop',
headerStyle: {
@@ -28,14 +29,25 @@ export default function Login(): React.JSX.Element {
headerTintColor: Colors.$iconPrimary
}}
component={ServerAddress}
>
</Stack.Screen>
/>
) : (
(_.isUndefined(username)) ? (
<Stack.Screen name="ServerAuthentication" component={ServerAuthentication} />
<Stack.Screen
name="ServerAuthentication"
options={{
headerShown: false
}}
component={ServerAuthentication}
/>
) : (
<Stack.Screen name="LibrarySelection" component={ServerLibrary}></Stack.Screen>
<Stack.Screen
name="LibrarySelection"
options={{
headerShown: false
}}
component={ServerLibrary}
/>
)
)
}

View File

@@ -1,12 +1,10 @@
import React from "react";
import { useColorScheme } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useMutation } from "@tanstack/react-query";
import { AsyncStorageKeys } from "../../../enums/async-storage-keys";
import { useApiClientContext } from "../../jellyfin-api-provider";
import { TextField, View, Button, Colors } from 'react-native-ui-lib';
import { jellifyStyles } from "../../styles";
import { credentials } from "../../../api/mutators/storage";
import { JellyfinCredentials } from "../../../api/types/jellyfin-credentials";
import * as Keychain from "react-native-keychain"
import _ from "lodash";
@@ -16,13 +14,11 @@ export default function ServerAuthentication(): React.JSX.Element {
const [username, setUsername] = React.useState('');
const [password, setPassword] = React.useState('');
const isDarkMode = useColorScheme() === 'dark';
const { apiClient, setApiClient, server, setServer, setChangeServer } = useApiClientContext();
const useApiMutation = useMutation({
mutationFn: async (credentials: JellyfinCredentials) => {
return apiClient!.authenticateUserByName(credentials.username, credentials.password!);
return await apiClient!.authenticateUserByName(credentials.username, credentials.password!);
},
onSuccess: async (authResult, credentials) => {
@@ -81,7 +77,9 @@ export default function ServerAuthentication(): React.JSX.Element {
<Button
label="Sign in"
color={Colors.$iconPrimary}
onPress={() => useApiMutation.mutate({ username, password })}
onPress={() => {
useApiMutation.mutate({ username, password })
}}
size={Button.sizes.medium}
margin
/>

View File

@@ -4,7 +4,7 @@ import { setupPlayer } from "react-native-track-player/lib/src/trackPlayer";
import _ from "lodash";
import { JellyfinApiClientProvider, useApiClientContext } from "./jellyfin-api-provider";
import React, { } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { NavigationContainer, useTheme } from "@react-navigation/native";
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Navigation from "./navigation";
import { jellifyStyles } from "./styles";
@@ -40,12 +40,12 @@ function conditionalHomeRender(): React.JSX.Element {
return (
<View style={jellifyStyles.container}>
<NavigationContainer>
<Stack.Navigator>
<NavigationContainer theme={useTheme()}>
<Stack.Navigator screenOptions={{ headerShown: false }}>
{ !_.isUndefined(libraryId) ? (
<Tab.Screen name="Navigation" component={Navigation} />
<Tab.Screen name="Navigation" options={{ headerShown: false }} component={Navigation} />
) : (
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Login" options={{ headerShown: false }} component={Login} />
)}
</Stack.Navigator>
</NavigationContainer>