1
1
import "./App.css" ;
2
- import { maxGuesses , seed } from "./util" ;
2
+ import { maxGuesses , seed , urlParam } from "./util" ;
3
3
import Game from "./Game" ;
4
4
import { useEffect , useState } from "react" ;
5
5
import { About } from "./About" ;
@@ -26,6 +26,8 @@ function useSetting<T>(
26
26
return [ current , setSetting ] ;
27
27
}
28
28
29
+ const todaySeed = new Date ( ) . toISOString ( ) . replace ( / - / g, "" ) . slice ( 0 , 8 ) ;
30
+
29
31
function App ( ) {
30
32
type Page = "game" | "about" | "settings" ;
31
33
const [ page , setPage ] = useState < Page > ( "game" ) ;
@@ -43,22 +45,24 @@ function App() {
43
45
44
46
useEffect ( ( ) => {
45
47
document . body . className = dark ? "dark" : "" ;
48
+ if ( urlParam ( "today" ) !== null || urlParam ( "todas" ) !== null ) {
49
+ document . location = "?seed=" + todaySeed ;
50
+ }
46
51
setTimeout ( ( ) => {
47
52
// Avoid transition on page load
48
53
document . body . style . transition = "0.3s background-color ease-out" ;
49
54
} , 1 ) ;
50
55
} , [ dark ] ) ;
51
56
52
57
const link = ( emoji : string , label : string , page : Page ) => (
53
- < a
58
+ < button
54
59
className = "emoji-link"
55
- href = "#"
56
60
onClick = { ( ) => setPage ( page ) }
57
61
title = { label }
58
62
aria-label = { label }
59
63
>
60
64
{ emoji }
61
- </ a >
65
+ </ button >
62
66
) ;
63
67
64
68
return (
@@ -92,15 +96,7 @@ function App() {
92
96
visibility : page === "game" ? "visible" : "hidden" ,
93
97
} }
94
98
>
95
- < a
96
- href = "#"
97
- onClick = { ( ) =>
98
- ( document . location = seed
99
- ? "?"
100
- : "?seed=" +
101
- new Date ( ) . toISOString ( ) . replace ( / - / g, "" ) . slice ( 0 , 8 ) )
102
- }
103
- >
99
+ < a href = { seed ? "?random" : "?seed=" + todaySeed } >
104
100
{ seed ? "Random" : "Today's" }
105
101
</ a >
106
102
</ div >
0 commit comments