Add intake auto sorting, chart intake markers, upped max daily intakes to 6, various style changes
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { LOCAL_STORAGE_KEY, getDefaultState, type AppState, type DayGroup, type DayDose } from '../constants/defaults';
|
||||
import { LOCAL_STORAGE_KEY, getDefaultState, MAX_DOSES_PER_DAY, type AppState, type DayGroup, type DayDose } from '../constants/defaults';
|
||||
|
||||
export const useAppState = () => {
|
||||
const [appState, setAppState] = React.useState<AppState>(getDefaultState);
|
||||
@@ -258,13 +258,34 @@ export const useAppState = () => {
|
||||
...prev,
|
||||
days: prev.days.map(day => {
|
||||
if (day.id !== dayId) return day;
|
||||
if (day.doses.length >= 5) return day; // Max 5 doses per day
|
||||
if (day.doses.length >= MAX_DOSES_PER_DAY) return day; // Max doses per day
|
||||
|
||||
// Calculate dynamic default time: max time + 1 hour, capped at 23:59
|
||||
let defaultTime = '12:00';
|
||||
if (!newDose?.time && day.doses.length > 0) {
|
||||
// Find the latest time in the day
|
||||
const times = day.doses.map(d => d.time || '00:00');
|
||||
const maxTime = times.reduce((max, time) => time > max ? time : max, '00:00');
|
||||
|
||||
// Parse and add 1 hour
|
||||
const [hours, minutes] = maxTime.split(':').map(Number);
|
||||
let newHours = hours + 1;
|
||||
|
||||
// Cap at 23:59
|
||||
if (newHours > 23) {
|
||||
newHours = 23;
|
||||
defaultTime = '23:59';
|
||||
} else {
|
||||
defaultTime = `${newHours.toString().padStart(2, '0')}:00`;
|
||||
}
|
||||
}
|
||||
|
||||
const dose: DayDose = {
|
||||
id: `dose-${Date.now()}-${Math.random()}`,
|
||||
time: newDose?.time || '12:00',
|
||||
time: newDose?.time || defaultTime,
|
||||
ldx: newDose?.ldx || '0',
|
||||
damph: newDose?.damph || '0',
|
||||
isFed: newDose?.isFed || false,
|
||||
};
|
||||
|
||||
return { ...day, doses: [...day.doses, dose] };
|
||||
|
||||
Reference in New Issue
Block a user