-
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.
Limit the number of asked questions per visitor
- Loading branch information
Showing
6 changed files
with
105 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
import { RoomQuestion } from '@/components/tiles/question-tile'; | ||
import { QuestionPageBody } from '@/components/questions/question-page-body'; | ||
import { getPresentationData } from '@/models/get-presentation-data'; | ||
|
||
export default async function questionsPage() { | ||
const presentations = await getPresentationData(); | ||
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} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'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 }: { presentations: PresentationWithDates[] | undefined }) { | ||
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' /> | ||
</div> | ||
<div className='order-4'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB025' /> | ||
</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 |
---|---|---|
@@ -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(''); | ||
} |