Skip to content

Commit

Permalink
feat: Use withoutDk factory on /break
Browse files Browse the repository at this point in the history
  • Loading branch information
hrk091 committed Jun 29, 2024
1 parent 21dd54b commit 2630209
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pages/break-dk/menu/[confDay].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useGetTalksAndTracksForMenu } from '@/components/hooks/useGetTalksAndTracks'
import { MenuView } from '@/components/models/talkView'
import config, { extendConfig } from '@/config'
import { Talk } from '@/generated/dreamkast-api.generated'
import type { Talk } from '@/data/types'
import { getTimeStr } from '@/utils/time'
import { Optional } from '@/utils/types'
import Link from 'next/link'
Expand Down
14 changes: 5 additions & 9 deletions src/pages/break/menu/[confDay].tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useGetTalksAndTracksForMenu } from '@/components/hooks/useGetTalksAndTracks'
import { MenuView } from '@/components/models/talkView'
import config, { extendConfig } from '@/config'
import { Talk } from '@/generated/dreamkast-api.generated'
import type { Talk } from '@/data/types'
import { getTimeStr } from '@/utils/time'
import { Optional } from '@/utils/types'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { talks } from '@/data/talks'
import { tracks } from '@/data/tracks'
import { speakers } from '@/data/speakers'

export default function Index() {
const router = useRouter()
Expand All @@ -16,14 +18,8 @@ export default function Index() {
}, [router.query])
const { eventAbbr } = config

const { isLoading, view } = useGetTalksAndTracksForMenu(
eventAbbr as Optional<string>,
confDay as Optional<string>
)
const view = MenuView.withoutDk(confDay as string, talks, tracks, speakers)

if (isLoading) {
return <div className="text-white">Loading...</div>
}
return (
<div>
<div className="text-3xl text-white text-center w-full my-5">
Expand Down
17 changes: 13 additions & 4 deletions src/pages/break/talks/[talkId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ 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 { TalkView } from '@/components/models/talkView'
import config, { extendConfig } from '@/config'
import { speakers } from '@/data/speakers'
import { talks } from '@/data/talks'
import { tracks } from '@/data/tracks'
import { useRouter } from 'next/router'
import { useContext, useEffect } from 'react'
import { useContext, useEffect, useMemo } from 'react'

function updateCache() {
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
Expand All @@ -23,7 +26,13 @@ function Pages() {
}, [router.query])

const { current, setTotalPage, goNextPage } = useContext(PageCtx)
const { isLoading, view } = useGetTalksAndTracks(talkId as string | null)

const view = useMemo(() => {
if (!talkId) {
return null
}
return TalkView.withoutDk(talkId as string, talks, tracks, speakers)
}, [talkId])

const pages = [
<Page1 key={1} view={view} />,
Expand All @@ -38,7 +47,7 @@ function Pages() {
const audioSrc = '/cnds2024/cnds2024_intermission.mp3'
const shouldPlayAudio = current !== pages.length - 1

if (isLoading) {
if (!view) {
return <div className="text-white">Loading...</div>
}
return (
Expand Down

0 comments on commit 2630209

Please sign in to comment.