|
1 | | -import { useState, useCallback } from 'react'; |
2 | | -import { ImageUploader } from './features/1Upload/components/ImageUploader'; |
3 | | -import { StringArtCanvas } from './features/3RenderImage/components/StringArtCanvas'; |
| 1 | +import { useSelector } from 'react-redux'; |
4 | 2 | import './App.css'; |
5 | | -import StringArtConfigSection from './features/3RenderImage/components/StringArtConfig/StringArtConfigSection'; |
6 | | -import { useStringArt, type ProgressInfo } from './features/shared/hooks/useStringArt'; |
7 | | -function App() { |
8 | | - const [imageData, setImageData] = useState<Uint8Array | null>(null); |
9 | | - const [imageUrl, setImageUrl] = useState<string>(''); |
10 | | - const [isGenerating, setIsGenerating] = useState(false); |
11 | | - const [currentPath, setCurrentPath] = useState<number[]>([]); |
12 | | - const [nailCoords, setNailCoords] = useState<Array<[number, number]>>([]); |
13 | | - const [progress, setProgress] = useState<ProgressInfo | null>(null); |
14 | | - const { generateStringArt, isLoading, error, settings } = useStringArt(); |
15 | | - const handleImageSelected = useCallback((data: Uint8Array, url: string) => { |
16 | | - setImageData(data); |
17 | | - setImageUrl(url); |
18 | | - setCurrentPath([]); |
19 | | - setProgress(null); |
20 | | - setNailCoords([]); // Clear until we generate the string art |
21 | | - }, []); |
22 | | - |
23 | | - const handleStartGeneration = async () => { |
24 | | - if (!imageData) return; |
25 | | - |
26 | | - setIsGenerating(true); |
27 | | - setCurrentPath([]); |
28 | | - setProgress(null); |
29 | | - |
30 | | - try { |
31 | | - const onProgress = (progressInfo: ProgressInfo) => { |
32 | | - setProgress(progressInfo); |
33 | | - |
34 | | - // Update the path in real-time |
35 | | - setCurrentPath((prevPath) => [...prevPath, ...progressInfo.current_path]); |
36 | | - }; |
| 3 | +import { |
| 4 | + type StringArtState |
| 5 | +} from './features/shared/redux/stringArtSlice'; |
| 6 | +import UploadScreen from './features/1Upload/UploadScreen'; |
| 7 | +import RenderImageScreen from './features/3RenderImage/RenderImageScreen'; |
| 8 | +import CanvasScreen from './features/3RenderImage/CanvasScreen'; |
37 | 9 |
|
38 | | - const onNailCoords = (coords: Array<[number, number]>) => { |
39 | | - setNailCoords(coords); |
40 | | - }; |
41 | | - |
42 | | - const result = await generateStringArt(imageData, onProgress, onNailCoords); |
43 | | - if (result.path) { |
44 | | - setCurrentPath((prevPath) => [...prevPath, ...(result.path || [])]); |
45 | | - } |
46 | | - if (result.nailCoords.length > 0) { |
47 | | - setNailCoords(result.nailCoords); |
48 | | - } |
49 | | - } catch (err) { |
50 | | - console.error('Generation failed:', err); |
51 | | - alert('String art generation failed. Please try again.'); |
52 | | - } finally { |
53 | | - setIsGenerating(false); |
54 | | - } |
55 | | - }; |
| 10 | +function App() { |
| 11 | + const { |
| 12 | + imageData, |
| 13 | + isLoading, |
| 14 | + error, |
| 15 | + } = useSelector((state: { stringArt: StringArtState }) => state.stringArt); |
56 | 16 |
|
57 | 17 | if (isLoading) { |
58 | 18 | return ( |
@@ -83,56 +43,14 @@ function App() { |
83 | 43 |
|
84 | 44 | <main className="app-main"> |
85 | 45 | <div className="controls-section"> |
86 | | - <div className="upload-section"> |
87 | | - <ImageUploader |
88 | | - onImageSelected={handleImageSelected} |
89 | | - disabled={isGenerating} |
90 | | - /> |
91 | | - </div> |
| 46 | + <UploadScreen/> |
92 | 47 |
|
93 | 48 | {imageData && ( |
94 | | - <div className="generation-controls"> |
95 | | - <StringArtConfigSection key={"stringArt"} settings={settings} /> |
96 | | - |
97 | | - <button |
98 | | - onClick={handleStartGeneration} |
99 | | - disabled={isGenerating} |
100 | | - className="generate-button" |
101 | | - > |
102 | | - {isGenerating ? 'Generating...' : 'Generate String Art'} |
103 | | - </button> |
104 | | - |
105 | | - {progress && ( |
106 | | - <div className="progress-section"> |
107 | | - <div className="progress-header"> |
108 | | - <span>Progress: {progress.completion_percent.toFixed(1)}%</span> |
109 | | - <span>Lines: {progress.lines_completed}/{progress.total_lines}</span> |
110 | | - </div> |
111 | | - <div className="progress-bar"> |
112 | | - <div |
113 | | - className="progress-fill" |
114 | | - style={{ width: `${progress.completion_percent}%` }} |
115 | | - ></div> |
116 | | - </div> |
117 | | - <div className="progress-details"> |
118 | | - <span>Score: {progress.score.toFixed(1)}</span> |
119 | | - </div> |
120 | | - </div> |
121 | | - )} |
122 | | - </div> |
| 49 | + <RenderImageScreen/> |
123 | 50 | )} |
124 | 51 | </div> |
125 | 52 |
|
126 | | - <div className="canvas-section"> |
127 | | - <StringArtCanvas |
128 | | - width={500} |
129 | | - height={500} |
130 | | - nailCoords={nailCoords} |
131 | | - currentPath={currentPath} |
132 | | - isAnimating={isGenerating} |
133 | | - imageUrl={imageUrl} |
134 | | - /> |
135 | | - </div> |
| 53 | + <CanvasScreen/> |
136 | 54 | </main> |
137 | 55 | </div> |
138 | 56 | ); |
|
0 commit comments