From a284f045d244e1f773b8b529b586f977132ee4ad Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 1 Dec 2022 15:45:18 +1300 Subject: [PATCH] Add left padding to settings selects --- SettingsPage.tsx | 145 +++++++++++++++++++---------------------------- constants.ts | 1 + input.ts | 3 + options.ts | 19 +++++++ 4 files changed, 81 insertions(+), 87 deletions(-) create mode 100644 options.ts diff --git a/SettingsPage.tsx b/SettingsPage.tsx index 552b5f0..868ba82 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -11,11 +11,11 @@ import { } from 'react-native' import DocumentPicker from 'react-native-document-picker' import {Button, Subheading} from 'react-native-paper' -import {darkColors, lightColors} from './colors' -import {MARGIN} from './constants' +import {ITEM_PADDING, MARGIN} from './constants' import {settingsRepo} from './db' import DrawerHeader from './DrawerHeader' import Input from './input' +import {darkOptions, lightOptions, themeOptions} from './options' import Page from './Page' import Select from './Select' import Switch from './Switch' @@ -142,38 +142,16 @@ export default function SettingsPage() { else toast('Enabled sound for rest timer alarms.') }, []) - const switches: Input[] = useMemo( - () => - [ - {name: 'Rest timers', value: alarm, onChange: changeAlarmEnabled}, - {name: 'Vibrate', value: vibrate, onChange: changeVibrate}, - {name: 'Disable sound', value: noSound, onChange: changeNoSound}, - {name: 'Notifications', value: notify, onChange: changeNotify}, - {name: 'Show images', value: images, onChange: changeImages}, - {name: 'Show unit', value: showUnit, onChange: changeUnit}, - {name: 'Show steps', value: steps, onChange: changeSteps}, - {name: 'Show date', value: showDate, onChange: changeShowDate}, - ].filter(({name}) => name.toLowerCase().includes(term.toLowerCase())), - [ - term, - showDate, - changeShowDate, - alarm, - changeAlarmEnabled, - vibrate, - changeVibrate, - noSound, - changeNoSound, - notify, - changeNotify, - images, - changeImages, - showUnit, - changeUnit, - steps, - changeSteps, - ], - ) + const switches: Input[] = [ + {name: 'Rest timers', value: alarm, onChange: changeAlarmEnabled}, + {name: 'Vibrate', value: vibrate, onChange: changeVibrate}, + {name: 'Disable sound', value: noSound, onChange: changeNoSound}, + {name: 'Notifications', value: notify, onChange: changeNotify}, + {name: 'Show images', value: images, onChange: changeImages}, + {name: 'Show unit', value: showUnit, onChange: changeUnit}, + {name: 'Show steps', value: steps, onChange: changeSteps}, + {name: 'Show date', value: showDate, onChange: changeShowDate}, + ].filter(({name}) => name.toLowerCase().includes(term.toLowerCase())) const changeTheme = useCallback( (value: string) => { @@ -210,7 +188,7 @@ export default function SettingsPage() { [setLightColor], ) - const renderItem = useCallback( + const renderSwitch = useCallback( ({item}: {item: Input}) => ( item.onChange(!item.value)} @@ -223,6 +201,44 @@ export default function SettingsPage() { [], ) + const selects: Input[] = [ + {name: 'Theme', value: theme, onChange: changeTheme, items: themeOptions}, + { + name: 'Dark color', + value: darkColor, + onChange: changeDarkColor, + items: lightOptions, + }, + { + name: 'Light color', + value: lightColor, + onChange: changeLightColor, + items: darkOptions, + }, + { + name: 'Date format', + value: date, + onChange: changeDate, + items: formatOptions.map(option => ({ + label: format(today, option), + value: option, + })), + }, + ].filter(({name}) => name.toLowerCase().includes(term.toLowerCase())) + + const renderSelect = useCallback( + ({item}: {item: Input}) => ( + - )} - {'color'.includes(term.toLowerCase()) && ( - ({ - label: color.name, - value: color.hex, - color: color.hex, - }))} - /> - )} - {'date format'.includes(term.toLowerCase()) && ( -