Update Storage URI settings
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { Text } from 'react-native-paper';
|
||||
import { PaddedView } from '../components';
|
||||
import { useSettings } from '../contexts';
|
||||
|
||||
function Home(): JSX.Element {
|
||||
const Home = () => {
|
||||
const { settings } = useSettings();
|
||||
|
||||
return (
|
||||
@@ -13,6 +13,6 @@ function Home(): JSX.Element {
|
||||
<Text>Settings: {JSON.stringify(settings)}</Text>
|
||||
</PaddedView>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Home;
|
||||
|
@@ -1,16 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View } from 'react-native';
|
||||
import {
|
||||
Button,
|
||||
Switch,
|
||||
SegmentedButtons,
|
||||
Text,
|
||||
List,
|
||||
Snackbar,
|
||||
} from 'react-native-paper';
|
||||
import { Button, List, Snackbar } from 'react-native-paper';
|
||||
import { useRealm } from '@realm/react';
|
||||
import { openDocumentTree } from 'react-native-scoped-storage';
|
||||
import { DocumentDirectoryPath } from 'react-native-fs';
|
||||
import { PaddedView } from '../components';
|
||||
import styles from '../styles';
|
||||
import { Meme } from '../database';
|
||||
@@ -22,48 +14,7 @@ const SettingsScreen = () => {
|
||||
const [snackbarVisible, setSnackbarVisible] = useState(false);
|
||||
const [snackbarMessage, setSnackbarMessage] = useState('');
|
||||
|
||||
const { settings, setSettings } = useSettings();
|
||||
|
||||
const setUseInternalStorage = (use: boolean) => {
|
||||
if (settings.useInternalStorage === use) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (use) {
|
||||
setSettings({
|
||||
useInternalStorage: use,
|
||||
storageUri: DocumentDirectoryPath,
|
||||
});
|
||||
} else {
|
||||
openDocumentTree(true)
|
||||
.then(uri => {
|
||||
setSettings({
|
||||
useInternalStorage: use,
|
||||
storageUri: uri.uri,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
setSnackbarMessage('Failed to select storage path!');
|
||||
setSnackbarVisible(true);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const setStorageUri = (uri: string) => {
|
||||
if (settings.storageUri === uri) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSettings({ storageUri: uri });
|
||||
};
|
||||
|
||||
const setAddNoMedia = (add: boolean) => {
|
||||
if (settings.addNoMedia === add) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSettings({ addNoMedia: add });
|
||||
};
|
||||
const { setSettings } = useSettings();
|
||||
|
||||
const realm = useRealm();
|
||||
|
||||
@@ -105,41 +56,16 @@ const SettingsScreen = () => {
|
||||
</List.Section>
|
||||
<List.Section>
|
||||
<List.Subheader>Media Storage</List.Subheader>
|
||||
<SegmentedButtons
|
||||
style={styles.marginBottom}
|
||||
buttons={[
|
||||
{ label: 'Internal', value: 'interneal' },
|
||||
{ label: 'External', value: 'external' },
|
||||
]}
|
||||
value={settings.useInternalStorage ? 'interneal' : 'external'}
|
||||
onValueChange={value =>
|
||||
setUseInternalStorage(value === 'interneal')
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
mode="elevated"
|
||||
style={styles.marginBottom}
|
||||
disabled={settings.useInternalStorage}
|
||||
onPress={() => {
|
||||
openDocumentTree(true)
|
||||
.then(uri => {
|
||||
setStorageUri(uri.uri);
|
||||
})
|
||||
.catch(() => {
|
||||
setSnackbarMessage('Failed to select storage path!');
|
||||
setSnackbarVisible(true);
|
||||
});
|
||||
void openDocumentTree().then(uri => {
|
||||
setSettings({ storageUri: uri.uri });
|
||||
});
|
||||
}}>
|
||||
Change External Storage Path
|
||||
</Button>
|
||||
<View style={styles.spaceBetweenHorizontal}>
|
||||
<Text>Hide media from Gallery</Text>
|
||||
<Switch
|
||||
value={settings.addNoMedia}
|
||||
onValueChange={setAddNoMedia}
|
||||
disabled={settings.useInternalStorage}
|
||||
/>
|
||||
</View>
|
||||
</List.Section>
|
||||
</View>
|
||||
</PaddedView>
|
||||
|
22
src/screens/welcome.tsx
Normal file
22
src/screens/welcome.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { Button, Text } from 'react-native-paper';
|
||||
import { PaddedView } from '../components';
|
||||
import styles from '../styles';
|
||||
|
||||
const WelcomeScreen = (properties: { selectStorageLocation: () => void }) => {
|
||||
return (
|
||||
<PaddedView centered>
|
||||
<Text
|
||||
variant="displayMedium"
|
||||
style={[styles.marginBottom, styles.centerText]}>
|
||||
Welcome to Terminally Online!
|
||||
</Text>
|
||||
|
||||
<Button mode="contained" onPress={properties.selectStorageLocation}>
|
||||
Select Storage Location
|
||||
</Button>
|
||||
</PaddedView>
|
||||
);
|
||||
};
|
||||
|
||||
export default WelcomeScreen;
|
Reference in New Issue
Block a user