Skip to content

Commit 608eaf7

Browse files
committed
feat: allow to hide past sessions
1 parent 6fcbfd6 commit 608eaf7

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

src/App.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import { useState } from 'react'
33
import { Footer } from './style/Footer'
4-
import { Main, Info, Headline, Title } from './style/Main'
4+
import { Main, Info, Headline, Title, TitleActions } from './style/Main'
55
import { Theme, dark, light } from './style/theme'
66
import { GlobalStyle } from './style/Global'
77
import { Schedule } from './Schedule'
@@ -13,6 +13,8 @@ import { ThemeSwitcher } from './ThemeSwitcher'
1313

1414
import LockIcon from 'feather-icons/dist/icons/lock.svg'
1515
import UnLockIcon from 'feather-icons/dist/icons/unlock.svg'
16+
import EyeOffIcon from 'feather-icons/dist/icons/eye-off.svg'
17+
import EyeIcon from 'feather-icons/dist/icons/eye.svg'
1618
import { TimeZoneSelector } from './timezones'
1719

1820
export const App = () => {
@@ -35,12 +37,16 @@ export const App = () => {
3537
1730: 'Dinner Break',
3638
1900: 'Evening Activities',
3739
},
40+
hidePastSessions: false,
3841
}
3942
const hash =
4043
new URLSearchParams(window.location.search).get('schedule') ??
4144
new URL(window.location.href).hash?.substr(1) ??
4245
false
4346

47+
const hidePastSessionsDefault =
48+
new URLSearchParams(window.location.search).get('hidePastSessions') !== null
49+
4450
if (hash) {
4551
cfg = {
4652
...cfg,
@@ -56,6 +62,9 @@ export const App = () => {
5662
const [updatedTimeZone, updateTimeZone] = useState(cfg.tz)
5763
const [updatedSessions, updateSessions] = useState(cfg.sessions)
5864
const [editing, setEditing] = useState(false)
65+
const [hidePastSessions, setHidePastSessions] = useState(
66+
hidePastSessionsDefault,
67+
)
5968
return (
6069
<ThemeProvider theme={theme}>
6170
<GlobalStyle />
@@ -99,6 +108,7 @@ export const App = () => {
99108
onChange={({ target: { value } }) => updateTimeZone(value)}
100109
/>
101110
</DateEditor>
111+
102112
<ThemeSwitcher
103113
currentTheme={theme}
104114
darkTheme={dark}
@@ -140,17 +150,24 @@ export const App = () => {
140150
<Headline>
141151
{updatedName}: {updatedDay}
142152
</Headline>
143-
<ThemeSwitcher
144-
currentTheme={theme}
145-
darkTheme={dark}
146-
lightTheme={light}
147-
onSwitch={updateTheme}
148-
/>
153+
<TitleActions>
154+
<Button onClick={() => setHidePastSessions((h) => !h)}>
155+
{hidePastSessions && <EyeOffIcon />}
156+
{!hidePastSessions && <EyeIcon />}
157+
</Button>
158+
<ThemeSwitcher
159+
currentTheme={theme}
160+
darkTheme={dark}
161+
lightTheme={light}
162+
onSwitch={updateTheme}
163+
/>
164+
</TitleActions>
149165
</Title>
150166
<Schedule
151167
sessions={cfg.sessions}
152168
eventTimezoneName={cfg.tz}
153169
conferenceDate={cfg.day}
170+
hidePastSessions={hidePastSessions}
154171
/>
155172
</>
156173
)}

src/Schedule.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ export const Schedule = ({
6666
conferenceDate,
6767
eventTimezoneName,
6868
sessions,
69+
hidePastSessions,
6970
}: {
7071
conferenceDate: string
7172
eventTimezoneName: string
7273
sessions: { [key: number]: string }
74+
hidePastSessions: boolean
7375
}) => {
7476
const userTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone
7577
const eventTime = toEventTime({ conferenceDate, userTimeZone })
@@ -95,22 +97,28 @@ export const Schedule = ({
9597
</tr>
9698
</thead>
9799
<tbody>
98-
{Object.entries(sessions).map(([time, name]) => (
99-
<tr key={time}>
100-
<td className={'time'}>
101-
{formatEventTime(eventTime((time as unknown) as number))}
102-
</td>
103-
<td className={'time'}>
104-
{userFormat(userTime((time as unknown) as number))}
105-
</td>
106-
<Countdown
107-
key={conferenceDate}
108-
conferenceDate={userTime(0)}
109-
startTime={userTime((time as unknown) as number)}
110-
/>
111-
<td>{name}</td>
112-
</tr>
113-
))}
100+
{Object.entries(sessions)
101+
.filter(
102+
([time]) =>
103+
!hidePastSessions ||
104+
startsInMinutes(userTime((time as unknown) as number)) > 0,
105+
)
106+
.map(([time, name]) => (
107+
<tr key={time}>
108+
<td className={'time'}>
109+
{formatEventTime(eventTime((time as unknown) as number))}
110+
</td>
111+
<td className={'time'}>
112+
{userFormat(userTime((time as unknown) as number))}
113+
</td>
114+
<Countdown
115+
key={conferenceDate}
116+
conferenceDate={userTime(0)}
117+
startTime={userTime((time as unknown) as number)}
118+
/>
119+
<td>{name}</td>
120+
</tr>
121+
))}
114122
</tbody>
115123
</Table>
116124
)

src/style/Main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const Headline = styled.h1`
1818
}
1919
`
2020

21+
export const TitleActions = styled.div``
22+
2123
export const Title = styled.div`
2224
display: flex;
2325
justify-content: space-between;
@@ -30,4 +32,7 @@ export const Title = styled.div`
3032
h1 {
3133
margin: 0;
3234
}
35+
${TitleActions} {
36+
display: flex;
37+
}
3338
`

0 commit comments

Comments
 (0)