fix: better room creation
continuous-integration/drone/push Build is passing Details

main
Antonio De Lucreziis 17 hours ago
parent 7121553761
commit 09cbbdd438

@ -27,7 +27,7 @@ export const NewRoom = ({}) => {
// const [questions, setQuestions] = useState<{ group: string; name: string }[]>([{ group: '', name: '' }])
const [questions, setQuestions] = useState<{ group: string; name: string }[]>(
Array.from({ length: 18 }, (_, i) => ({
group: `P${Math.floor(i / 6) + 1}`,
group: ['A', 'B', 'C'][Math.floor(i / 6)],
name: `${(i % 6) + 1}`,
}))
)
@ -53,20 +53,21 @@ export const NewRoom = ({}) => {
<button
class="square"
onClick={() => {
const teamsSyntax = prompt(`Aggiungi squadre separate da virgola, e.g. "Team 1,Team 2,..."`)
if (!teamsSyntax) return
const teamsSyntax = prompt(`Aggiungi squadre separate da virgola, e.g. "Team 1, Team 2, ..."`)
if (!teamsSyntax) {
return
}
setTeams(teams => {
return [
...teams,
...teamsSyntax.split(',').flatMap(t => {
if (t.includes('*')) {
const [team, count] = t.split('*')
const [team, count] = t.trim().split('*')
return Array.from({ length: Number(count) }, (_, i) => `${team}-${i + 1}`)
}
return [t]
return [t.trim()]
}),
]
})
@ -119,15 +120,16 @@ export const NewRoom = ({}) => {
<button
class="square"
onClick={() => {
const questionsSyntax = prompt(`Aggiungi domande separate da virgola, e.g. "P1*6, P2*4"`)
if (!questionsSyntax) return
const questionsSyntax = prompt(`Aggiungi domande separate da virgola, e.g. "A*6, B*4"`)
if (!questionsSyntax) {
return
}
setQuestions(questions => {
return [
...questions,
...questionsSyntax.split(',').flatMap(q => {
const [group, count] = q.split('*')
const [group, count] = q.trim().split('*')
return Array.from({ length: Number(count) }, (_, i) => ({
group,
@ -187,12 +189,14 @@ export const NewRoom = ({}) => {
<button
onClick={() =>
handleCreateRoom(
roomName,
teams,
questions.map(q => ({
id: `${q.group}.${q.name}`,
group: q.group,
}))
roomName.trim(),
teams.map(t => t.trim()).filter(t => t.length > 0),
questions
.filter(q => [q.group, q.name].every(s => s.trim().length > 0))
.map(q => ({
id: `${q.group.trim()}.${q.name.trim()}`,
group: q.group.trim(),
}))
)
}
>

Loading…
Cancel
Save