You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Restyle recursion tree nodes and fix pathfinder visited cells
Recursion tree: replace double-border nodes with single border, drop
shadow, and three-state coloring (amber=active, teal=partial, slate=completed).
Soften edge/arrow colors to slate-500.
Pathfinder: fix bug where visited cell colors disappeared when shortest
path was animated (stale grid closure).
Update REFACTOR.md to reflect completed tasks.
@@ -4,141 +4,21 @@ A prioritized list of refactoring tasks for the Algorithm Visualizer project. Ea
4
4
5
5
---
6
6
7
-
## 1. Convert Class Components to Functional Components with Hooks
7
+
## 1. ~~Convert Class Components to Functional Components with Hooks~~ ✅
8
8
9
-
**Priority:** High
10
-
**Effort:** Large (9 page components + ~30 child components)
11
-
**Impact:** Eliminates stale state bugs, simplifies code, enables better React patterns
12
-
13
-
### Problem
14
-
15
-
All visualizer pages except Game of Life use class components. This causes subtle bugs — for example, calling `this.setState({ number })` and immediately reading `this.state.number` gives the old value because `setState` is async in class components.
setBoard(getBoard(num)); // no stale state — uses the param directly
85
-
}
86
-
87
-
conststartAlgo=async () => {
88
-
setIsRunning(true);
89
-
// use ref inside async loops so speed changes take effect mid-animation
90
-
awaitsleep(speedRef.current);
91
-
}
92
-
}
93
-
```
94
-
95
-
### Key patterns for async animations
9
+
**Status:** Done
96
10
97
-
- Use `useRef` for values read inside `async` loops (`speed`, `isRunning`) — state closures will be stale
98
-
- Game of Life (`src/app/game-of-life/page.jsx`) is already converted and serves as a reference
99
-
- Convert `componentDidMount` to `useEffect(() => { ... }, [])`
100
-
- Convert `componentDidUpdate` to `useEffect` with dependency arrays
101
-
102
-
### Recommended order
11
+
All visualizer pages and child components converted to functional components with hooks. Uses `useRef` for values read inside async animation loops (speed, isRunning, etc.) to avoid stale closures. The only remaining class component is `src/app/15-puzzle/page.jsx` (skipped intentionally).
103
12
104
-
Convert menu components first (they're simpler — mostly render-only), then child components, then page components last since they have the most logic.
13
+
Unused files removed during conversion: `convex-hull/cnvas2.jsx`, `convex-hull/timer.jsx`, `recursion-tree/details.jsx`, `recursion-tree/vertexOriginal.jsx`.
105
14
106
15
---
107
16
108
-
## 2. Standardize Disabled Prop Naming
109
-
110
-
**Priority:** High
111
-
**Effort:** Small
112
-
**Impact:** Removes confusion, prevents bugs from mismatched prop names
113
-
114
-
### Problem
115
-
116
-
Three different prop names are used for the same concept:
117
-
-`disable` — used in pathfinder, sorting, recursive-sorting, n-queen, recursion-tree, turing-machine
118
-
-`isDisabled` — used in convex-hull, prime-numbers
119
-
-`disabled` — standard HTML attribute name
120
-
121
-
The `CustomSlider` component even accepts **both**`disable` and `isDisabled` and reconciles them.
122
-
123
-
### Fix
124
-
125
-
Standardize everything to `disabled` (the HTML standard). Update:
**Page → Menu prop passing (change `disable=` and `isDisabled=` to `disabled=`):**
131
-
-`src/app/pathfinder/page.jsx`
132
-
-`src/app/sorting/page.jsx`
133
-
-`src/app/recursive-sorting/page.jsx`
134
-
-`src/app/n-queen/page.jsx`
135
-
-`src/app/convex-hull/page.jsx`
136
-
-`src/app/prime-numbers/page.jsx`
137
-
-`src/app/recursion-tree/page.jsx`
138
-
-`src/app/turing-machine/page.jsx`
139
-
140
-
**Menu components (change `this.props.disable` / `this.props.isDisabled` to `this.props.disabled`):**
141
-
- All 8 menu files listed above
21
+
All components now use `disabled` (the HTML standard). Removed `disable` and `isDisabled` variants from all pages, menus, and shared components. Added visual disabled state (opacity + pointer-events) to the Slider UI component.
142
22
143
23
---
144
24
@@ -148,19 +28,7 @@ Standardize everything to `disabled` (the HTML standard). Update:
ESLint `no-console` rule is now configured as a warning. Most console.log statements were removed during the hooks migration. Remaining ones are flagged by the linter.
164
32
165
33
---
166
34
@@ -330,65 +198,11 @@ Per-page metadata can also be added using Next.js `generateMetadata` or `metadat
330
198
331
199
---
332
200
333
-
## 10. Add ESLint
334
-
335
-
**Priority:** High
336
-
**Effort:** Small
337
-
**Impact:** Catches bugs automatically, enforces consistency, runs during `next build`
338
-
339
-
### Current state
340
-
341
-
The `package.json` has a stale `eslintConfig` block from Create React App, but ESLint is not installed. The `next build` output even warns: *"ESLint must be installed in order to run during builds"*.
342
-
343
-
### Setup
344
-
345
-
```bash
346
-
npm install -D eslint eslint-config-next
347
-
```
348
-
349
-
Then replace the CRA `eslintConfig` block in `package.json` with an `.eslintrc.json`:
-`@next/next/no-img-element` — flags `<img>` tags that should use `next/image`
378
-
-`@next/next/no-html-link-for-pages` — flags `<a>` tags that should use `next/link`
201
+
## 10. ~~Add ESLint~~ ✅
379
202
380
-
### Clean up the stale CRA config
203
+
**Status:** Done
381
204
382
-
Remove this block from `package.json`:
383
-
384
-
```json
385
-
"eslintConfig": {
386
-
"extends": [
387
-
"react-app",
388
-
"react-app/jest"
389
-
]
390
-
}
391
-
```
205
+
ESLint configured in `eslint.config.mjs` using eslint-config-next v16 native flat config. Rules: `no-console` (warn), `no-unused-vars` (warn, `_` prefix ignored), `react/no-unescaped-entities` (off). All lint errors resolved. Stale CRA `eslintConfig` removed from `package.json`. Run with `npm run lint`.
392
206
393
207
---
394
208
@@ -420,12 +234,14 @@ Rename and type one visualizer at a time, starting with the simplest (Game of Li
420
234
421
235
## Quick Wins Checklist
422
236
423
-
-[ ] Install ESLint with `next/core-web-vitals` config
424
-
-[ ] Remove stale CRA `eslintConfig` from `package.json`
425
-
-[ ] Remove 18 `console.log` statements
426
-
-[ ] Standardize `disabled` prop naming
237
+
-[x] Install ESLint with `next/core-web-vitals` config
238
+
-[x] Remove stale CRA `eslintConfig` from `package.json`
239
+
-[x] Remove unused variables and dead code
240
+
-[x] Standardize `disabled` prop naming
241
+
-[x] Add `alt="Queen"` to queen cell image
242
+
-[x] Convert class components to functional components with hooks
243
+
-[ ] Remove remaining `console.log` statements (flagged by linter)
0 commit comments