Fixed puzzle & added code block as spoiler
This commit is contained in:
parent
825d6c4e12
commit
0773cba2c8
5 changed files with 62 additions and 45 deletions
|
@ -49,7 +49,7 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
formData.append('answer', data.answer);
|
formData.append('answer', data.answer.trim());
|
||||||
// formData.append('filename', 'placeholder');
|
// formData.append('filename', 'placeholder');
|
||||||
// formData.append('code_file', new Blob(), 'placeholder');
|
// formData.append('code_file', new Blob(), 'placeholder');
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import Dialog from './Dialog';
|
||||||
import Icon from './Icon';
|
import Icon from './Icon';
|
||||||
import Input from './Input';
|
import Input from './Input';
|
||||||
import Select from './Select';
|
import Select from './Select';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
export default function Puzzles({ token }: { token: string }) {
|
export default function Puzzles({ token }: { token: string }) {
|
||||||
const { data: me } = useContext(UserContext);
|
const { data: me } = useContext(UserContext);
|
||||||
|
@ -93,28 +94,30 @@ export default function Puzzles({ token }: { token: string }) {
|
||||||
{isInEventGroup(chapter) && (
|
{isInEventGroup(chapter) && (
|
||||||
<ul className="flex flex-col space-y-4">
|
<ul className="flex flex-col space-y-4">
|
||||||
{chapter.puzzles &&
|
{chapter.puzzles &&
|
||||||
chapter.puzzles.sort((p1, p2) => {
|
chapter.puzzles
|
||||||
if(p1.tags == undefined) return 1;
|
.sort((p1, p2) => {
|
||||||
if(p2.tags == undefined) return -1;
|
if (p1.tags == undefined) return 1;
|
||||||
let e1 = p1.tags.findIndex(tag => tag.name === "easy") >= 0;
|
if (p2.tags == undefined) return -1;
|
||||||
let e2 = p2.tags.findIndex(tag => tag.name === "easy") >= 0;
|
const e1 = p1.tags.findIndex((tag) => tag.name === 'easy') >= 0;
|
||||||
if(e1 && e2) return p1.tags.length-p2.tags.length;
|
const e2 = p2.tags.findIndex((tag) => tag.name === 'easy') >= 0;
|
||||||
if(e1) return -1;
|
if (e1 && e2) return p1.tags.length - p2.tags.length;
|
||||||
if(e2) return 1;
|
if (e1) return -1;
|
||||||
let m1 = p1.tags.findIndex(tag => tag.name === "medium") >= 0;
|
if (e2) return 1;
|
||||||
let m2 = p2.tags.findIndex(tag => tag.name === "medium") >= 0;
|
const m1 = p1.tags.findIndex((tag) => tag.name === 'medium') >= 0;
|
||||||
if(m1 && m2) return p1.tags.length-p2.tags.length;
|
const m2 = p2.tags.findIndex((tag) => tag.name === 'medium') >= 0;
|
||||||
if(m1) return -1;
|
if (m1 && m2) return p1.tags.length - p2.tags.length;
|
||||||
if(m2) return 1;
|
if (m1) return -1;
|
||||||
let h1 = p1.tags.findIndex(tag => tag.name === "hard") >= 0;
|
if (m2) return 1;
|
||||||
let h2 = p2.tags.findIndex(tag => tag.name === "hard") >= 0;
|
const h1 = p1.tags.findIndex((tag) => tag.name === 'hard') >= 0;
|
||||||
if(h1 && h2) return p1.tags.length-p2.tags.length;
|
const h2 = p2.tags.findIndex((tag) => tag.name === 'hard') >= 0;
|
||||||
if(h1) return -1;
|
if (h1 && h2) return p1.tags.length - p2.tags.length;
|
||||||
if(h2) return 1;
|
if (h1) return -1;
|
||||||
return p1.tags.length-p2.tags.length;
|
if (h2) return 1;
|
||||||
}).map((puzzle) => (
|
return p1.tags.length - p2.tags.length;
|
||||||
<PuzzleProp key={puzzle.id} puzzle={puzzle} chapter={chapter} />
|
})
|
||||||
))}
|
.map((puzzle) => (
|
||||||
|
<PuzzleProp key={puzzle.id} puzzle={puzzle} chapter={chapter} />
|
||||||
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -238,6 +241,7 @@ type GroupData = {
|
||||||
|
|
||||||
function GroupForm({ chapter, token }: { chapter: Chapter; token: string }) {
|
function GroupForm({ chapter, token }: { chapter: Chapter; token: string }) {
|
||||||
const [isJoining, setIsJoining] = useState(false);
|
const [isJoining, setIsJoining] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const { data: groups } = useGroups({ token });
|
const { data: groups } = useGroups({ token });
|
||||||
|
|
||||||
|
@ -256,13 +260,20 @@ function GroupForm({ chapter, token }: { chapter: Chapter; token: string }) {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function onSubmit(data: GroupData) {
|
async function onSubmit(data: GroupData) {
|
||||||
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/${isJoining ? 'groupJoin' : 'groupCreate'}`, {
|
const res = await fetch(
|
||||||
method: 'POST',
|
`${process.env.NEXT_PUBLIC_API_URL}/${isJoining ? 'groupJoin' : 'groupCreate'}`,
|
||||||
body: JSON.stringify(data),
|
{
|
||||||
headers: {
|
method: 'POST',
|
||||||
Authorization: `Bearer ${token}`
|
body: JSON.stringify(data),
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
// TODO: handle errors
|
||||||
|
if (res.ok) {
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -31,9 +31,11 @@ export function Timer({ targetDate, className }: { targetDate: Date; className?:
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
const timeDifference = targetDate.getTime() - Date.now();
|
const timeDifference = targetDate.getTime() - Date.now();
|
||||||
|
|
||||||
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
|
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
|
||||||
const minutes = Math.floor((timeDifference / (1000 * 60)) % 60);
|
const minutes = Math.floor((timeDifference / (1000 * 60)) % 60);
|
||||||
const seconds = Math.floor((timeDifference / 1000) % 60);
|
const seconds = Math.floor((timeDifference / 1000) % 60);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SET_TIME_REMAINING',
|
type: 'SET_TIME_REMAINING',
|
||||||
payload: { hours, minutes, seconds }
|
payload: { hours, minutes, seconds }
|
||||||
|
@ -45,9 +47,7 @@ export function Timer({ targetDate, className }: { targetDate: Date; className?:
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={clsx('', className)}>
|
<span className={clsx('', className)}>
|
||||||
{`${timeRemaining.hours.toString().padStart(2, '0')}:${timeRemaining.minutes
|
{timeRemaining.hours}h {timeRemaining.minutes}m {timeRemaining.seconds}s
|
||||||
.toString()
|
|
||||||
.padStart(2, '0')}:${timeRemaining.seconds.toString().padStart(2, '0')}`}
|
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,23 @@ import remarkBreaks from 'remark-breaks';
|
||||||
|
|
||||||
export default function ToHTML({ data, className }: { data: string; className?: string }) {
|
export default function ToHTML({ data, className }: { data: string; className?: string }) {
|
||||||
return (
|
return (
|
||||||
<div className={cn('select-none', className)}>
|
<div className={cn(className)}>
|
||||||
<Mardown
|
<Mardown
|
||||||
components={{
|
components={{
|
||||||
a: ({ node, ...props }) => (
|
a: ({ node, ...props }) => (
|
||||||
<a {...props} className="text-brand" download={node} target="_blank" rel="noreferrer" />
|
<a
|
||||||
|
{...props}
|
||||||
|
className="text-brand hover:text-brand/80 hover:underline"
|
||||||
|
download={node}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
code: ({ ...props }) => (
|
||||||
|
<span
|
||||||
|
{...props}
|
||||||
|
className="cursor-pointer select-none rounded bg-black p-0.5 text-black hover:bg-transparent hover:text-white"
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
remarkPlugins={[remarkGfm, remarkBreaks]}
|
remarkPlugins={[remarkGfm, remarkBreaks]}
|
||||||
|
|
|
@ -58,8 +58,6 @@ export default function UserAuthForm() {
|
||||||
type: 'manual',
|
type: 'manual',
|
||||||
message: "Une erreur s'est produite."
|
message: "Une erreur s'est produite."
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSignIn) {
|
if (!isSignIn) {
|
||||||
|
@ -70,8 +68,6 @@ export default function UserAuthForm() {
|
||||||
type: 'manual',
|
type: 'manual',
|
||||||
message: "Nom d'utilisateur indisponible"
|
message: "Nom d'utilisateur indisponible"
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
}
|
||||||
if (!email_valid) {
|
if (!email_valid) {
|
||||||
setError('email', {
|
setError('email', {
|
||||||
|
@ -79,7 +75,6 @@ export default function UserAuthForm() {
|
||||||
message: 'Adresse e-mail indisponible'
|
message: 'Adresse e-mail indisponible'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +92,6 @@ export default function UserAuthForm() {
|
||||||
type: 'manual',
|
type: 'manual',
|
||||||
message: "Nom d'utilisateur ou mot de passe incorrect"
|
message: "Nom d'utilisateur ou mot de passe incorrect"
|
||||||
});
|
});
|
||||||
setIsLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
@ -113,7 +107,7 @@ export default function UserAuthForm() {
|
||||||
<Input
|
<Input
|
||||||
label="Adresse e-mail"
|
label="Adresse e-mail"
|
||||||
type="email"
|
type="email"
|
||||||
placeholder="peer-at@exemple.be"
|
placeholder="philipzcwbarlow@peerat.dev"
|
||||||
required
|
required
|
||||||
error={errors.email?.message}
|
error={errors.email?.message}
|
||||||
{...register('email')}
|
{...register('email')}
|
||||||
|
@ -121,14 +115,14 @@ export default function UserAuthForm() {
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label="Nom"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Doe"
|
placeholder="Barlow"
|
||||||
error={errors.lastname?.message}
|
error={errors.lastname?.message}
|
||||||
{...register('lastname')}
|
{...register('lastname')}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Prénom"
|
label="Prénom"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="John"
|
placeholder="Philipz"
|
||||||
error={errors.firstname?.message}
|
error={errors.firstname?.message}
|
||||||
{...register('firstname')}
|
{...register('firstname')}
|
||||||
/>
|
/>
|
||||||
|
@ -137,7 +131,7 @@ export default function UserAuthForm() {
|
||||||
<Input
|
<Input
|
||||||
label="Nom d'utilisateur"
|
label="Nom d'utilisateur"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="PeerAt"
|
placeholder="CZ"
|
||||||
required
|
required
|
||||||
error={errors.pseudo?.message}
|
error={errors.pseudo?.message}
|
||||||
{...register('pseudo')}
|
{...register('pseudo')}
|
||||||
|
@ -145,7 +139,7 @@ export default function UserAuthForm() {
|
||||||
<Input
|
<Input
|
||||||
label="Mot de passe"
|
label="Mot de passe"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="MotDePasse123"
|
placeholder="Terre en vue mon capitaine !"
|
||||||
required
|
required
|
||||||
error={errors.passwd?.message}
|
error={errors.passwd?.message}
|
||||||
{...register('passwd')}
|
{...register('passwd')}
|
||||||
|
|
Loading…
Add table
Reference in a new issue