09. Refactoring Report - khalillabban/Snorting-Code GitHub Wiki

Refactoring Report

Throughout development, refactoring was performed both proactively and continuously. A significant portion of improvements were identified and addressed during pull request reviews, where code quality, maintainability, and design consistency were evaluated before merging into main. In addition to PR-based refinements, we also periodically reviewed the main branch to identify structural improvements, eliminate technical debt, and refactor opportunistically when implementing new features. This approach ensured that refactoring was not treated as a one-time activity, but as an ongoing process integrated into our workflow. # Refactoring Report

Refactor Report Format

REF-XX: [Title of Change]

Refactor

Write a single sentence summarizing the primary action of refactor issue.

What: The Change

Provide a concise technical description of the code movement or logic modification.

Why: The Rationale

Explain the business or technical pain point this refactor solves.

Refactor Commit Table

Refactoring type Commit (link to exact lines) and GitHub Refactor issue (if existed) Reason / brief explanation
Inline Function Inline function refactor Inlined a small function that was only used once to reduce indirection and improve readability.
Rename Variable Rename variable for clarity Renamed a variable to make its purpose clearer and improve understanding of the logic.
Remove Dead Code Remove unused code (diff) Removed unused or obsolete code to reduce clutter and improve maintainability.
Remove Dead Code Remove additional dead code Removed additional dead code that was unreachable or no longer relevant to any feature.
Move Function Move function to appropriate module Moved a function to a more appropriate module/class to improve cohesion and clarify responsibilities.
Introduce Assertion Introduce assertions and error handling Improved reliability and performance by validating environment variables, strengthening API error handling, safely constructing URLs, guarding against empty responses, and optimizing route decoding logic.
Replace Magic Literal Replace magic literals and improve typing Replaced raw string literals with CampusKey or "user" for focusTarget, synchronized region state with coordinates, normalized comparisons, documented zoom thresholds, and improved label rendering performance.
Decompose Conditional Simplify campus filtering logic Removed restrictive campus filtering logic so all buildings from both SGW and Loyola render simultaneously, simplifying condition complexity.
Extract Class Extract configuration and memoize handlers Centralized semester configuration and memoized handlers using useCallback to improve organization and reduce unnecessary re-renders.
Encapsulate Record Encapsulate ScheduleItem type Extracted ScheduleItem into a shared type file, creating a single source of truth and improving consistency across components.
Split Variable Introduce SerializedScheduleItem Separated runtime Date objects from storage-safe string formats using SerializedScheduleItem, ensuring safe persistence and parsing.
Remove Dead Code Remove unused useState call setSelectedBuilding Removed unused state to eliminate unnecessary re-renders and reduce component complexity.
Remove Dead Code Remove unused constant floorSummaryText Removed unused constant to clean up the codebase and improve maintainability.
Extract Method Reduce complexity of IndoorMapScreen() Broke down a large function into smaller methods to reduce cognitive complexity and improve readability.
Extract Method Converted repeated expression into a single variable Introduced new variable to replace repeating expressions to improve readability and reduce number of calculations.
Slide Statements Slide Statements - CampusMapScreen.tsx
REF-01
Reordered shuttle-related useState, useEffect, and memoized label logic to align with the component’s hook grouping and improve readability.
Move Function Move function to utils (normalizeRoomQuery)
REF-02
Moved normalizeRoomQuery from component scope into utils to keep non-component logic outside the screen file.
Extract Function Extract indoor routing helper
REF-03
Extracted indoor-routing branch logic from handleConfirmRoute into a dedicated helper and added direct tests for the helper path.
Replace Magic Literal Replace inline flex style
REF-04
Replaced top-level inline flex: 1 with a named stylesheet entry for consistency and maintainability.
Extract Variable Extract 'demoCurrentBuilding ?? autoStartBuilding'
REF-05
Extract 'demoCurrentBuilding ?? autoStartBuilding' into a single variable to improve readability and and reduce calculations.
Move Function Move IndoorMapScreen helpers
REF-06
Moved geometry and param helper functions out of IndoorMapScreen into utils to separate rendering from utility logic.
Extract Variable Extract trimParam usage
REF-07
Replaced repeated trimParam(outdoorDestBuilding) calls with derived constants to reduce duplication and improve clarity.
Extract Function Extract outdoor strategy parsing
REF-08
Extracted outdoor strategy JSON parsing into a reusable helper and added direct unit tests.
Move Function / Replace Magic Literal Refactor proximity helper
REF-09
Moved isLikelyNearOriginBuilding to utils and replaced distance magic literal with named threshold constants.
Replace Derived Variable with Query Simplify conditional rendering
REF-10
Removed showNoMapMessage and used !showFloorImageMap directly where needed.
Inline Variable Inline candidateExitOutdoor
REF-11
Inlined candidateExitOutdoor and used pendingExitOutdoor directly to remove a trivial alias.
Replace Inline Code with Function Call Normalize trim logic
REF-12
Replaced repeated inline trim expressions with trimParam(...) calls for consistency and reduced duplication.
Remove Dead Code Remove unused code Removed unused or obsolete code to reduce clutter and improve maintainability.
Remove Dead Code Remove unused useState call setSearchQuery Removed unused or obsolete code to reduce clutter and improve maintainability.
Extract Shared Module Extract building/room search logic
REF-13
Extracted building/room search logic from navigation bar to reuse for next class navigation.
Extract Variable Extract nested ternary to textColor variable
REF-15
Extracted nested ternary color logic into a textColor constant to reduce logic duplication and improve clarity across the icon and text components.
Extract Variable Replace nested ternary with IIFE for textColor assignment
REF-16
Converted the inline nested ternary operation for textColor into an Immediately Invoked Function Expression (IIFE) using explicit if statements to determine the color value.
Extract Class Extract StrategyModeSelector to eliminate duplication
REF-17
Extracted the duplicated strategy button rendering logic from both NavigationBar.tsx and NextClassDirectionsPanel.tsx into a standalone, reusable StrategyModeSelector component.
Extract Class Extract shared requireGoogleApiKey into googleEnvUtils
REF-18
Extracted shared requireGoogleApiKey utility to eliminate duplication across Google services.
Remove Dead Code Remove redundant guard clause in getMatchScore
REF-19
Removed the internal safety check for !normalizedQuery and !compactQuery within the getMatchScore helper function.
Remove Dead Code Remove dead code of unreachable statement "else { return; }"
REF-20
Removed the redundant else { return; } statement from the handleSelectRoomSuggestion callback and simplified the logic to a binary if/else structure for activeNavField.
⚠️ **GitHub.com Fallback** ⚠️