Skip to content

Commit 11039e8

Browse files
committed
refactor: Convert Sorting and Recursive Sorting to functional components
Sorting: menu with useState for compareMode, page with useRef for speed and dual running state tracking via refs. Recursive Sorting: rect, menu, page converted. Three async animation handlers (merge, heap, quick) use speedRef and countRef. Also fixes CustomSlider to accept disabled prop alongside disable/isDisabled.
1 parent b01f868 commit 11039e8

8 files changed

Lines changed: 392 additions & 527 deletions

File tree

src/app/recursive-sorting/menu.jsx

Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,73 @@ import { CustomSelect } from '@/components/custom-select';
22
import { CustomSlider } from '@/components/custom-slider';
33
import { Button } from '@/components/ui/button';
44
import { Play, Shuffle } from 'lucide-react';
5-
import { Component } from 'react';
65

7-
class Menu extends Component {
8-
render() {
9-
const disabled = this.props.disable;
10-
return (
11-
<div className="w-64 bg-gray-100 p-4 space-y-6">
12-
<h2 className="text-lg font-semibold">Recursive Sorting</h2>
6+
export default function Menu({ disabled, onViusalize, onRandomize, onCountChange, onAlgoChanged, onSpeedChange }) {
7+
return (
8+
<div className="w-64 bg-gray-100 p-4 space-y-6">
9+
<h2 className="text-lg font-semibold">Recursive Sorting</h2>
1310

14-
<div className="space-y-3">
15-
<div className="flex items-center gap-2">
16-
<div className="h-px flex-1 bg-gray-300" />
17-
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Config</span>
18-
<div className="h-px flex-1 bg-gray-300" />
19-
</div>
20-
<CustomSlider
21-
title="Numbers"
22-
defaultValue={20}
23-
min={10}
24-
max={100}
25-
step={10}
26-
onChange={this.props.onCountChange}
27-
disable={disabled}
28-
/>
29-
<CustomSlider
30-
title="Speed"
31-
defaultValue={50}
32-
min={10}
33-
max={100}
34-
step={1}
35-
onChange={this.props.onSpeedChange}
36-
/>
11+
<div className="space-y-3">
12+
<div className="flex items-center gap-2">
13+
<div className="h-px flex-1 bg-gray-300" />
14+
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Config</span>
15+
<div className="h-px flex-1 bg-gray-300" />
3716
</div>
17+
<CustomSlider
18+
title="Numbers"
19+
defaultValue={20}
20+
min={10}
21+
max={100}
22+
step={10}
23+
onChange={onCountChange}
24+
disabled={disabled}
25+
/>
26+
<CustomSlider
27+
title="Speed"
28+
defaultValue={50}
29+
min={10}
30+
max={100}
31+
step={1}
32+
onChange={onSpeedChange}
33+
/>
34+
</div>
3835

39-
<div className="space-y-3">
40-
<div className="flex items-center gap-2">
41-
<div className="h-px flex-1 bg-gray-300" />
42-
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Algorithm</span>
43-
<div className="h-px flex-1 bg-gray-300" />
44-
</div>
45-
<CustomSelect
46-
title="Algorithm"
47-
options={["Merge Sort", "Heap Sort", "Quick Sort"]}
48-
onChange={this.props.onAlgoChanged}
49-
disabled={disabled}
50-
/>
36+
<div className="space-y-3">
37+
<div className="flex items-center gap-2">
38+
<div className="h-px flex-1 bg-gray-300" />
39+
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Algorithm</span>
40+
<div className="h-px flex-1 bg-gray-300" />
5141
</div>
42+
<CustomSelect
43+
title="Algorithm"
44+
options={["Merge Sort", "Heap Sort", "Quick Sort"]}
45+
onChange={onAlgoChanged}
46+
disabled={disabled}
47+
/>
48+
</div>
5249

53-
<div className="space-y-3">
54-
<div className="flex items-center gap-2">
55-
<div className="h-px flex-1 bg-gray-300" />
56-
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</span>
57-
<div className="h-px flex-1 bg-gray-300" />
58-
</div>
59-
<Button
60-
className="w-full"
61-
onClick={this.props.onViusalize}
62-
disabled={disabled}
63-
>
64-
<Play /> Visualize
65-
</Button>
66-
<Button
67-
className="w-full"
68-
variant="outline"
69-
onClick={this.props.onRandomize}
70-
disabled={disabled}
71-
>
72-
<Shuffle /> Randomize
73-
</Button>
50+
<div className="space-y-3">
51+
<div className="flex items-center gap-2">
52+
<div className="h-px flex-1 bg-gray-300" />
53+
<span className="text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</span>
54+
<div className="h-px flex-1 bg-gray-300" />
7455
</div>
56+
<Button
57+
className="w-full"
58+
onClick={onViusalize}
59+
disabled={disabled}
60+
>
61+
<Play /> Visualize
62+
</Button>
63+
<Button
64+
className="w-full"
65+
variant="outline"
66+
onClick={onRandomize}
67+
disabled={disabled}
68+
>
69+
<Shuffle /> Randomize
70+
</Button>
7571
</div>
76-
);
77-
}
72+
</div>
73+
);
7874
}
79-
80-
export default Menu;

0 commit comments

Comments
 (0)