This commit is contained in:
michael committed 2026-09-21 09:46:53 +00:00
1 parent 904b123884
commit 89429c70cf
2 files changed
+14 -12

No files matched your search

+13 -11
View File
@@ -99,6 +99,8 @@ type DashboardNote = {
const dashboardPreferenceVersion = 3; const dashboardPreferenceVersion = 3;
const rowHeight = 48; const rowHeight = 48;
const gridColumns = 12; const gridColumns = 12;
const maxWidgetHeight = 40;
const maxWidgetY = 120;
const widgetDefinitions: WidgetDefinition[] = [ const widgetDefinitions: WidgetDefinition[] = [
{ type: "dayControl", title: "Tagessteuerung", defaultSize: { w: 6, h: 5 }, minSize: { w: 4, h: 4 }, fixed: true }, { type: "dayControl", title: "Tagessteuerung", defaultSize: { w: 6, h: 5 }, minSize: { w: 4, h: 4 }, fixed: true },
@@ -278,9 +280,9 @@ function normalizePreference(preference: Partial<DashboardPreference>): Dashboar
type: widget.type, type: widget.type,
title: typeof widget.title === "string" ? widget.title : widgetTitle(widget.type), title: typeof widget.title === "string" ? widget.title : widgetTitle(widget.type),
x: clampNumber(widget.x, 0, gridColumns - 1), x: clampNumber(widget.x, 0, gridColumns - 1),
y: clampNumber(widget.y, 0, 30), y: clampNumber(widget.y, 0, maxWidgetY),
w: clampNumber(widget.w, widgetMinSize(widget.type).w, gridColumns), w: clampNumber(widget.w, widgetMinSize(widget.type).w, gridColumns),
h: clampNumber(widget.h, widgetMinSize(widget.type).h, 8), h: clampNumber(widget.h, widgetMinSize(widget.type).h, maxWidgetHeight),
config: normalizeWidgetConfig(widget.type, widget.config) config: normalizeWidgetConfig(widget.type, widget.config)
})) }))
.reduce<DashboardWidget[]>((placed, widget) => [...placed, resolveWidgetPlacement(placed, widget)], []); .reduce<DashboardWidget[]>((placed, widget) => [...placed, resolveWidgetPlacement(placed, widget)], []);
@@ -332,14 +334,14 @@ function columnsOverlap(left: DashboardWidget, right: DashboardWidget) {
function normalizeWidgetPlacement(changed: DashboardWidget) { function normalizeWidgetPlacement(changed: DashboardWidget) {
const minSize = widgetMinSize(changed.type); const minSize = widgetMinSize(changed.type);
const w = clampNumber(changed.w, minSize.w, gridColumns); const w = clampNumber(changed.w, minSize.w, gridColumns);
const h = clampNumber(changed.h, minSize.h, 8); const h = clampNumber(changed.h, minSize.h, maxWidgetHeight);
return { return {
...changed, ...changed,
w, w,
h, h,
x: clampNumber(changed.x, 0, gridColumns - w), x: clampNumber(changed.x, 0, gridColumns - w),
y: clampNumber(changed.y, 0, 80) y: clampNumber(changed.y, 0, maxWidgetY)
}; };
} }
@@ -352,7 +354,7 @@ function resolveWidgetPlacement(widgets: DashboardWidget[], changed: DashboardWi
return next; return next;
} }
const maxExistingRow = Math.max(80, ...widgets.filter((widget) => widget.id !== next.id).map((widget) => widget.y + widget.h + next.h)); const maxExistingRow = Math.max(maxWidgetY, ...widgets.filter((widget) => widget.id !== next.id).map((widget) => widget.y + widget.h + next.h));
for (let distance = 1; distance <= maxExistingRow + next.h; distance += 1) { for (let distance = 1; distance <= maxExistingRow + next.h; distance += 1) {
const yAbove = next.y - distance; const yAbove = next.y - distance;
@@ -367,7 +369,7 @@ function resolveWidgetPlacement(widgets: DashboardWidget[], changed: DashboardWi
} }
} }
return { ...next, y: maxExistingRow + h }; return { ...next, y: maxExistingRow + next.h };
} }
function moveCollidingWidgetsDown(widgets: DashboardWidget[], lockedWidgetId: string) { function moveCollidingWidgetsDown(widgets: DashboardWidget[], lockedWidgetId: string) {
@@ -462,7 +464,7 @@ function placeWidget(widgets: DashboardWidget[], changed: DashboardWidget) {
return layoutWidgetsWithPlacement(widgets, changed); return layoutWidgetsWithPlacement(widgets, changed);
} }
function widgetPlacementFromPoint(gridElement: HTMLDivElement, widgets: DashboardWidget[], widget: DashboardWidget, clientX: number, clientY: number) { function widgetPlacementFromPoint(gridElement: HTMLDivElement, widget: DashboardWidget, clientX: number, clientY: number) {
const rect = gridElement.getBoundingClientRect(); const rect = gridElement.getBoundingClientRect();
const styles = window.getComputedStyle(gridElement); const styles = window.getComputedStyle(gridElement);
const columnGap = Number.parseFloat(styles.columnGap) || 0; const columnGap = Number.parseFloat(styles.columnGap) || 0;
@@ -473,7 +475,7 @@ function widgetPlacementFromPoint(gridElement: HTMLDivElement, widgets: Dashboar
return normalizeWidgetPlacement({ return normalizeWidgetPlacement({
...widget, ...widget,
x: clampNumber(Math.floor((clientX - rect.left) / columnStep), 0, gridColumns - widget.w), x: clampNumber(Math.floor((clientX - rect.left) / columnStep), 0, gridColumns - widget.w),
y: clampNumber(Math.floor((clientY - rect.top) / rowStep), 0, 80) y: clampNumber(Math.floor((clientY - rect.top) / rowStep), 0, maxWidgetY)
}); });
} }
@@ -1122,7 +1124,7 @@ export function DashboardPage({ onNavigate }: DashboardPageProps) {
const next = dragPreview?.id === widget.id const next = dragPreview?.id === widget.id
? dragPreview ? dragPreview
: widgetPlacementFromPoint(gridRef.current, preference.widgets, widget, clientX, clientY); : widgetPlacementFromPoint(gridRef.current, widget, clientX, clientY);
setPreference((current) => ({ setPreference((current) => ({
...current, ...current,
@@ -1143,7 +1145,7 @@ export function DashboardPage({ onNavigate }: DashboardPageProps) {
return; return;
} }
setDragPreview(widgetPlacementFromPoint(gridRef.current, preference.widgets, widget, clientX, clientY)); setDragPreview(widgetPlacementFromPoint(gridRef.current, widget, clientX, clientY));
} }
function startResize(event: PointerEvent<HTMLButtonElement>, widget: DashboardWidget) { function startResize(event: PointerEvent<HTMLButtonElement>, widget: DashboardWidget) {
@@ -1161,7 +1163,7 @@ export function DashboardPage({ onNavigate }: DashboardPageProps) {
function onMove(moveEvent: globalThis.PointerEvent) { function onMove(moveEvent: globalThis.PointerEvent) {
updateWidget(widget.id, { updateWidget(widget.id, {
w: clampNumber(startW + Math.round((moveEvent.clientX - startX) / columnWidth), minSize.w, gridColumns - widget.x), w: clampNumber(startW + Math.round((moveEvent.clientX - startX) / columnWidth), minSize.w, gridColumns - widget.x),
h: clampNumber(startH + Math.round((moveEvent.clientY - startY) / rowHeight), minSize.h, 8) h: clampNumber(startH + Math.round((moveEvent.clientY - startY) / rowHeight), minSize.h, maxWidgetHeight)
}); });
} }
+1 -1
View File
@@ -21,7 +21,7 @@ export function LoginPage({ onLogin }: LoginPageProps) {
setLoading(true); setLoading(true);
try { try {
const result = await login({ username, password }); const result = await login({ username: username.trim(), password });
onLogin(result.user); onLogin(result.user);
} catch (error) { } catch (error) {
toast.error("Login fehlgeschlagen", { toast.error("Login fehlgeschlagen", {