From ecf8f9d01ad15e060614ae5aaa41dd8594f5afe9 Mon Sep 17 00:00:00 2001 From: Behnam Date: Thu, 25 Dec 2025 17:28:40 +0000 Subject: [PATCH] refactor: extract magic strings to centralized constants file - Create src/lib/constants.ts with all magic strings: - STORAGE_KEYS for localStorage keys - PNG_WORKFLOW_KEY for workflow metadata - NODE_PATHS for all node type paths - DRAG_DATA_TYPES for drag-and-drop data transfer - SIZE_LIMITS for file size thresholds - ERROR_MESSAGES with factory functions - MIME_TYPES and image format helpers - ASPECT_RATIOS and model name constants - Update 12 files to use centralized constants: - workflow-storage.ts - useClipboard.ts - png-metadata.ts - graph-executor.ts - WorkflowCanvas.tsx - ContextMenu.tsx - ImageHistory.tsx - SettingsDialog.tsx - ErrorBoundary.tsx - ImageHistoryContext.tsx - prompt-templates.ts - Test files - Fix lint errors in test files (unused variables, empty blocks) Co-Authored-By: Behnam & Claude Code --- src/components/ContextMenu.tsx | 13 +- src/components/ErrorBoundary.tsx | 3 +- src/components/ImageHistory.tsx | 7 +- src/components/SettingsDialog.tsx | 12 +- src/components/WorkflowCanvas.tsx | 7 +- src/context/ImageHistoryContext.tsx | 8 +- src/hooks/useClipboard.ts | 7 +- src/lib/constants.ts | 189 ++++++++++++++++++++++++++++ src/lib/graph-executor.test.ts | 30 ++--- src/lib/graph-executor.ts | 5 +- src/lib/png-metadata.ts | 7 +- src/lib/prompt-templates.ts | 8 +- src/lib/workflow-storage.test.ts | 5 +- src/lib/workflow-storage.ts | 42 +++---- 14 files changed, 269 insertions(+), 74 deletions(-) create mode 100644 src/lib/constants.ts diff --git a/src/components/ContextMenu.tsx b/src/components/ContextMenu.tsx index 6f0a108..0de8940 100644 --- a/src/components/ContextMenu.tsx +++ b/src/components/ContextMenu.tsx @@ -1,4 +1,5 @@ import { useState, useEffect, useCallback, useRef, type ReactNode } from 'react' +import { NODE_PATHS } from '../lib/constants' interface ContextMenuItem { id: string @@ -309,14 +310,14 @@ export function getCanvasContextMenuItems(options: { id: 'add-node', label: 'Add Node', submenu: [ - { id: 'add-prompt', label: 'Prompt', onClick: () => options.onAddNode?.('input/prompt') }, - { id: 'add-image', label: 'Image Source', onClick: () => options.onAddNode?.('input/image') }, - { id: 'add-seed', label: 'Seed', onClick: () => options.onAddNode?.('input/seed') }, + { id: 'add-prompt', label: 'Prompt', onClick: () => options.onAddNode?.(NODE_PATHS.PROMPT) }, + { id: 'add-image', label: 'Image Source', onClick: () => options.onAddNode?.(NODE_PATHS.IMAGE_SOURCE) }, + { id: 'add-seed', label: 'Seed', onClick: () => options.onAddNode?.(NODE_PATHS.SEED) }, { id: 'sep', label: '', separator: true }, - { id: 'add-fal', label: 'Fal Flux', onClick: () => options.onAddNode?.('generation/fal-flux') }, - { id: 'add-gemini', label: 'Gemini', onClick: () => options.onAddNode?.('generation/gemini') }, + { id: 'add-fal', label: 'Fal Flux', onClick: () => options.onAddNode?.(NODE_PATHS.FAL_FLUX) }, + { id: 'add-gemini', label: 'Gemini', onClick: () => options.onAddNode?.(NODE_PATHS.GEMINI) }, { id: 'sep2', label: '', separator: true }, - { id: 'add-output', label: 'Image Output', onClick: () => options.onAddNode?.('output/image') }, + { id: 'add-output', label: 'Image Output', onClick: () => options.onAddNode?.(NODE_PATHS.IMAGE_OUTPUT) }, ], }, ] diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index c957a89..bc1567c 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -1,4 +1,5 @@ import { Component, type ReactNode, type ErrorInfo } from 'react' +import { STORAGE_KEYS } from '../lib/constants' interface Props { children: ReactNode @@ -114,7 +115,7 @@ export class CanvasErrorBoundary extends ErrorBoundary {