forked from ijokarumawak/web-interlude
-
Notifications
You must be signed in to change notification settings - Fork 0
/
[talkId].tsx
86 lines (79 loc) · 2.7 KB
/
[talkId].tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import AudioPlayer from '@/components/AudioPlayer'
import Page1 from '@/components/Page1'
import Page2, { AvatarPreLoader } from '@/components/Page2'
import Page3 from '@/components/Page3'
import Page4 from '@/components/Page4'
import { useGetTalksAndTracks } from '@/components/hooks/useGetTalksAndTracks'
import { PageCtx, PageCtxProvider } from '@/components/models/pageContext'
import config, { extendConfig } from '@/config'
import { useRouter } from 'next/router'
import { useContext, useEffect } from 'react'
function updateCache() {
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ type: 'UPDATE_CACHE' })
}
}
function Pages() {
const router = useRouter()
const { talkId } = router.query
useEffect(() => {
extendConfig(router.query as Record<string, string>)
}, [router.query])
const { current, setTotalPage, goNextPage } = useContext(PageCtx)
const { isLoading, view } = useGetTalksAndTracks(talkId as string | null)
const pages = [
<Page1 key={1} view={view} />,
<Page2 key={2} view={view} />,
<Page3 key={3} view={view} />,
// CM スポンサーなしのためコメントアウト (下のshouldPlayAudioも編集が必要)
// <Page4 key={4} view={view} />,
]
useEffect(() => {
setTotalPage(pages.length)
}, []) // eslint-disable-line react-hooks/exhaustive-deps
const audioSrc = '/cndw2024/cndw2024_intermission.mp3'
// CM ありの場合
// const shouldPlayAudio = current !== pages.length - 1
// CM なしの場合
const shouldPlayAudio = true
if (isLoading) {
return <div className="text-white">Loading...</div>
}
return (
<>
<div>
<link rel="stylesheet" href="https://use.typekit.net/egz6rzg.css" />
<link rel="stylesheet" href="https://use.typekit.net/hbv7ezy.css" />
</div>
{config.debug && (
<>
<button
onClick={updateCache}
className="font-bold py-0 px-4 mx-2 my-2 rounded bg-yellow-300 items-right"
>
Update Video Cache
</button>
<button
onClick={goNextPage}
className="font-bold py-0 px-4 mx-2 my-2 rounded bg-blue-300 items-right"
>
Go Next
</button>
</>
)}
<AudioPlayer src={audioSrc} shouldPlay={shouldPlayAudio} />
<AvatarPreLoader view={view}></AvatarPreLoader>
<div className="w-[1920px] h-[1080px] bg-[url('/cndw2024/background.png')]">
{pages[current]}
</div>
<div className="w-[1280px] h-[300px] bg-black relative"></div>
</>
)
}
export default function Index() {
return (
<PageCtxProvider>
<Pages />
</PageCtxProvider>
)
}