-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from simonyiszk/feature/limit-questions-per-pr…
…esentation Limit questions per presentation
- Loading branch information
Showing
13 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
import { RoomQuestion } from '@/components/tiles/question-tile'; | ||
import { QuestionPageBody } from '@/components/questions/question-page-body'; | ||
import { getDelayData } from '@/models/get-delay-data'; | ||
import { getPresentationData } from '@/models/get-presentation-data'; | ||
|
||
export default async function questionsPage() { | ||
const presentations = await getPresentationData(); | ||
const delay = await getDelayData(); | ||
return ( | ||
<div className='flex flex-col px-4 sm:px-6 xl:px-0 max-w-6xl w-full overflow-hidden'> | ||
<h1 className='mb-16 mt-8'>Kérdezz az elődóktól!</h1> | ||
|
||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-6'> | ||
<div className='order-1'> | ||
<h2 className='text-4xl text-center'>IB028</h2> | ||
</div> | ||
<div className='order-3 sm:order-2'> | ||
<h2 className='text-4xl text-center'>IB025</h2> | ||
</div> | ||
<div className='order-2 sm:order-3'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB028' /> | ||
</div> | ||
<div className='order-4'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB025' /> | ||
</div> | ||
</div> | ||
<QuestionPageBody presentations={presentations} delay={delay ?? 0} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3'; | ||
|
||
import { RoomQuestion } from '@/components/tiles/question-tile'; | ||
import { PresentationWithDates } from '@/models/models'; | ||
|
||
export function QuestionPageBody({ | ||
presentations, | ||
delay, | ||
}: { | ||
presentations: PresentationWithDates[] | undefined; | ||
delay: number; | ||
}) { | ||
return ( | ||
<GoogleReCaptchaProvider reCaptchaKey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY ?? ''}> | ||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-6'> | ||
<div className='order-1'> | ||
<h2 className='text-4xl text-center'>IB028</h2> | ||
</div> | ||
<div className='order-3 sm:order-2 mt-16 sm:mt-0'> | ||
<h2 className='text-4xl text-center'>IB025</h2> | ||
</div> | ||
<div className='order-2 sm:order-3'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB028' delay={delay} /> | ||
</div> | ||
<div className='order-4'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB025' delay={delay} /> | ||
</div> | ||
</div> | ||
</GoogleReCaptchaProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
'use client'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { PresentationWithDates } from '@/models/models'; | ||
import { getCurrentDate } from '@/utils/dateHelper'; | ||
|
||
import { PresentationTile } from '../presentation/PresentationGrid'; | ||
|
||
type Props = { | ||
presentations: PresentationWithDates[]; | ||
room: 'IB028' | 'IB025'; | ||
delay: number; | ||
}; | ||
const MARGIN_MINUTES = 10; | ||
|
||
export function RoomQuestion({ presentations, room, delay }: Props) { | ||
const [now, setNow] = useState(new Date(0)); | ||
|
||
useEffect(() => { | ||
setNow(getNow(delay)); | ||
const id = setInterval(() => setNow(getNow(delay)), 30000); | ||
return () => clearInterval(id); | ||
}, []); | ||
|
||
export function RoomQuestion({ presentations, room }: Props) { | ||
const now = getCurrentDate(); | ||
const presentation = presentations.find((p) => p.room === room && p.startDate < now && p.endDate > now); | ||
return presentation ? ( | ||
<PresentationTile presentation={presentation} preview /> | ||
const presentationInRoom = presentations.filter((p) => { | ||
const endDateWithMargin = new Date(p.endDate); | ||
endDateWithMargin.setMinutes(endDateWithMargin.getMinutes() + MARGIN_MINUTES); | ||
return p.room === room && !p.placeholder && p.startDate < now && endDateWithMargin > now; | ||
}); | ||
return presentationInRoom.length > 0 ? ( | ||
<div className='flex flex-col gap-4'> | ||
{presentationInRoom.reverse().map((p) => ( | ||
<PresentationTile presentation={p} key={p.slug} preview /> | ||
))} | ||
</div> | ||
) : ( | ||
<p className='text-stone-200 text-base sm:text-[20px] text-center'> | ||
Jelenleg nincs előadás ebben a teremben, nézz vissza később! | ||
</p> | ||
); | ||
} | ||
|
||
function getNow(delay: number): Date { | ||
const now = new Date(); | ||
now.setMinutes(now.getMinutes() - delay); | ||
return now; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export async function getDelayData() { | ||
const response = await fetch(`${process.env.BACKEND_URL}/proto/delay`, { cache: 'no-store' }); | ||
if (!response.ok) { | ||
console.error(response); | ||
return; | ||
} | ||
const data: { delay: number } = await response.json(); | ||
return data.delay; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; | ||
|
||
export const AllowedQuestionCount = 3; | ||
|
||
export function getUserId(): string { | ||
let key = localStorage.getItem('user-id'); | ||
if (!key) { | ||
key = generateRandomString(32); | ||
localStorage.setItem('user-id', key); | ||
} | ||
return key; | ||
} | ||
|
||
export function getQuestionCount(slug: string) { | ||
let amount = Number(localStorage.getItem(`question-${slug}`)); | ||
if (isNaN(amount)) { | ||
amount = 0; | ||
localStorage.setItem(`question-${slug}`, String(amount)); | ||
} | ||
return amount; | ||
} | ||
|
||
export function incrementQuestionCount(slug: string) { | ||
localStorage.setItem(`question-${slug}`, String(getQuestionCount(slug) + 1)); | ||
} | ||
|
||
function generateRandomString(length: number): string { | ||
return Array.from({ length }) | ||
.map(() => chars[Math.floor(Math.random() * chars.length)]) | ||
.join(''); | ||
} |