Skip to content

Commit 695dfdc

Browse files
committed
feat: add iCal export
1 parent 8c0ef93 commit 695dfdc

File tree

5 files changed

+245
-11
lines changed

5 files changed

+245
-11
lines changed

package-lock.json

Lines changed: 103 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"ajv": "8.10.0",
3333
"date-fns-tz": "1.3.0",
3434
"feather-icons": "4.28.0",
35+
"ics": "2.35.0",
3536
"react": "17.0.2",
3637
"react-dom": "17.0.2",
3738
"react-router-dom": "6.2.2"

src/App.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import styles from 'app/App.module.css'
22
import { DaySelector } from 'app/DaySelector'
33
import { Editor } from 'app/Editor'
4-
import { EyeIcon, EyeOffIcon, LockIcon, UnLockIcon } from 'app/FeatherIcons'
4+
import {
5+
CalendarIcon,
6+
EyeIcon,
7+
EyeOffIcon,
8+
LockIcon,
9+
UnLockIcon,
10+
} from 'app/FeatherIcons'
511
import { Footer } from 'app/Footer'
612
import formStyles from 'app/Form.module.css'
7-
import { Schedule } from 'app/Schedule'
13+
import { Schedule as ScheduleComponent } from 'app/Schedule'
814
import { Theme, ThemeSwitcher } from 'app/ThemeSwitcher'
915
import { TimeZoneSelector } from 'app/timezones'
16+
import { useIcalExport } from 'app/useIcalExport'
1017
import { format } from 'date-fns'
1118
import { useEffect, useState } from 'react'
1219

@@ -16,8 +23,16 @@ if (typeof window.matchMedia === 'function') {
1623
defaultTheme = match.matches ? Theme.dark : Theme.light
1724
}
1825

26+
export type Schedule = {
27+
name: string
28+
day: string
29+
tz: string
30+
sessions: Record<number, string>
31+
hidePastSessions: boolean
32+
}
33+
1934
export const App = () => {
20-
let cfg = {
35+
let cfg: Schedule = {
2136
name: 'ExampleConf',
2237
day: format(new Date(), 'yyyy-MM-dd'),
2338
tz: 'Europe/Oslo',
@@ -70,6 +85,8 @@ export const App = () => {
7085
hidePastSessionsDefault,
7186
)
7287

88+
const downloadIcal = useIcalExport(cfg)
89+
7390
useEffect(() => {
7491
document.documentElement.setAttribute('data-theme', theme)
7592
}, [theme])
@@ -153,6 +170,15 @@ export const App = () => {
153170
{updatedName}: {updatedDay}
154171
</h1>
155172
<div className="actions">
173+
<button
174+
className={formStyles.Button}
175+
title="Export as calendar (.ics)"
176+
onClick={() => {
177+
downloadIcal()
178+
}}
179+
>
180+
<CalendarIcon />
181+
</button>
156182
<button
157183
className={formStyles.Button}
158184
title="Hide past sessions"
@@ -164,7 +190,7 @@ export const App = () => {
164190
<ThemeSwitcher currentTheme={theme} onSwitch={updateTheme} />
165191
</div>
166192
</div>
167-
<Schedule
193+
<ScheduleComponent
168194
sessions={cfg.sessions}
169195
eventTimezoneName={cfg.tz}
170196
conferenceDate={cfg.day}

src/FeatherIcons.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,7 @@ export const LightModeIcon = (options?: TypedIconOptions) => (
363363
export const GithubIcon = (options?: TypedIconOptions) => (
364364
<FeatherIcon {...options} type="github" title="GitHub" />
365365
)
366+
367+
export const CalendarIcon = (options?: TypedIconOptions) => (
368+
<FeatherIcon {...options} type="calendar" title="Export as calendar (.ics)" />
369+
)

0 commit comments

Comments
 (0)