1+ import styles from 'app/App.module.css'
2+ import { DaySelector } from 'app/DaySelector'
13import { Editor } from 'app/Editor'
4+ import { EyeIcon , EyeOffIcon , LockIcon , UnLockIcon } from 'app/FeatherIcons'
5+ import { Footer } from 'app/Footer'
6+ import formStyles from 'app/Form.module.css'
27import { Schedule } from 'app/Schedule'
3- import { ThemeSwitcher } from 'app/ThemeSwitcher'
8+ import { Theme , ThemeSwitcher } from 'app/ThemeSwitcher'
9+ import { TimeZoneSelector } from 'app/timezones'
410import { format } from 'date-fns'
5- import { useState } from 'react'
6- import { EyeIcon , EyeOffIcon , LockIcon , UnLockIcon } from 'style/FeatherIcons'
7- import { Footer } from 'style/Footer'
8- import {
9- Button ,
10- DateEditor ,
11- Input ,
12- StyledDaySelector ,
13- StyledTimeZoneSelector ,
14- } from 'style/Form'
15- import { GlobalStyle } from 'style/Global'
16- import { Headline , Info , Main , Title , TitleActions } from 'style/Main'
17- import { dark , light , Theme } from 'style/theme'
18- import { ThemeProvider } from 'styled-components'
11+ import { useEffect , useState } from 'react'
12+
13+ let defaultTheme = Theme . light
14+ if ( typeof window . matchMedia === 'function' ) {
15+ const match = window . matchMedia ( '(prefers-color-scheme: dark)' )
16+ defaultTheme = match . matches ? Theme . dark : Theme . light
17+ }
1918
2019export const App = ( ) => {
2120 let cfg = {
@@ -57,7 +56,9 @@ export const App = () => {
5756 }
5857 }
5958 const [ theme , updateTheme ] = useState < Theme > (
60- window . localStorage . getItem ( 'theme' ) === 'light' ? light : dark ,
59+ ( window . localStorage . getItem ( 'theme' ) ?? defaultTheme ) === 'dark'
60+ ? Theme . dark
61+ : Theme . light ,
6162 )
6263 const [ updatedName , updateName ] = useState ( cfg . name )
6364 const [ updatedDay , updateDay ] = useState ( cfg . day )
@@ -67,14 +68,19 @@ export const App = () => {
6768 const [ hidePastSessions , setHidePastSessions ] = useState (
6869 hidePastSessionsDefault ,
6970 )
71+
72+ useEffect ( ( ) => {
73+ document . documentElement . setAttribute ( 'data-theme' , theme )
74+ } , [ theme ] )
75+
7076 return (
71- < ThemeProvider theme = { theme } >
72- < GlobalStyle />
73- < Main >
77+ < >
78+ < main >
7479 { editing && (
7580 < >
76- < Title >
77- < Button
81+ < div className = { styles . Title } >
82+ < button
83+ className = { formStyles . Button }
7884 title = "Save changes"
7985 onClick = { ( ) => {
8086 const cfg = {
@@ -92,26 +98,22 @@ export const App = () => {
9298 } }
9399 >
94100 < UnLockIcon />
95- </ Button >
96- < DateEditor >
97- < Input
101+ </ button >
102+ < div className = { formStyles . DateEditor } >
103+ < input
104+ className = { formStyles . Input }
98105 type = "text"
99106 value = { updatedName }
100107 onChange = { ( { target : { value } } ) => updateName ( value ) }
101108 />
102- < StyledDaySelector day = { updatedDay } onUpdate = { updateDay } />
103- < StyledTimeZoneSelector
109+ < DaySelector day = { updatedDay } onUpdate = { updateDay } />
110+ < TimeZoneSelector
104111 value = { updatedTimeZone }
105112 onChange = { ( { target : { value } } ) => updateTimeZone ( value ) }
106113 />
107- </ DateEditor >
108- < ThemeSwitcher
109- currentTheme = { theme }
110- darkTheme = { dark }
111- lightTheme = { light }
112- onSwitch = { updateTheme }
113- />
114- </ Title >
114+ </ div >
115+ < ThemeSwitcher currentTheme = { theme } onSwitch = { updateTheme } />
116+ </ div >
115117 < Editor
116118 onAdd = { ( add ) => {
117119 updateSessions ( ( sessions ) => ( {
@@ -134,34 +136,31 @@ export const App = () => {
134136 ) }
135137 { ! editing && (
136138 < >
137- < Title >
138- < Button
139+ < div className = { styles . Title } >
140+ < button
141+ className = { formStyles . Button }
139142 title = "Edit schedule"
140143 onClick = { ( ) => {
141144 setEditing ( true )
142145 } }
143146 >
144147 < LockIcon />
145- </ Button >
146- < Headline >
148+ </ button >
149+ < h1 className = { styles . Headline } >
147150 { updatedName } : { updatedDay }
148- </ Headline >
149- < TitleActions >
150- < Button
151+ </ h1 >
152+ < div className = "actions" >
153+ < button
154+ className = { formStyles . Button }
151155 title = "Hide past sessions"
152156 onClick = { ( ) => setHidePastSessions ( ( h ) => ! h ) }
153157 >
154158 { hidePastSessions && < EyeOffIcon /> }
155159 { ! hidePastSessions && < EyeIcon /> }
156- </ Button >
157- < ThemeSwitcher
158- currentTheme = { theme }
159- darkTheme = { dark }
160- lightTheme = { light }
161- onSwitch = { updateTheme }
162- />
163- </ TitleActions >
164- </ Title >
160+ </ button >
161+ < ThemeSwitcher currentTheme = { theme } onSwitch = { updateTheme } />
162+ </ div >
163+ </ div >
165164 < Schedule
166165 sessions = { cfg . sessions }
167166 eventTimezoneName = { cfg . tz }
@@ -170,7 +169,7 @@ export const App = () => {
170169 />
171170 </ >
172171 ) }
173- < Info >
172+ < div className = { styles . Info } >
174173 < p >
175174 Click the < LockIcon /> icon to create your own schedule. When done,
176175 click the < UnLockIcon /> and share the updated URL.
@@ -186,9 +185,9 @@ export const App = () => {
186185 </ a > { ' ' }
187186 to embed it on any page.
188187 </ p >
189- </ Info >
190- </ Main >
188+ </ div >
189+ </ main >
191190 < Footer />
192- </ ThemeProvider >
191+ </ >
193192 )
194193}
0 commit comments