bug fixes
This commit is contained in:
@@ -112,14 +112,6 @@ function timeToMinutes(t: string): number {
|
||||
return h * 60 + m;
|
||||
}
|
||||
|
||||
function timeToMinutesLocal(t: string, offsetMinutes: number): number {
|
||||
const mins = timeToMinutes(t);
|
||||
const localMins = mins - offsetMinutes;
|
||||
if (localMins < 0) return localMins + 24 * 60;
|
||||
if (localMins >= 24 * 60) return localMins - 24 * 60;
|
||||
return localMins;
|
||||
}
|
||||
|
||||
function minutesToTop(minutes: number, startHour: number): number {
|
||||
return ((minutes - startHour * 60) / 60) * HOUR_HEIGHT;
|
||||
}
|
||||
@@ -135,17 +127,6 @@ function formatTime(t: string): string {
|
||||
return `${dh}:${String(m).padStart(2, '0')} ${period}`;
|
||||
}
|
||||
|
||||
function formatTimeLocal(t: string, offsetMinutes: number): string {
|
||||
const totalMins = timeToMinutes(t) - offsetMinutes;
|
||||
let h = Math.floor(totalMins / 60) % 24;
|
||||
if (h < 0) h += 24;
|
||||
let m = totalMins % 60;
|
||||
if (m < 0) m += 60;
|
||||
const period = h >= 12 ? 'PM' : 'AM';
|
||||
const dh = h > 12 ? h - 12 : h === 0 ? 12 : h;
|
||||
return `${dh}:${String(m).padStart(2, '0')} ${period}`;
|
||||
}
|
||||
|
||||
function addMinutesToTime(t: string, mins: number): string {
|
||||
const [h, m] = t.split(':').map(Number);
|
||||
const total = h * 60 + m + mins;
|
||||
@@ -229,7 +210,6 @@ export default function RoutinesPage() {
|
||||
const [todayMeds, setTodayMeds] = useState<TodaysMedication[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [selectedDate, setSelectedDate] = useState(() => new Date());
|
||||
const [timezoneOffset, setTimezoneOffset] = useState(0);
|
||||
const [nowMinutes, setNowMinutes] = useState(() => {
|
||||
const n = new Date();
|
||||
return n.getHours() * 60 + n.getMinutes();
|
||||
@@ -250,7 +230,7 @@ export default function RoutinesPage() {
|
||||
|
||||
const scheduledForDay = allSchedules
|
||||
.filter((s) => s.days.includes(dayKey))
|
||||
.sort((a, b) => timeToMinutesLocal(a.time, timezoneOffset) - timeToMinutesLocal(b.time, timezoneOffset));
|
||||
.sort((a, b) => timeToMinutes(a.time) - timeToMinutes(b.time));
|
||||
|
||||
const scheduledRoutineIds = new Set(allSchedules.map((s) => s.routine_id));
|
||||
const unscheduledRoutines = allRoutines.filter(
|
||||
@@ -317,18 +297,14 @@ export default function RoutinesPage() {
|
||||
|
||||
// ── Dynamic time window ───────────────────────────────────────
|
||||
const allEventMins = [
|
||||
nowMinutes,
|
||||
...scheduledForDay.map((e) => timeToMinutesLocal(e.time, timezoneOffset)),
|
||||
...groupedMedEntries.map((e) => timeToMinutesLocal(e.time, timezoneOffset)),
|
||||
...scheduledForDay.map((e) => timeToMinutes(e.time)),
|
||||
...groupedMedEntries.map((e) => timeToMinutes(e.time)),
|
||||
];
|
||||
const displayStartHour =
|
||||
allEventMins.length > 0
|
||||
? Math.max(5, Math.floor(Math.min(...allEventMins) / 60) - 1)
|
||||
: DEFAULT_START_HOUR;
|
||||
const displayEndHour =
|
||||
allEventMins.length > 0
|
||||
? Math.min(24, Math.ceil(Math.max(...allEventMins) / 60) + 2)
|
||||
: DEFAULT_END_HOUR;
|
||||
const eventStartHour = allEventMins.length > 0 ? Math.floor(Math.min(...allEventMins) / 60) : DEFAULT_START_HOUR;
|
||||
const eventEndHour = allEventMins.length > 0 ? Math.ceil(Math.max(...allEventMins) / 60) : DEFAULT_END_HOUR;
|
||||
// Always include current time in the view
|
||||
const displayStartHour = Math.min(Math.max(0, eventStartHour - 1), Math.floor(nowMinutes / 60));
|
||||
const displayEndHour = Math.max(Math.min(24, eventEndHour + 2), Math.ceil(nowMinutes / 60) + 1);
|
||||
|
||||
const nowTopPx = minutesToTop(nowMinutes, displayStartHour);
|
||||
|
||||
@@ -440,13 +416,11 @@ export default function RoutinesPage() {
|
||||
api.routines.list(),
|
||||
api.routines.listAllSchedules(),
|
||||
api.medications.getToday().catch(() => []),
|
||||
api.preferences.get().catch(() => ({ timezone_offset: 0 })),
|
||||
])
|
||||
.then(([routines, schedules, meds, prefs]) => {
|
||||
.then(([routines, schedules, meds]) => {
|
||||
setAllRoutines(routines);
|
||||
setAllSchedules(schedules);
|
||||
setTodayMeds(meds);
|
||||
setTimezoneOffset((prefs as any).timezone_offset || 0);
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => setIsLoading(false));
|
||||
@@ -640,7 +614,7 @@ export default function RoutinesPage() {
|
||||
|
||||
{/* Routine cards */}
|
||||
{scheduledForDay.map((entry) => {
|
||||
const startMin = timeToMinutesLocal(entry.time, timezoneOffset);
|
||||
const startMin = timeToMinutes(entry.time);
|
||||
const topPx = minutesToTop(startMin, displayStartHour);
|
||||
const heightPx = durationToHeight(entry.total_duration_minutes);
|
||||
const endMin = startMin + entry.total_duration_minutes;
|
||||
@@ -678,17 +652,16 @@ export default function RoutinesPage() {
|
||||
{entry.routine_name}
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||||
{formatTimeLocal(entry.time, timezoneOffset)}
|
||||
{formatTime(entry.time)}
|
||||
{entry.total_duration_minutes > 0 && (
|
||||
<>
|
||||
{' '}
|
||||
-{' '}
|
||||
{formatTimeLocal(
|
||||
{formatTime(
|
||||
addMinutesToTime(
|
||||
entry.time,
|
||||
entry.total_duration_minutes
|
||||
),
|
||||
timezoneOffset
|
||||
)
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -627,7 +627,6 @@ export const api = {
|
||||
haptic_enabled: boolean;
|
||||
show_launch_screen: boolean;
|
||||
celebration_style: string;
|
||||
timezone_offset: number;
|
||||
}>('/api/preferences', { method: 'GET' });
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user