diff --git a/backend/app/challenges/routes.py b/backend/app/challenges/routes.py index 916003d0..1bb7d053 100644 --- a/backend/app/challenges/routes.py +++ b/backend/app/challenges/routes.py @@ -95,6 +95,8 @@ async def save_answer( if participant is None: raise BadRequestError("You are not subscribed to this challenge.") + if participant.submitted_at is not None: + raise BadRequestError("Challenge submission is already complete.") await answer_service.upsert_answer( session, participant.id, data.question_id, data.answer @@ -123,24 +125,24 @@ async def submit_input( raise NotFoundError("Challenge not found.") if challenge.scoring_type != ChallengeScoringType.INPUT: raise BadRequestError("Challenge does not accept input submissions.") - challenge_service.ensure_challenge_open(challenge.finishes_at) if participant.submitted_at is not None: return challenge_schemas.SubmissionResponse( submitted_at=participant.submitted_at, score=participant.score ) + challenge_service.ensure_challenge_open(challenge.finishes_at) participant.submission = data.answer - participant.submitted_at = datetime.now(UTC) input_data = challenge.input - participant.score = ( - challenge.points_value - if input_data is not None + is_correct = ( + input_data is not None and input_data.input_answer is not None and data.answer.strip().lower() == input_data.input_answer.strip().lower() - else 0 ) + participant.score = challenge.points_value if is_correct else 0 + if is_correct: + participant.submitted_at = datetime.now(UTC) await session.flush() - if participant.semana_participant is not None: + if is_correct and participant.semana_participant is not None: await semana_service.add_points( session, participant.semana_participant, @@ -180,6 +182,8 @@ async def save_many_answers( if participant is None: raise BadRequestError("You are not subscribed to this challenge.") + if participant.submitted_at is not None: + raise BadRequestError("Challenge submission is already complete.") for answer_body in data: await answer_service.upsert_answer( @@ -224,7 +228,10 @@ async def submit_challenge( challenge_service.ensure_challenge_open(challenge.finishes_at) score = await challenge_service.process_submission(session, participant, challenge) - if participant.semana_participant is not None: + if ( + participant.submitted_at is not None + and participant.semana_participant is not None + ): await semana_service.add_points( session, participant.semana_participant, @@ -280,6 +287,7 @@ async def get_challenge( questions=question_responses, is_participant=participant is not None, submitted_at=participant.submitted_at if participant else None, + score=participant.score if participant else None, ) @@ -310,6 +318,11 @@ async def get_ranking( ] +@router.get( + "", + response_model=Page[challenge_schemas.ChallengePublicResponse], + include_in_schema=False, +) @router.get("/", response_model=Page[challenge_schemas.ChallengePublicResponse]) async def list_challenges( session: Annotated[AsyncSession, Depends(get_session)], diff --git a/backend/app/challenges/schemas.py b/backend/app/challenges/schemas.py index dda13c9f..44741764 100644 --- a/backend/app/challenges/schemas.py +++ b/backend/app/challenges/schemas.py @@ -13,7 +13,7 @@ class AnswerBody(BaseModel): class SubmissionResponse(BaseModel): - submitted_at: datetime + submitted_at: datetime | None score: int @@ -185,6 +185,7 @@ class ChallengeResponse(ChallengeImageMixin): questions: list[QuestionResponse] = Field(default_factory=list) is_participant: bool = False submitted_at: datetime | None = None + score: int | None = None class ChallengePublicResponse(ChallengeImageMixin): diff --git a/backend/app/challenges/services/challenge.py b/backend/app/challenges/services/challenge.py index 57a6f94a..4f436089 100644 --- a/backend/app/challenges/services/challenge.py +++ b/backend/app/challenges/services/challenge.py @@ -85,7 +85,8 @@ async def process_submission( else 0 ) - participant.submitted_at = datetime.now(UTC) + is_complete = bool(question_count) and (correct_count or 0) == question_count + participant.submitted_at = datetime.now(UTC) if is_complete else None participant.score = score await session.flush() diff --git a/backend/app/semana/schemas.py b/backend/app/semana/schemas.py index be7873c7..faa2c0ab 100644 --- a/backend/app/semana/schemas.py +++ b/backend/app/semana/schemas.py @@ -62,6 +62,7 @@ class ParticipationWeek(BaseModel): semana_id: int nome: str ano: int + nickname: str | None pontos: int horas: int diff --git a/backend/app/semana/services.py b/backend/app/semana/services.py index ccbf30d1..00fbd8e3 100644 --- a/backend/app/semana/services.py +++ b/backend/app/semana/services.py @@ -116,6 +116,7 @@ async def get_user_participation(session: AsyncSession, user_id): Semana.id, Semana.nome, Semana.ano, + SemanaParticipant.nickname, func.coalesce(func.sum(PointEvent.amount), 0).label("pontos"), ) .join(SemanaParticipant, SemanaParticipant.semana_id == Semana.id) @@ -125,7 +126,12 @@ async def get_user_participation(session: AsyncSession, user_id): SemanaParticipant.deleted_at.is_(None), PointEvent.deleted_at.is_(None) | (PointEvent.id.is_(None)), ) - .group_by(Semana.id, Semana.nome, Semana.ano) + .group_by( + Semana.id, + Semana.nome, + Semana.ano, + SemanaParticipant.nickname, + ) ) hours_rows = await session.execute( select( @@ -155,6 +161,7 @@ async def get_user_participation(session: AsyncSession, user_id): "ano": point_row.ano if point_row else (await get_semana(session, semana_id)).ano, + "nickname": point_row.nickname if point_row else None, "pontos": int(point_row.pontos) if point_row else 0, "horas": int(hours.get(semana_id, 0)), } diff --git a/backend/app/tests/challenges/integration/test_list_and_ranking.py b/backend/app/tests/challenges/integration/test_list_and_ranking.py index 82be4148..2b20e493 100644 --- a/backend/app/tests/challenges/integration/test_list_and_ranking.py +++ b/backend/app/tests/challenges/integration/test_list_and_ranking.py @@ -21,7 +21,7 @@ async def test_list_challenges_paginated( c = as_user(user) - r = await c.get("api/v1/challenge/", params={"limit": 2, "offset": 0}) + r = await c.get("api/v1/challenge", params={"limit": 2, "offset": 0}) assert r.status_code == 200 body = r.json() assert body["total"] == 5 diff --git a/backend/app/tests/challenges/integration/test_quiz_lifecycle.py b/backend/app/tests/challenges/integration/test_quiz_lifecycle.py index 4e9112ce..9636e983 100644 --- a/backend/app/tests/challenges/integration/test_quiz_lifecycle.py +++ b/backend/app/tests/challenges/integration/test_quiz_lifecycle.py @@ -6,9 +6,12 @@ from datetime import UTC, datetime, timedelta from httpx import AsyncClient +from sqlalchemy import func, select from app.challenges.models.challenge import ChallengeScoringType +from app.challenges.models.challenge_participant import ChallengeParticipant from app.challenges.models.input import Input +from app.semana.models import PointEvent, SemanaEvent, SemanaParticipant async def test_input_challenge_scores_using_challenge_points( @@ -24,11 +27,91 @@ async def test_input_challenge_scores_using_challenge_points( assert joined.status_code == 200, joined.text response = await c.post( - f"api/v1/challenge/{challenge.id}/input", json={"answer": "correct"} + f"api/v1/challenge/{challenge.id}/input", json={"answer": "incorrect"} ) assert response.status_code == 200, response.text - assert response.json()["score"] == 40 + assert response.json() == {"submitted_at": None, "score": 0} + + challenge_state = await c.get(f"api/v1/challenge/{challenge.id}") + assert challenge_state.status_code == 200, challenge_state.text + assert challenge_state.json()["submitted_at"] is None + assert "input_answer" not in challenge_state.json() + + participant = await db_session.scalar( + select(ChallengeParticipant).where( + ChallengeParticipant.user_id == user.id, + ChallengeParticipant.challenge_id == challenge.id, + ) + ) + assert participant is not None + assert ( + await db_session.scalar( + select(func.count(PointEvent.id)).where( + PointEvent.source_type == "challenge", + PointEvent.source_id == participant.id, + ) + ) + == 0 + ) + + correct_response = await c.post( + f"api/v1/challenge/{challenge.id}/input", json={"answer": "correct"} + ) + assert correct_response.status_code == 200, correct_response.text + assert correct_response.json()["score"] == 40 + assert correct_response.json()["submitted_at"] is not None + + challenge_state = await c.get(f"api/v1/challenge/{challenge.id}") + assert ( + challenge_state.json()["submitted_at"] + == correct_response.json()["submitted_at"] + ) + assert challenge_state.json()["score"] == 40 + + repeated_response = await c.post( + f"api/v1/challenge/{challenge.id}/input", json={"answer": "incorrect"} + ) + assert repeated_response.status_code == 200, repeated_response.text + assert repeated_response.json() == correct_response.json() + assert ( + await db_session.scalar( + select(func.count(PointEvent.id)).where( + PointEvent.source_type == "challenge", + PointEvent.source_id == participant.id, + ) + ) + == 1 + ) + + challenge.finishes_at = datetime.now(UTC) - timedelta(seconds=1) + await db_session.flush() + expired_retry = await c.post( + f"api/v1/challenge/{challenge.id}/input", json={"answer": "incorrect"} + ) + assert expired_retry.status_code == 200 + assert expired_retry.json() == correct_response.json() + + +async def test_input_submission_is_rejected_after_challenge_expires( + client: AsyncClient, as_user, user, challenge, db_session +): + challenge.scoring_type = ChallengeScoringType.INPUT + challenge.input = Input(prompt="Answer?", input_answer="correct") + await db_session.flush() + + c = as_user(user) + joined = await c.post(f"api/v1/challenge/{challenge.id}/join") + assert joined.status_code == 200, joined.text + + challenge.finishes_at = datetime.now(UTC) - timedelta(seconds=1) + await db_session.flush() + + response = await c.post( + f"api/v1/challenge/{challenge.id}/input", json={"answer": "incorrect"} + ) + + assert response.status_code == 409 async def test_full_quiz_lifecycle( @@ -37,6 +120,7 @@ async def test_full_quiz_lifecycle( user, challenge, questions, + db_session, ): c = as_user(user) @@ -82,24 +166,87 @@ async def test_full_quiz_lifecycle( assert answers_by_qid[str(questions[1].id)] == "9" assert answers_by_qid[str(questions[2].id)] == "Rio" - # 5. Submit + # 5. Submit with one incorrect answer; retry remains available. r = await c.post(f"api/v1/challenge/{challenge.id}/submit") assert r.status_code == 200, r.text body = r.json() assert body["score"] == 150 + assert body["submitted_at"] is None + + participant = await db_session.scalar( + select(ChallengeParticipant).where( + ChallengeParticipant.user_id == user.id, + ChallengeParticipant.challenge_id == challenge.id, + ) + ) + assert participant is not None + assert ( + await db_session.scalar( + select(func.count(PointEvent.id)).where( + PointEvent.source_type == "challenge", + PointEvent.source_id == participant.id, + ) + ) + == 0 + ) + + retry = await c.post( + f"api/v1/challenge/{challenge.id}/answer", + json={"question_id": str(questions[2].id), "answer": "Brasília"}, + ) + assert retry.status_code == 204 + + completed = await c.post(f"api/v1/challenge/{challenge.id}/submit") + assert completed.status_code == 200, completed.text + body = completed.json() + assert body["score"] == 225 assert body["submitted_at"] is not None + completed_details = await c.get(f"api/v1/challenge/{challenge.id}") + assert completed_details.json()["submitted_at"] == body["submitted_at"] + assert completed_details.json()["score"] == 225 + + blocked_edit = await c.post( + f"api/v1/challenge/{challenge.id}/answer", + json={"question_id": str(questions[2].id), "answer": "Rio"}, + ) + assert blocked_edit.status_code == 400 + # 6. Submit de novo → idempotente r2 = await c.post(f"api/v1/challenge/{challenge.id}/submit") assert r2.status_code == 200 assert r2.json() == body + assert ( + await db_session.scalar( + select(func.count(PointEvent.id)).where( + PointEvent.source_type == "challenge", + PointEvent.source_id == participant.id, + ) + ) + == 1 + ) # 7. Ranking r = await c.get(f"api/v1/challenge/{challenge.id}/ranking") assert r.status_code == 200 ranking = r.json() assert len(ranking) == 1 - assert ranking[0]["score"] == 150 + assert ranking[0]["score"] == 225 + + +async def test_quiz_submission_is_rejected_after_challenge_expires( + client: AsyncClient, as_user, user, challenge, db_session +): + c = as_user(user) + joined = await c.post(f"api/v1/challenge/{challenge.id}/join") + assert joined.status_code == 200, joined.text + + challenge.finishes_at = datetime.now(UTC) - timedelta(seconds=1) + await db_session.flush() + + response = await c.post(f"api/v1/challenge/{challenge.id}/submit") + + assert response.status_code == 409 async def test_answering_without_joining_returns_400( @@ -132,6 +279,33 @@ async def test_nickname_is_reused_across_challenge_joins( assert second_join.json()["nickname"] == first_join.json()["nickname"] +async def test_profile_returns_the_nickname_for_each_week( + client: AsyncClient, as_user, user, challenge, db_session +): + c = as_user(user) + joined = await c.post(f"api/v1/challenge/{challenge.id}/join") + assert joined.status_code == 200, joined.text + + other_week = SemanaEvent(nome="Outra Semana", ano=2025) + db_session.add(other_week) + await db_session.flush() + db_session.add( + SemanaParticipant( + semana_id=other_week.id, + user_id=user.id, + nickname="OutraPessoa2025", + ) + ) + await db_session.flush() + + response = await c.get("/api/v1/semanas/participacao") + + assert response.status_code == 200, response.text + weeks = {week["semana_id"]: week for week in response.json()["semanas"]} + assert weeks[challenge.semana_id]["nickname"] == joined.json()["nickname"] + assert weeks[other_week.id]["nickname"] == "OutraPessoa2025" + + async def test_submitting_without_joining_returns_400( client: AsyncClient, as_user, user, challenge ): @@ -238,12 +412,23 @@ async def test_existing_submission_remains_idempotent_after_deadline( as_user, user, challenge, + questions, db_session, ): c = as_user(user) - await c.post(f"api/v1/challenge/{challenge.id}/join") + joined = await c.post(f"api/v1/challenge/{challenge.id}/join") + assert joined.status_code == 200, joined.text + saved_answers = await c.post( + f"api/v1/challenge/{challenge.id}/answer/all", + json=[ + {"question_id": str(question.id), "answer": question.answer} + for question in questions + ], + ) + assert saved_answers.status_code == 204 first_response = await c.post(f"api/v1/challenge/{challenge.id}/submit") assert first_response.status_code == 200 + assert first_response.json()["submitted_at"] is not None challenge.finishes_at = datetime.now(UTC) - timedelta(seconds=1) await db_session.flush() diff --git a/backend/app/tests/challenges/unit/test_scoring.py b/backend/app/tests/challenges/unit/test_scoring.py index 7763e553..3ad8d713 100644 --- a/backend/app/tests/challenges/unit/test_scoring.py +++ b/backend/app/tests/challenges/unit/test_scoring.py @@ -57,7 +57,7 @@ async def test_process_submission_sums_only_correct_answers( assert score == 150 assert participant.score == 150 - assert participant.submitted_at is not None + assert participant.submitted_at is None async def test_process_submission_ignores_deleted_answers( diff --git a/backend/scripts/seed_mock_data.py b/backend/scripts/seed_mock_data.py index 830dcc68..4db3ca6f 100644 --- a/backend/scripts/seed_mock_data.py +++ b/backend/scripts/seed_mock_data.py @@ -518,7 +518,7 @@ async def seed() -> None: await get_or_create_activity( session, weeks[2026], - code="M001", + code="1001", kind=TipoAtividade.PALESTRA, title="Mock: Abertura e computação", start=now + timedelta(days=1), @@ -529,7 +529,7 @@ async def seed() -> None: await get_or_create_activity( session, weeks[2026], - code="M002", + code="1002", kind=TipoAtividade.WORKSHOP, title="Mock: Laboratório de programação", start=now + timedelta(days=1, hours=2), @@ -541,7 +541,7 @@ async def seed() -> None: await get_or_create_activity( session, weeks[2025], - code="M003", + code="1003", kind=TipoAtividade.COFFEE_BREAK, title="Mock: Intervalo arquivado", start=now - timedelta(days=300), diff --git a/frontend/src/app/semana/(site)/desafios/page.tsx b/frontend/src/app/semana/(site)/desafios/page.tsx new file mode 100644 index 00000000..b8923b36 --- /dev/null +++ b/frontend/src/app/semana/(site)/desafios/page.tsx @@ -0,0 +1,5 @@ +import { ChallengeListPage } from '@/features/challenges/components/challenge-list-page' + +export default function DesafiosPage() { + return +} diff --git a/frontend/src/features/challenges/api.ts b/frontend/src/features/challenges/api.ts index 3ea01eed..d0309601 100644 --- a/frontend/src/features/challenges/api.ts +++ b/frontend/src/features/challenges/api.ts @@ -11,22 +11,66 @@ export type Challenge = { image_url: string | null } +export type ChallengeQuestion = { + id: string + prompt: string + current_answer: string | null +} + +export type ChallengeSubmission = { + submitted_at: string | null + score: number +} + +type ChallengePage = { + items: Challenge[] + total: number + limit: number + offset: number +} + export type ChallengeDetails = Challenge & { - questions: unknown[] + questions: ChallengeQuestion[] is_participant: boolean submitted_at: string | null + score: number | null } export function getChallenge(id: string) { - return requestApi(`/challenge/${id}`) + return requestApi(`/challenge/${id}`, { cache: 'no-store' }) } export function joinChallenge(id: string) { - return requestApi(`/challenge/${id}/join`, { method: 'POST' }) + return requestApi<{ submitted_at: string | null; score: number }>( + `/challenge/${id}/join`, + { method: 'POST' }, + ) +} + +export function listChallenges(limit = 20, offset = 0) { + return requestApi(`/challenge?limit=${limit}&offset=${offset}`, { + cache: 'no-store', + }) +} + +export function saveChallengeAnswers( + id: string, + answers: { question_id: string; answer: string }[], +) { + return requestApi(`/challenge/${id}/answer/all`, { + method: 'POST', + body: JSON.stringify(answers), + }) +} + +export function submitChallenge(id: string) { + return requestApi(`/challenge/${id}/submit`, { + method: 'POST', + }) } export function submitInput(id: string, answer: string) { - return requestApi<{ submitted_at: string; score: number }>(`/challenge/${id}/input`, { + return requestApi(`/challenge/${id}/input`, { method: 'POST', body: JSON.stringify({ answer }), }) diff --git a/frontend/src/features/challenges/components/challenge-list-page.tsx b/frontend/src/features/challenges/components/challenge-list-page.tsx new file mode 100644 index 00000000..547c17c3 --- /dev/null +++ b/frontend/src/features/challenges/components/challenge-list-page.tsx @@ -0,0 +1,161 @@ +'use client' + +import { ArrowUpRight, Clock3, Trophy } from 'lucide-react' +import Image from 'next/image' +import Link from 'next/link' +import { useEffect, useState } from 'react' + +import { SemanaButton } from '@/features/semana/components/semana-button' + +import { listChallenges, mediaUrl, type Challenge } from '../api' + +const PAGE_SIZE = 20 + +const challengeTypeLabels: Record = { + input: 'Resposta livre', + quiz: 'Quiz', + manual: 'Desafio', +} + +const deadlineFormatter = new Intl.DateTimeFormat('pt-BR', { + dateStyle: 'medium', + timeStyle: 'short', + timeZone: 'America/Sao_Paulo', +}) + +export function ChallengeListPage() { + const [challenges, setChallenges] = useState([]) + const [total, setTotal] = useState(0) + const [loading, setLoading] = useState(true) + const [loadingMore, setLoadingMore] = useState(false) + const [error, setError] = useState('') + + useEffect(() => { + let active = true + listChallenges(PAGE_SIZE) + .then((page) => { + if (active) { + setChallenges(page.items) + setTotal(page.total) + } + }) + .catch((reason: Error) => { + if (active) setError(reason.message) + }) + .finally(() => { + if (active) setLoading(false) + }) + + return () => { + active = false + } + }, []) + + async function loadMore() { + setLoadingMore(true) + setError('') + try { + const page = await listChallenges(PAGE_SIZE, challenges.length) + setChallenges((current) => [...current, ...page.items]) + setTotal(page.total) + } catch (reason) { + setError(reason instanceof Error ? reason.message : 'Não foi possível carregar.') + } finally { + setLoadingMore(false) + } + } + + return ( +
+
+

+ Semana da Computação +

+

+ Desafios +

+

+ Explore os desafios e teste seus conhecimentos. +

+
+ + {loading &&

Carregando desafios…

} + {error && ( +

+ {error} +

+ )} + {!loading && !error && !challenges.length &&

Novos desafios em breve.

} + +
+ {challenges.map((challenge) => ( + +
+ {challenge.image_url && ( +
+ +
+ )} +
+
+
+

+ {challengeTypeLabels[challenge.scoring_type]} +

+

+ {challenge.title} +

+
+
+ {(challenge.description || challenge.prompt) && ( +

+ {challenge.description || challenge.prompt} +

+ )} +

+ {challenge.scoring_type === 'quiz' ? ( +

+
+
+ + ))} +
+ + {!loading && challenges.length < total && ( +
+ + {loadingMore ? 'Carregando…' : 'Carregar mais desafios'} + +
+ )} +
+ ) +} diff --git a/frontend/src/features/challenges/components/challenge-page.tsx b/frontend/src/features/challenges/components/challenge-page.tsx index 2e2f42db..19261de8 100644 --- a/frontend/src/features/challenges/components/challenge-page.tsx +++ b/frontend/src/features/challenges/components/challenge-page.tsx @@ -9,6 +9,8 @@ import { useAuth } from '@/features/auth/auth-provider' import { getChallenge, joinChallenge, + saveChallengeAnswers, + submitChallenge, submitInput, type ChallengeDetails, mediaUrl, @@ -22,9 +24,13 @@ export function ChallengePage() { const { user, loading: authLoading } = useAuth() const [challenge, setChallenge] = useState() const [inputAnswer, setInputAnswer] = useState('') + const [answers, setAnswers] = useState>({}) const [busy, setBusy] = useState(false) const [error, setError] = useState() - const [result, setResult] = useState<{ score: number }>() + const [result, setResult] = useState<{ + submitted_at: string | null + score: number + }>() useEffect(() => { if (!authLoading && !user) router.replace('/semana/login') @@ -36,6 +42,14 @@ export function ChallengePage() { .then((data) => { setChallenge(data) setInputAnswer('') + setAnswers( + Object.fromEntries( + data.questions.map((question) => [ + question.id, + question.current_answer ?? '', + ]), + ), + ) }) .catch((err: Error) => { if (err.message.includes('challenge has ended')) { @@ -50,8 +64,17 @@ export function ChallengePage() { setBusy(true) setError(undefined) try { - await joinChallenge(params.id) - setChallenge(await getChallenge(params.id)) + const participant = await joinChallenge(params.id) + setChallenge((current) => + current + ? { + ...current, + is_participant: true, + submitted_at: participant.submitted_at, + score: participant.score, + } + : current, + ) } catch (err) { setError(err instanceof Error ? err.message : 'Não foi possível aceitar o desafio.') } finally { @@ -60,12 +83,35 @@ export function ChallengePage() { } async function submit() { + if (!challenge) return setBusy(true) setError(undefined) + setResult(undefined) try { - setResult(await submitInput(params.id, inputAnswer)) + let submission + if (challenge.scoring_type === 'input') { + submission = await submitInput(params.id, inputAnswer) + } else if (challenge.scoring_type === 'quiz') { + await saveChallengeAnswers( + params.id, + challenge.questions.map((question) => ({ + question_id: question.id, + answer: answers[question.id] ?? '', + })), + ) + submission = await submitChallenge(params.id) + } else { + throw new Error('Este formato de desafio não está disponível.') + } + setResult(submission) setChallenge((current) => - current ? { ...current, submitted_at: new Date().toISOString() } : current, + current + ? { + ...current, + submitted_at: submission.submitted_at, + score: submission.score, + } + : current, ) } catch (err) { setError( @@ -97,6 +143,13 @@ export function ChallengePage() { if (!challenge) return null + const hasQuizAttempt = + challenge.scoring_type === 'quiz' && + challenge.questions.some((question) => question.current_answer !== null) + const showRetryFeedback = + (result !== undefined && result.submitted_at === null) || + (challenge.scoring_type === 'quiz' && !challenge.submitted_at && hasQuizAttempt) + return (
@@ -140,35 +193,76 @@ export function ChallengePage() { {busy ? 'Entrando…' : 'Aceitar desafio'} - ) : challenge.submitted_at || result ? ( + ) : challenge.submitted_at || result?.submitted_at ? (

- Respostas enviadas + {challenge.scoring_type === 'input' + ? 'Resposta correta' + : challenge.scoring_type === 'quiz' + ? 'Quiz concluído' + : 'Respostas enviadas'}

- {result &&

Pontuação: {result.score}

} +

+ Pontuação: {result?.score ?? challenge.score ?? 0} +

) : (
- {challenge.scoring_type !== 'input' ? ( -

- Este formato de desafio ainda não está disponível. + {showRetryFeedback && ( +

+

+ {challenge.scoring_type === 'quiz' + ? 'Ainda há respostas incorretas. Tente novamente.' + : 'Resposta incorreta. Tente novamente.'} +

+ {challenge.scoring_type === 'quiz' && ( +

+ Pontuação parcial: {result?.score ?? challenge.score ?? 0} +

+ )} +
+ )} + {challenge.scoring_type === 'manual' ? ( +

+ Complete o desafio e reporte à equipe para ganhar os seus pontos!

- ) : ( + ) : challenge.scoring_type === 'input' ? ( + ) : challenge.scoring_type === 'quiz' ? ( +
+ {challenge.questions.map((question, index) => ( + + ))} +
+ ) : null} + {challenge.scoring_type !== 'manual' && ( + + {busy ? 'Enviando…' : 'Enviar resposta'} + )} - - {busy ? 'Enviando…' : 'Enviar resposta'} -
)}
diff --git a/frontend/src/features/profile/components/profile-page.tsx b/frontend/src/features/profile/components/profile-page.tsx index cfa7d866..d434a7a9 100644 --- a/frontend/src/features/profile/components/profile-page.tsx +++ b/frontend/src/features/profile/components/profile-page.tsx @@ -103,9 +103,16 @@ export function ProfilePage() { key={semana.semana_id} >
- - {semana.nome} ({semana.ano}) - +
+

+ {semana.nome} ({semana.ano}) +

+ {semana.nickname && ( +

+ Apelido: {semana.nickname} +

+ )} +
{semana.pontos} pts · {semana.horas}h diff --git a/frontend/src/features/semana/api.ts b/frontend/src/features/semana/api.ts index 14068c4b..30d39928 100644 --- a/frontend/src/features/semana/api.ts +++ b/frontend/src/features/semana/api.ts @@ -19,6 +19,7 @@ export type Participation = { semana_id: number nome: string ano: number + nickname: string | null pontos: number horas: number }[] diff --git a/frontend/src/features/semana/components/semana-shell.tsx b/frontend/src/features/semana/components/semana-shell.tsx index 93a10e34..da2e4a92 100644 --- a/frontend/src/features/semana/components/semana-shell.tsx +++ b/frontend/src/features/semana/components/semana-shell.tsx @@ -25,6 +25,7 @@ const links = [ { href: '/semana', label: 'Início' }, { href: '/semana/cronograma', label: 'Programação' }, { href: '/semana/presenca', label: 'Presença' }, + { href: '/semana/desafios', label: 'Desafios' }, { href: '/semana/patrocinadores', label: 'Patrocinadores' }, { href: '/semana/sobre-nos', label: 'Sobre nós' }, ]