Files
jellyfin-audio-player/src/screens/modals/SetJellyfinServer/index.tsx

64 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-06-17 14:58:04 +02:00
import React, { useState, useCallback } from 'react';
import { Button, View } from 'react-native';
2023-06-19 22:26:41 +02:00
import Modal from '@/components/Modal';
import Input from '@/components/Input';
import { setJellyfinCredentials } from '@/store/settings/actions';
2020-06-17 14:58:04 +02:00
import { useNavigation, StackActions } from '@react-navigation/native';
import CredentialGenerator from './components/CredentialGenerator';
2023-06-19 22:26:41 +02:00
import { THEME_COLOR } from '@/CONSTANTS';
import { t } from '@/localisation';
import useDefaultStyles from '@/components/Colors';
import { Text } from '@/components/Typography';
2024-01-29 00:14:19 +01:00
import { AppState, useAppDispatch } from '@/store';
2020-06-17 14:58:04 +02:00
export default function SetJellyfinServer() {
const defaultStyles = useDefaultStyles();
2020-06-17 14:58:04 +02:00
// State for first screen
const [serverUrl, setServerUrl] = useState<string>();
const [isLogginIn, setIsLogginIn] = useState<boolean>(false);
// Handlers needed for dispatching stuff
2022-05-18 22:10:06 +02:00
const dispatch = useAppDispatch();
2020-06-17 14:58:04 +02:00
const navigation = useNavigation();
// Save creedentials to store and close the modal
2024-01-29 00:14:19 +01:00
const saveCredentials = useCallback((credentials: AppState['settings']['jellyfin']) => {
if (credentials) {
dispatch(setJellyfinCredentials(credentials));
navigation.dispatch(StackActions.popToTop());
}
2020-06-17 14:58:04 +02:00
}, [navigation, dispatch]);
return (
<Modal>
{isLogginIn ? (
<CredentialGenerator
serverUrl={serverUrl as string}
onCredentialsRetrieved={saveCredentials}
/>
) : (
2020-08-25 10:39:21 +02:00
<View style={{ padding: 20, flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>
2020-11-02 22:50:00 +01:00
{t('set-jellyfin-server-instruction')}
2020-08-09 17:49:36 +02:00
</Text>
2020-06-17 14:58:04 +02:00
<Input
placeholder="https://jellyfin.yourserver.io/"
onChangeText={setServerUrl}
value={serverUrl}
keyboardType="url"
autoCapitalize="none"
autoCorrect={false}
style={[ defaultStyles.input, { width: '100%' } ]}
2020-06-17 14:58:04 +02:00
/>
2020-07-10 15:25:32 +02:00
<Button
2020-11-02 22:50:00 +01:00
title={t('set-jellyfin-server')}
2020-07-10 15:25:32 +02:00
onPress={() => setIsLogginIn(true)}
disabled={!serverUrl?.length}
color={THEME_COLOR}
/>
2020-06-17 14:58:04 +02:00
</View>
)}
</Modal>
);
}