Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 3bb0b75

Browse files
committed
fix(challenge): Correct hint implementation
The query will not update to Live Component model now, so we should get the query from the last query. Besides, I remove the writable query model as it is completely unused now.
1 parent 9f29f67 commit 3bb0b75

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/Twig/Components/Challenge/Instruction/Content.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace App\Twig\Components\Challenge\Instruction;
66

7-
use Psr\Log\LoggerInterface;
8-
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
7+
use Symfony\Component\Serializer\SerializerInterface;
98
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
109
use Symfony\UX\LiveComponent\Attribute\LiveArg;
1110
use Symfony\UX\LiveComponent\Attribute\LiveListener;
@@ -21,9 +20,9 @@ final class Content
2120
public ?HintPayload $hint = null;
2221

2322
#[LiveListener('app:challenge-hint')]
24-
public function onHintReceived(LoggerInterface $logger, #[LiveArg] #[MapRequestPayload] HintPayload $hint): void
23+
public function onHintReceived(SerializerInterface $serializer, #[LiveArg] string $hint): void
2524
{
26-
$logger->debug('Received hint', ['hint' => $hint]);
27-
$this->hint = $hint;
25+
$deserializedHint = $serializer->deserialize($hint, HintPayload::class, 'json');
26+
$this->hint = $deserializedHint;
2827
}
2928
}

src/Twig/Components/Challenge/Instruction/Modal.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\HintOpenEvent;
88
use App\Entity\Question;
99
use App\Entity\User;
10+
use App\Repository\SolutionEventRepository;
1011
use App\Service\DbRunnerService;
1112
use App\Service\PointCalculationService;
1213
use App\Service\PromptService;
@@ -33,9 +34,6 @@ final class Modal
3334
#[LiveProp]
3435
public Question $question;
3536

36-
#[LiveProp(updateFromParent: true)]
37-
public string $query = '';
38-
3937
public function getCost(): int
4038
{
4139
return PointCalculationService::hintOpenEventPoint;
@@ -48,6 +46,7 @@ public function getCost(): int
4846
*/
4947
#[LiveAction]
5048
public function instruct(
49+
SolutionEventRepository $solutionEventRepository,
5150
DbRunnerService $dbRunnerService,
5251
PromptService $promptService,
5352
TranslatorInterface $translator,
@@ -62,7 +61,8 @@ public function instruct(
6261
throw new BadRequestHttpException('Hint feature is disabled.');
6362
}
6463

65-
if ('' === $this->query) {
64+
$query = $solutionEventRepository->getLatestQuery($this->question, $this->currentUser);
65+
if (null === $query) {
6666
return;
6767
}
6868

@@ -72,7 +72,7 @@ public function instruct(
7272
$hintOpenEvent = (new HintOpenEvent())
7373
->setOpener($this->currentUser)
7474
->setQuestion($this->question)
75-
->setQuery($this->query);
75+
->setQuery($query->getQuery());
7676

7777
// run answer. if it failed, we should consider it an error
7878
try {
@@ -87,13 +87,13 @@ public function instruct(
8787

8888
try {
8989
// run query to get the error message (or compare the result)
90-
$result = $dbRunnerService->runQuery($schema, $this->query);
90+
$result = $dbRunnerService->runQuery($schema, $query->getQuery());
9191
} catch (\Throwable $e) {
92-
$hint = $promptService->hint($this->query, $e->getMessage(), $answer);
92+
$hint = $promptService->hint($query->getQuery(), $e->getMessage(), $answer);
9393
}
9494

9595
if (isset($result) && $result !== $answerResult) {
96-
$hint = $promptService->hint($this->query, 'Different output', $answer);
96+
$hint = $promptService->hint($query->getQuery(), 'Different output', $answer);
9797
}
9898

9999
if (!isset($hint)) {

src/Twig/Components/Challenge/Ui.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,4 @@ final class Ui
2323

2424
#[LiveProp]
2525
public int $limit;
26-
27-
/**
28-
* @var string $query the user's query
29-
*/
30-
#[LiveProp(writable: true)]
31-
public string $query = '';
3226
}

templates/components/Challenge/Ui.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<twig:Challenge:SolutionVideoModal class="challenge-solution-video-modal" :question="question" :user="user" />
55
{% endif %}
66
{% if appfeatures.hint %}
7-
<twig:Challenge:Instruction:Modal class="challenge-instruction-modal" :question="question" :currentUser="user" :query="query" />
7+
<twig:Challenge:Instruction:Modal class="challenge-instruction-modal" :question="question" :currentUser="user" />
88
{% endif %}
99

1010
<main>
1111
<twig:Challenge:Header class="mb-2" :question="question" :limit="limit" :user="user" />
1212
<hr class="opacity-50">
1313
<section class="app-challenge-primary row g-4">
1414
<div class="app-challenge-primary__left col-12 col-md-6">
15-
<twig:Challenge:Executor class="mt-2" data-model="query:query" :question="question" :user="user">
15+
<twig:Challenge:Executor class="mt-2" :question="question" :user="user">
1616
<twig:block name="actions">
1717
<div class="btn-group">
1818
{% if appfeatures.hint %}

0 commit comments

Comments
 (0)