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

62 lines
2.4 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';
2020-06-21 10:30: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 { useDispatch } from 'react-redux';
import { useNavigation, StackActions } from '@react-navigation/native';
import CredentialGenerator from './components/CredentialGenerator';
2020-07-10 15:25:32 +02:00
import { THEME_COLOR } from 'CONSTANTS';
2020-11-02 22:50:00 +01:00
import { t } from '@localisation';
import useDefaultStyles from 'components/Colors';
import { Text } from 'components/Typography';
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
const dispatch = useDispatch();
const navigation = useNavigation();
// Save creedentials to store and close the modal
const saveCredentials = useCallback((credentials) => {
dispatch(setJellyfinCredentials(credentials));
navigation.dispatch(StackActions.popToTop());
}, [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>
);
}