From 814504db8c65eab7f08872e6d7abf8bf14b97895 Mon Sep 17 00:00:00 2001 From: M1ngdaXie <156019134+M1ngdaXie@users.noreply.github.com> Date: Thu, 26 Mar 2026 14:14:31 -0700 Subject: [PATCH] refactor: extract layout constants to avoid magic numbers --- src/config/layout.ts | 2 ++ src/context/WindowContext.tsx | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 src/config/layout.ts diff --git a/src/config/layout.ts b/src/config/layout.ts new file mode 100644 index 0000000..615a1f4 --- /dev/null +++ b/src/config/layout.ts @@ -0,0 +1,2 @@ +export const MENUBAR_HEIGHT = 28; +export const DOCK_HEIGHT = 72; diff --git a/src/context/WindowContext.tsx b/src/context/WindowContext.tsx index ea90cc1..53c1245 100644 --- a/src/context/WindowContext.tsx +++ b/src/context/WindowContext.tsx @@ -1,6 +1,7 @@ import React, { createContext, useContext, useReducer, useCallback } from 'react'; import type { OSState, OSAction, WindowState } from '../types'; import { APPS } from '../config/apps'; +import { MENUBAR_HEIGHT, DOCK_HEIGHT } from '../config/layout'; function initWindows(): Record { const map: Record = {}; @@ -85,9 +86,9 @@ function reducer(state: OSState, action: OSAction): OSState { isMaximized: true, prevPosition: { ...win.position }, prevSize: { ...win.size }, - position: { x: 0, y: 28 }, // 28px = menubar height + position: { x: 0, y: MENUBAR_HEIGHT }, // viewport dims passed in from caller — keeps reducer pure - size: { width: action.viewportWidth, height: action.viewportHeight - 28 - 72 }, + size: { width: action.viewportWidth, height: action.viewportHeight - MENUBAR_HEIGHT - DOCK_HEIGHT }, }, }, };