From faabe00c7e166d6b7ea0cc7693e6d26b77769f5e Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:11:08 +0900 Subject: [PATCH] impl more settings state --- app/components/SettingsItem.tsx | 8 +- app/components/SettingsSwitch.tsx | 36 +++++++ app/models/settings.ts | 5 +- app/screens/ServerView.tsx | 32 +----- app/screens/Settings.tsx | 160 +++++++++++++++++++++++++++++- app/state/settings.ts | 77 ++++++++++++-- app/state/trackplayer.ts | 2 +- 7 files changed, 270 insertions(+), 50 deletions(-) create mode 100644 app/components/SettingsSwitch.tsx diff --git a/app/components/SettingsItem.tsx b/app/components/SettingsItem.tsx index 908638b..aaccfd4 100644 --- a/app/components/SettingsItem.tsx +++ b/app/components/SettingsItem.tsx @@ -4,11 +4,13 @@ import React from 'react' import { StyleSheet, View, Text } from 'react-native' import PressableOpacity from './PressableOpacity' -const SettingsItem: React.FC<{ +export type SettingsItemProps = { title: string subtitle?: string onPress?: () => void -}> = ({ title, subtitle, onPress, children }) => { +} + +const SettingsItem: React.FC = ({ title, subtitle, onPress, children }) => { return ( @@ -22,13 +24,13 @@ const SettingsItem: React.FC<{ const styles = StyleSheet.create({ item: { - height: 60, marginBottom: 10, alignItems: 'stretch', flexDirection: 'row', }, itemText: { flex: 1, + paddingVertical: 10, alignSelf: 'stretch', alignItems: 'flex-start', }, diff --git a/app/components/SettingsSwitch.tsx b/app/components/SettingsSwitch.tsx new file mode 100644 index 0000000..01373d8 --- /dev/null +++ b/app/components/SettingsSwitch.tsx @@ -0,0 +1,36 @@ +import colors from '@app/styles/colors' +import React from 'react' +import { Switch, StyleSheet } from 'react-native' +import SettingsItem, { SettingsItemProps } from './SettingsItem' + +export type SettingsSwitchProps = SettingsItemProps & { + value: boolean + setValue: (value: boolean) => void +} + +const SettingsSwitch = React.memo(props => { + const { value, setValue } = props + + return ( + setValue(!value)} {...props}> + + + ) +}) + +const styles = StyleSheet.create({ + switch: { + marginLeft: 20, + }, +}) + +export default SettingsSwitch diff --git a/app/models/settings.ts b/app/models/settings.ts index cc9c288..6f9c78b 100644 --- a/app/models/settings.ts +++ b/app/models/settings.ts @@ -4,7 +4,6 @@ export interface Server { username: string token: string salt: string - scrobble: boolean } export interface AppSettings { @@ -13,4 +12,8 @@ export interface AppSettings { lists: string[] } activeServer?: string + scrobble: boolean + estimateContentLength: boolean + maxBitrateWifi: number + maxBitrateMobile: number } diff --git a/app/screens/ServerView.tsx b/app/screens/ServerView.tsx index 130a666..020e533 100644 --- a/app/screens/ServerView.tsx +++ b/app/screens/ServerView.tsx @@ -1,6 +1,5 @@ import Button from '@app/components/Button' import GradientScrollView from '@app/components/GradientScrollView' -import SettingsItem from '@app/components/SettingsItem' import { Server } from '@app/models/settings' import { selectSettings } from '@app/state/settings' import { useStore } from '@app/state/store' @@ -10,7 +9,6 @@ import { useNavigation } from '@react-navigation/native' import md5 from 'md5' import React, { useCallback, useState } from 'react' import { StyleSheet, Text, TextInput, View } from 'react-native' -import { Switch } from 'react-native-gesture-handler' import { v4 as uuidv4 } from 'uuid' function replaceIndex(array: T[], index: number, replacement: T): T[] { @@ -32,7 +30,6 @@ const ServerView: React.FC<{ const [address, setAddress] = useState(server?.address || '') const [username, setUsername] = useState(server?.username || '') const [password, setPassword] = useState(server?.token ? 'password' : '') - const [scrobble, setScrobble] = useState(server?.scrobble || false) const validate = useCallback(() => { return !!address && !!username && !!password @@ -69,7 +66,6 @@ const ServerView: React.FC<{ username, salt, token, - scrobble, } if (server) { @@ -89,20 +85,7 @@ const ServerView: React.FC<{ } exit() - }, [ - activeServer, - address, - exit, - id, - password, - scrobble, - server, - servers, - setActiveServer, - setServers, - username, - validate, - ]) + }, [activeServer, address, exit, id, password, server, servers, setActiveServer, setServers, username, validate]) const remove = useCallback(() => { if (!canRemove()) { @@ -155,19 +138,6 @@ const ServerView: React.FC<{ value={password} onChangeText={setPassword} /> - - -