mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-04 20:41:51 +08:00
refactor(schedules): use fixed scrollable hourly grid in day and week views
- Remove auto-fit grid density mode and toolbar toggle in Day/Week views - Render uniform 52px hourly rows with full 01:00-23:00 gutter labels and smooth vertical scrolling - Auto-scroll near current hour when entering Day/Week views or clicking Today
This commit is contained in:
1 parent
be2fff5561
commit
8efd26b8b7
2 files changed
+33
-83
No files matched your search
@@ -61,8 +61,7 @@ import type { ProxyPoolEntry, Task, TaskSchedule } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { MonthSwimlaneView } from "./month-swimlane-view";
|
||||
|
||||
const EXPANDED_HOUR_HEIGHT = 52; // px per hour in expanded mode
|
||||
const MIN_FIT_HOUR_HEIGHT = 22; // minimum px per hour in auto-fit mode
|
||||
const HOUR_HEIGHT = 52; // px per hour slot in scrollable Day/Week time grid
|
||||
const ALL_STATUSES: TaskSchedule["status"][] = ["running", "waiting", "outside", "paused", "completed", "error"];
|
||||
|
||||
const STATUS_STYLE: Record<
|
||||
@@ -733,7 +732,6 @@ export function ScheduleCalendarWorkspace({
|
||||
left: number;
|
||||
top: number;
|
||||
} | null>(null);
|
||||
const [gridDensity, setGridDensity] = React.useState<"fit" | "comfortable">("fit");
|
||||
const [sidebarOpen, setSidebarOpen] = React.useState(true);
|
||||
React.useEffect(() => {
|
||||
try {
|
||||
@@ -754,43 +752,24 @@ export function ScheduleCalendarWorkspace({
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
const [gridViewportHeight, setGridViewportHeight] = React.useState(0);
|
||||
const gridBodyRef = React.useRef<HTMLDivElement>(null);
|
||||
const dayColumnsRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
const scrollToCurrentHour = React.useCallback(
|
||||
(smooth = false) => {
|
||||
const el = gridBodyRef.current;
|
||||
if (!el) return;
|
||||
const targetHour = Math.max(0, Math.min(18, nowParts.hour >= 6 ? nowParts.hour - 2 : 7));
|
||||
el.scrollTo({ top: targetHour * HOUR_HEIGHT, behavior: smooth ? "smooth" : "auto" });
|
||||
},
|
||||
[nowParts.hour],
|
||||
);
|
||||
|
||||
// Scroll the week/day time grid near current server hour when switching into Day/Week view.
|
||||
React.useEffect(() => {
|
||||
if (viewMode !== "week" && viewMode !== "day") return;
|
||||
const el = gridBodyRef.current;
|
||||
if (!el) return;
|
||||
const updateHeight = () => {
|
||||
const h = el.clientHeight;
|
||||
if (h > 0) setGridViewportHeight(h);
|
||||
};
|
||||
updateHeight();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const ro = new ResizeObserver(updateHeight);
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
}, [viewMode]);
|
||||
|
||||
const hourHeight = React.useMemo(() => {
|
||||
if (gridDensity === "comfortable") return EXPANDED_HOUR_HEIGHT;
|
||||
if (gridViewportHeight <= 0) return 26;
|
||||
return Math.max(MIN_FIT_HOUR_HEIGHT, gridViewportHeight / 24);
|
||||
}, [gridDensity, gridViewportHeight]);
|
||||
|
||||
// Scroll the week/day time grid near current server hour when in expanded mode.
|
||||
React.useEffect(() => {
|
||||
if (viewMode !== "week" && viewMode !== "day") return;
|
||||
const el = gridBodyRef.current;
|
||||
if (!el) return;
|
||||
if (gridDensity === "fit") {
|
||||
el.scrollTop = 0;
|
||||
return;
|
||||
}
|
||||
const targetHour = Math.max(0, Math.min(18, nowParts.hour >= 6 ? nowParts.hour - 2 : 7));
|
||||
el.scrollTop = targetHour * EXPANDED_HOUR_HEIGHT;
|
||||
}, [viewMode, gridDensity]); // intentionally run on view/density switch
|
||||
scrollToCurrentHour(false);
|
||||
}, [viewMode]); // intentionally run on view switch
|
||||
const taskById = React.useMemo(() => {
|
||||
const map = new Map<number, Task>();
|
||||
for (const t of tasks) {
|
||||
@@ -1392,7 +1371,7 @@ export function ScheduleCalendarWorkspace({
|
||||
const dx = e.clientX - dragState.originClientX;
|
||||
const dy = e.clientY - dragState.originClientY;
|
||||
const moved = dragState.moved || Math.abs(dx) > 4 || Math.abs(dy) > 4;
|
||||
const deltaMinutes = Math.round(((dy / hourHeight) * 60) / 15) * 15;
|
||||
const deltaMinutes = Math.round(((dy / HOUR_HEIGHT) * 60) / 15) * 15;
|
||||
|
||||
let nextDateKey = dragState.occurrence.dateKey;
|
||||
if (viewMode === "week" && dayColumnsRef.current) {
|
||||
@@ -1451,7 +1430,7 @@ export function ScheduleCalendarWorkspace({
|
||||
window.removeEventListener("pointerup", handleUp);
|
||||
window.removeEventListener("pointercancel", handleCancel);
|
||||
};
|
||||
}, [dragState, viewMode, visibleDateKeys, displayOffset, serverOffset, onQuickUpdateSchedule, hourHeight]);
|
||||
}, [dragState, viewMode, visibleDateKeys, displayOffset, serverOffset, onQuickUpdateSchedule]);
|
||||
// Keep selectedOccurrence synced if schedule refreshes.
|
||||
const activeSelectedSchedule = React.useMemo(() => {
|
||||
if (!selectedOccurrence) return null;
|
||||
@@ -2004,7 +1983,12 @@ export function ScheduleCalendarWorkspace({
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 rounded-md px-3 text-xs font-medium"
|
||||
onClick={() => jumpToDateKey(todayKey)}
|
||||
onClick={() => {
|
||||
jumpToDateKey(todayKey);
|
||||
if (viewMode === "day" || viewMode === "week") {
|
||||
scrollToCurrentHour(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{translate("schedule.calendar.today")}
|
||||
</Button>
|
||||
@@ -2165,36 +2149,6 @@ export function ScheduleCalendarWorkspace({
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
{/* Auto-fit vs Expanded grid height toggle (Day/Week views) */}
|
||||
{viewMode === "day" || viewMode === "week" ? (
|
||||
<div className="flex items-center rounded-full border bg-muted/40 p-0.5 text-[11px]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setGridDensity("fit")}
|
||||
className={cn(
|
||||
"rounded-full px-2 py-1 font-medium transition-colors",
|
||||
gridDensity === "fit"
|
||||
? "bg-background text-foreground shadow-xs"
|
||||
: "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{translate("schedule.calendar.densityFit")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setGridDensity("comfortable")}
|
||||
className={cn(
|
||||
"rounded-full px-2 py-1 font-medium transition-colors",
|
||||
gridDensity === "comfortable"
|
||||
? "bg-background text-foreground shadow-xs"
|
||||
: "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{translate("schedule.calendar.densityExpand")}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* View mode segmented control */}
|
||||
<div className="flex items-center rounded-full border bg-muted/40 p-0.5 text-xs">
|
||||
{(["day", "week", "month", "year", "list"] as CalendarViewMode[]).map((mode) => (
|
||||
@@ -2634,7 +2588,7 @@ export function ScheduleCalendarWorkspace({
|
||||
<div
|
||||
className="relative grid"
|
||||
style={{
|
||||
height: `${24 * hourHeight}px`,
|
||||
height: `${24 * HOUR_HEIGHT}px`,
|
||||
gridTemplateColumns: `64px minmax(0, 1fr)`,
|
||||
}}
|
||||
>
|
||||
@@ -2644,11 +2598,9 @@ export function ScheduleCalendarWorkspace({
|
||||
<div
|
||||
key={hour}
|
||||
className="relative pr-1.5 text-right font-mono text-[10px] text-muted-foreground"
|
||||
style={{ height: `${hourHeight}px` }}
|
||||
style={{ height: `${HOUR_HEIGHT}px` }}
|
||||
>
|
||||
{hour > 0 && (hourHeight >= 25 || hour % 2 === 0) ? (
|
||||
<span className="relative -top-2">{formatHourGutter(hour, isEn)}</span>
|
||||
) : null}
|
||||
{hour > 0 ? <span className="relative -top-2">{formatHourGutter(hour, isEn)}</span> : null}
|
||||
</div>
|
||||
))}
|
||||
{/* Red Current-Time Pill on Gutter */}
|
||||
@@ -2656,7 +2608,7 @@ export function ScheduleCalendarWorkspace({
|
||||
<div
|
||||
title={translate("schedule.calendar.currentTimeTooltip", { time: liveClockStr })}
|
||||
className="pointer-events-none absolute inset-x-1 z-20 -translate-y-1/2 rounded-full bg-rose-500 px-1 py-px text-center font-mono text-[9px] font-semibold text-white shadow-xs"
|
||||
style={{ top: `${(nowMinutes / 60) * hourHeight}px` }}
|
||||
style={{ top: `${(nowMinutes / 60) * HOUR_HEIGHT}px` }}
|
||||
>
|
||||
{liveClockStr}
|
||||
</div>
|
||||
@@ -2690,7 +2642,7 @@ export function ScheduleCalendarWorkspace({
|
||||
onCreateAtSlot(dk, hour * 60, Math.min(1440, (hour + 1) * 60));
|
||||
}}
|
||||
className="cursor-crosshair border-b border-border/50 transition-colors hover:bg-blue-50/40 dark:hover:bg-blue-950/20"
|
||||
style={{ height: `${hourHeight}px` }}
|
||||
style={{ height: `${HOUR_HEIGHT}px` }}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -2699,7 +2651,7 @@ export function ScheduleCalendarWorkspace({
|
||||
<div
|
||||
title={translate("schedule.calendar.currentTimeTooltip", { time: liveClockStr })}
|
||||
className="pointer-events-none absolute inset-x-0 z-20 flex items-center"
|
||||
style={{ top: `${(nowMinutes / 60) * hourHeight}px` }}
|
||||
style={{ top: `${(nowMinutes / 60) * HOUR_HEIGHT}px` }}
|
||||
>
|
||||
<span className="-ml-1 size-2 rounded-full bg-rose-500" />
|
||||
<div className="h-[1.5px] flex-1 bg-rose-500" />
|
||||
@@ -2714,8 +2666,8 @@ export function ScheduleCalendarWorkspace({
|
||||
}
|
||||
const startM = isBeingDragged ? dragState.previewStartMin : ev.startMin;
|
||||
const endM = isBeingDragged ? dragState.previewEndMin : ev.endMin;
|
||||
const topPx = (startM / 60) * hourHeight;
|
||||
const baseHeightPx = Math.max(22, ((endM - startM) / 60) * hourHeight - 2);
|
||||
const topPx = (startM / 60) * HOUR_HEIGHT;
|
||||
const baseHeightPx = Math.max(22, ((endM - startM) / 60) * HOUR_HEIGHT - 2);
|
||||
const widthPct = 100 / ev.colCount;
|
||||
const leftPct = ev.col * widthPct;
|
||||
const st = STATUS_STYLE[ev.schedule.status] ?? STATUS_STYLE.waiting;
|
||||
@@ -2732,7 +2684,7 @@ export function ScheduleCalendarWorkspace({
|
||||
? Math.max(0, Math.min(180, -expandDrag.deltaY))
|
||||
: 0;
|
||||
const showInlineDetails = isExpanded || pullExtra >= 18;
|
||||
const nearGridBottom = topPx + 220 > 24 * hourHeight;
|
||||
const nearGridBottom = topPx + 220 > 24 * HOUR_HEIGHT;
|
||||
const cardHeightPx = isPullingThis
|
||||
? expandDrag.wasExpanded
|
||||
? Math.max(baseHeightPx, 210 - pullShrink)
|
||||
@@ -3022,8 +2974,8 @@ export function ScheduleCalendarWorkspace({
|
||||
dragState.occurrence.dateKey !== dk ? (
|
||||
<div
|
||||
style={{
|
||||
top: `${(dragState.previewStartMin / 60) * hourHeight}px`,
|
||||
height: `${Math.max(20, ((dragState.previewEndMin - dragState.previewStartMin) / 60) * hourHeight - 2)}px`,
|
||||
top: `${(dragState.previewStartMin / 60) * HOUR_HEIGHT}px`,
|
||||
height: `${Math.max(20, ((dragState.previewEndMin - dragState.previewStartMin) / 60) * HOUR_HEIGHT - 2)}px`,
|
||||
}}
|
||||
className={cn(
|
||||
"pointer-events-none absolute inset-x-1 z-30 overflow-hidden rounded-md border px-2 py-1 shadow-lg",
|
||||
|
||||
@@ -275,8 +275,6 @@ export const scheduleMessages = {
|
||||
"schedule.calendar.weekdayShort.5": ["五", "F"],
|
||||
"schedule.calendar.weekdayShort.6": ["六", "S"],
|
||||
"schedule.calendar.weekdayShort.7": ["日", "S"],
|
||||
"schedule.calendar.densityFit": ["自适应", "Fit"],
|
||||
"schedule.calendar.densityExpand": ["展开", "Expand"],
|
||||
"schedule.calendar.currentTimeTooltip": ["当前服务器时间 {{time}}", "Current time {{time}}"],
|
||||
"schedule.calendar.dayEventCount": ["当日 {{count}} 个计划", "{{count}} schedule(s) on this day"],
|
||||
"schedule.calendar.allDayShort": ["全天", "All day"],
|
||||
|
||||
Reference in new issue
Block a user