diff --git a/src/components/layout/mobile-nav-sheet.tsx b/src/components/layout/mobile-nav-sheet.tsx index 813a2f6..1441991 100644 --- a/src/components/layout/mobile-nav-sheet.tsx +++ b/src/components/layout/mobile-nav-sheet.tsx @@ -102,31 +102,31 @@ export function MobileNavSheet(props: { onPointerUp={endDrag} onPointerCancel={endDrag} > -
- +
+
-
-

{t("nav.menu")}

+
+

{t("nav.menu")}

-
+
{(group) => ( -
-

+

+

{t(group.labelKey)}

-
+
{(item) => { const active = () => current()?.id === item.id; @@ -136,19 +136,19 @@ export function MobileNavSheet(props: { onClick={props.onClose} aria-current={active() ? "page" : undefined} class={cn( - "flex items-center gap-3 rounded-md px-2 py-3 transition-colors active:bg-muted", + "flex items-center gap-2.5 rounded-md px-3 py-1.5 transition-colors active:bg-muted", active() ? "text-primary" : "text-foreground", )} > - + - + {t(item.labelKey)} 0}> diff --git a/src/components/layout/mobile-tab-bar.tsx b/src/components/layout/mobile-tab-bar.tsx index 8747909..4d4533b 100644 --- a/src/components/layout/mobile-tab-bar.tsx +++ b/src/components/layout/mobile-tab-bar.tsx @@ -46,14 +46,14 @@ export function MobileTabBar(props: { onMenu: () => void }) {
  • diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 625fb60..d5dbe1b 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -1452,6 +1452,9 @@ export type MessageKey = | "calendar.lessons" | "calendar.studies" | "calendar.homework" + | "calendar.viewDay" + | "calendar.viewWeek" + | "calendar.viewMonth" | "nav.appointments" | "appointments.title" | "appointments.subtitle" @@ -2161,6 +2164,9 @@ const en: Dict = { "calendar.lessons": "Lessons", "calendar.studies": "Studies & clubs", "calendar.homework": "Homework due", + "calendar.viewDay": "Day", + "calendar.viewWeek": "Week", + "calendar.viewMonth": "Month", "nav.appointments": "Appointments", "appointments.title": "Appointments", "appointments.subtitle": "Pick one of the times a teacher opened for meetings, then follow your request here.", @@ -3698,6 +3704,9 @@ const tr: Dict = { "calendar.lessons": "Dersler", "calendar.studies": "Etütler ve kulüpler", "calendar.homework": "Ödev teslimi", + "calendar.viewDay": "Gün", + "calendar.viewWeek": "Hafta", + "calendar.viewMonth": "Ay", "nav.appointments": "Randevular", "appointments.title": "Randevular", "appointments.subtitle": "Bir öğretmenin görüşmeye açtığı saatlerden birini seç, talebini buradan takip et.", diff --git a/src/pages/calendar-page.tsx b/src/pages/calendar-page.tsx index 315631a..cfe3e4e 100644 --- a/src/pages/calendar-page.tsx +++ b/src/pages/calendar-page.tsx @@ -114,6 +114,16 @@ const KIND_STYLES: Record = { const KIND_ORDER = Object.keys(KIND_STYLES) as CalendarKind[]; +/** Day / week / month, the three zoom levels a phone calendar is expected to + * offer. The month grid alone is unreadable at 45px per cell. */ +type CalendarView = "day" | "week" | "month"; + +const VIEWS: { id: CalendarView; labelKey: MessageKey }[] = [ + { id: "day", labelKey: "calendar.viewDay" }, + { id: "week", labelKey: "calendar.viewWeek" }, + { id: "month", labelKey: "calendar.viewMonth" }, +]; + function dateKey(d: Date) { return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`; } @@ -135,6 +145,7 @@ function CalendarContent() { const [viewYear, setViewYear] = createSignal(nowDate().getFullYear()); const [viewMonth, setViewMonth] = createSignal(nowDate().getMonth()); const [selected, setSelected] = createSignal(dateKey(nowDate())); + const [view, setView] = createSignal("month"); const [events] = createResource(async () => (await getEvents({ limit: 100 })).items, { initialValue: [] }); const [exams] = createResource(async () => (await getExams({ limit: 100 })).items, { initialValue: [] }); @@ -255,6 +266,41 @@ function CalendarContent() { ms == null ? "" : new Date(ms).toLocaleTimeString(locale() === "tr" ? "tr-TR" : "en-US", { hour: "2-digit", minute: "2-digit" }); const timeRange = (item: CalendarItem) => (item.endsAt ? `${clock(item.at)} — ${clock(item.endsAt)}` : clock(item.at)); + const intl = () => (locale() === "tr" ? "tr-TR" : "en-US"); + + /** Moves the selected day, keeping the month grid on the same page as it. */ + const shiftSelected = (days: number) => { + const d = selectedDay(); + d.setDate(d.getDate() + days); + setSelected(dateKey(d)); + setViewYear(d.getFullYear()); + setViewMonth(d.getMonth()); + }; + + // Monday-first, like the month grid. + const weekDays = createMemo(() => { + const start = selectedDay(); + start.setDate(start.getDate() - ((start.getDay() + 6) % 7)); + return Array.from({ length: 7 }, (_, i) => { + const d = new Date(start); + d.setDate(start.getDate() + i); + return d; + }); + }); + + const rangeLabel = () => { + if (view() === "month") return monthLabel(); + if (view() === "day") { + return selectedDay().toLocaleDateString(intl(), { day: "numeric", month: "long", year: "numeric" }); + } + const days = weekDays(); + return `${days[0].toLocaleDateString(intl(), { day: "numeric", month: "short" })} – ${days[6].toLocaleDateString(intl(), { day: "numeric", month: "short", year: "numeric" })}`; + }; + + // One pair of arrows for all three views: they step by whatever is on screen. + const goPrev = () => (view() === "month" ? prevMonth() : shiftSelected(view() === "week" ? -7 : -1)); + const goNext = () => (view() === "month" ? nextMonth() : shiftSelected(view() === "week" ? 7 : 1)); + const goToday = () => { const n = nowDate(); setViewYear(n.getFullYear()); @@ -277,21 +323,41 @@ function CalendarContent() {
    -

    {t("calendar.title")}

    -
    - - {monthLabel()} -
    - +
    + {/* Day / week / month, the way a phone calendar switches zoom. */} +
    + + {(entry) => ( + + )} + +
    + +
    {/* Legend — six categories share one grid, so the colours need naming. */} @@ -307,7 +373,49 @@ function CalendarContent() {
    }> -
    +
    + + {/* Week strip: seven tappable days with their category dots, the + middle zoom level between a month of cells and one day's list. */} +
    + + {(day) => { + const key = dateKey(day); + const dayItems = () => itemsByDay().get(key) ?? []; + const today = () => dateKey(nowDate()) === key; + return ( + + ); + }} + +
    +
    + +
    @@ -329,7 +437,7 @@ function CalendarContent() {