Add setting for date format

This commit is contained in:
Brandon Presley 2022-09-26 18:23:06 +13:00
parent 46692f5805
commit 023041b846
4 changed files with 35 additions and 2 deletions

View File

@ -27,6 +27,7 @@ export default function SettingsPage() {
const [showUnit, setShowUnit] = useState(!!settings.showUnit);
const [workouts, setWorkouts] = useState(!!settings.workouts);
const [steps, setSteps] = useState(!!settings.steps);
const [date, setDate] = useState('%Y-%m-%d %H:%M');
const {color, setColor} = useContext(CustomTheme);
const {toast} = useContext(SnackbarContext);
@ -48,6 +49,7 @@ export default function SettingsPage() {
color,
workouts: +workouts,
steps: +steps,
date,
});
getSettings();
}, [
@ -61,6 +63,7 @@ export default function SettingsPage() {
color,
workouts,
steps,
date,
]);
const changeAlarmEnabled = useCallback(
@ -189,6 +192,23 @@ export default function SettingsPage() {
))}
</Picker>
)}
{'date format'.includes(search.toLowerCase()) && (
<Picker
style={{color}}
dropdownIconColor={color}
selectedValue={date}
onValueChange={value => setDate(value)}>
<Picker.Item
value="%Y-%m-%d %H:%M"
label="Format date as 1990-12-24 15:05"
/>
<Picker.Item
value="%Y-%m-%d"
label="Format date as 1990-12-24 (YYYY-MM-dd)"
/>
<Picker.Item value="%m-%d" label="Format date as 12-24 (MM-dd)" />
</Picker>
)}
{'alarm sound'.includes(search.toLowerCase()) && (
<Button style={{alignSelf: 'flex-start'}} onPress={changeSound}>
Alarm sound

3
db.ts
View File

@ -103,6 +103,9 @@ const migrations = [
`
ALTER TABLE settings ADD COLUMN nextAlarm TEXT NULL
`,
`
ALTER TABLE settings ADD COLUMN date TEXT NULL
`,
];
export let db: SQLiteDatabase;

View File

@ -1,5 +1,6 @@
import {db} from './db';
import Set from './set';
import {settings} from './settings.service';
export const updateSet = async (value: Set) => {
const update = `
@ -65,13 +66,21 @@ export const getSets = async ({
limit,
offset,
}: PageParams): Promise<Set[]> => {
const format = settings.date || '%Y-%m-%d %H:%M';
const select = `
SELECT * from sets
SELECT id, name, reps, weight, sets, minutes, seconds,
STRFTIME(?, created) as created, unit, image, steps
FROM sets
WHERE name LIKE ? AND NOT hidden
ORDER BY created DESC
LIMIT ? OFFSET ?
`;
const [result] = await db.executeSql(select, [`%${search}%`, limit, offset]);
const [result] = await db.executeSql(select, [
format,
`%${search}%`,
limit,
offset,
]);
return result.rows.raw();
};

View File

@ -10,4 +10,5 @@ export default interface Settings {
workouts: number;
steps: number;
nextAlarm?: string;
date?: string;
}