From de43eb05d2e43ab31effce3dcca62ad91a556b26 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 5 Oct 2025 16:42:02 -0700 Subject: Init --- src/App.tsx | 62 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 18 deletions(-) (limited to 'src/App.tsx') diff --git a/src/App.tsx b/src/App.tsx index c50d1fc..dd3d76d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,28 +2,54 @@ import { useEffect, useState } from 'react'; import { ChooseArt } from '@/pages/ChooseArt'; import { Paint } from '@/pages/Paint'; +import { LoadScreen } from '@/components/LoadScreen'; -import { gridFromAscii } from '@/utils/grid'; - -const butterfly = `| | -| ⠀⠀⠀⠀⊹ | -| ⢶⢻⣑⣒⢤⡀⠀⢄⠀⠀⡠⠀⢀⡤⣆⣊⡿⡷ | -| ⠀⠹⠹⣚⣣⠻⣦⡀⠀⠀⢀⣴⠟⣸⢓⢎⠏⠀ | -| ⠀⠀⢡⣱⣖⣢⡾⢿⣾⣷⡿⢷⣖⣒⣎⡎⠀⠀ | -| ⠀⠀⠀⣠⠓⢬⠅⡺⢻⡟⢗⠨⡥⠚⣄⠀⠀⠀ | -| ⠀⠀⠀⣿⡆⠘⠆⢇⢸⡇⠸⠰⠃⢰⣿⠀⠀⠀ | -| ⠀⠀⠀⠐⡻⣮⣬⠞⠈⠁⠳⣤⣴⢿⠂⠀⠀⠀ | -| ⠀⠀⠀⡜⠀⠁⠉⠀⠀⠀⠀⠈⠈⠀⢣⠀⠀⠀ | -| ⊹ | -| |`; +import { gridFromAscii, gridFromAnsi } from '@/utils/grid'; +import type { Grid } from '@/types/grid'; export const App: React.FC = () => { - // const [chosenArt, setChosenArt] = useState(undefined); - const [chosenArt, setChosenArt] = useState(butterfly); + const [route, setRoute] = useState(window.location.hash || '#home'); + const [chosenArt, setChosenArt] = useState(null); + const [loadedGrid, setLoadedGrid] = useState(null); + + useEffect(() => { + const handleHashChange = () => { + setRoute(window.location.hash || '#home'); + }; + window.addEventListener('hashchange', handleHashChange); + return () => window.removeEventListener('hashchange', handleHashChange); + }, []); + + const handleLoad = (grid: Grid) => { + setLoadedGrid(grid); + window.location.hash = '#paint'; + }; + + const handleNew = () => { + setChosenArt(''); + window.location.hash = '#paint'; + }; + + const handlePaste = (ansiText: string) => { + const importedGrid = gridFromAnsi(ansiText); + setLoadedGrid(importedGrid); + window.location.hash = '#paint'; + }; + + const handleGoHome = () => { + setLoadedGrid(null); + setChosenArt(null); + window.location.hash = '#home'; + }; - if (chosenArt !== undefined) { - return ; + if (route === '#paint') { + if (loadedGrid !== null) { + return ; + } + if (chosenArt !== null) { + return ; + } } - return ; + return ; }; -- cgit v1.2.3-70-g09d2