Shitty gadgets removed. Some useful gadgets added.

This commit is contained in:
2026-07-11 03:12:56 +03:30
parent 2f8c9f0f4d
commit ed8ff61205
31 changed files with 1489 additions and 170 deletions

View File

@@ -2,8 +2,9 @@ import { isSameLocalCalendarDay } from '@/components/appointments/appointmentTim
import type { TreatmentAppointment } from '@/types/treatment';
/**
* For the selected calendar day: if it is today, pick the appointment whose time range contains now;
* otherwise pick the first appointment of that day. Returns null when there are no appointments.
* For the selected calendar day: if it is today, pick the in-progress appointment,
* otherwise the appointment whose start time is nearest to now; on other days pick
* the first appointment of that day. Returns null when there are no appointments.
*/
export function pickAutoAppointment(
appointments: TreatmentAppointment[],
@@ -19,7 +20,23 @@ export function pickAutoAppointment(
const e = new Date(a.endAt).getTime();
if (t >= s && t <= e) return a.id;
}
let nearest = appointments[0];
let nearestDistance = Math.abs(new Date(nearest.startAt).getTime() - t);
for (const appointment of appointments.slice(1)) {
const distance = Math.abs(new Date(appointment.startAt).getTime() - t);
if (distance < nearestDistance) {
nearest = appointment;
nearestDistance = distance;
}
}
return nearest.id;
}
return appointments[0].id;
}
export function treatmentAppointmentHref(appointmentId?: string): string {
if (!appointmentId) return '/treatment';
return `/treatment?appointmentId=${encodeURIComponent(appointmentId)}`;
}