Update clunky auto to manual sorting by time, primary color blue
This commit is contained in:
@@ -186,20 +186,11 @@ export const useAppState = () => {
|
||||
days: prev.days.map(day => {
|
||||
if (day.id !== dayId) return day;
|
||||
|
||||
// Update the dose field
|
||||
// Update the dose field (no auto-sort)
|
||||
const updatedDoses = day.doses.map(dose =>
|
||||
dose.id === doseId ? { ...dose, [field]: value } : dose
|
||||
);
|
||||
|
||||
// Sort by time if time field was changed
|
||||
if (field === 'time') {
|
||||
updatedDoses.sort((a, b) => {
|
||||
const timeA = a.time || '00:00';
|
||||
const timeB = b.time || '00:00';
|
||||
return timeA.localeCompare(timeB);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...day,
|
||||
doses: updatedDoses
|
||||
@@ -208,6 +199,26 @@ export const useAppState = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
const sortDosesInDay = (dayId: string) => {
|
||||
setAppState(prev => ({
|
||||
...prev,
|
||||
days: prev.days.map(day => {
|
||||
if (day.id !== dayId) return day;
|
||||
|
||||
const sortedDoses = [...day.doses].sort((a, b) => {
|
||||
const timeA = a.time || '00:00';
|
||||
const timeB = b.time || '00:00';
|
||||
return timeA.localeCompare(timeB);
|
||||
});
|
||||
|
||||
return {
|
||||
...day,
|
||||
doses: sortedDoses
|
||||
};
|
||||
})
|
||||
}));
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
if (window.confirm("Bist du sicher, dass du alle Einstellungen auf die Standardwerte zurücksetzen möchtest? Dies kann nicht rückgängig gemacht werden.")) {
|
||||
window.localStorage.removeItem(LOCAL_STORAGE_KEY);
|
||||
@@ -227,6 +238,7 @@ export const useAppState = () => {
|
||||
addDoseToDay,
|
||||
removeDoseFromDay,
|
||||
updateDoseInDay,
|
||||
sortDosesInDay,
|
||||
handleReset
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user