This repository was archived by the owner on Oct 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-8
lines changed
src/Twig/Components/Challenge
templates/components/Challenge Expand file tree Collapse file tree 3 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,10 @@ export default class extends Controller<HTMLElement> {
2525 throw new Error ( `Element not found: ${ editorSelector } ` ) ;
2626 }
2727
28+ const lastQuery = this . element . dataset [ "lastQuery" ] ;
29+
2830 this . view = new EditorView ( {
31+ doc : lastQuery ,
2932 extensions : [
3033 basicSetup ,
3134 sql ( ) ,
Original file line number Diff line number Diff line change 88use App \Entity \SolutionEvent ;
99use App \Entity \SolutionEventStatus ;
1010use App \Entity \User ;
11+ use App \Repository \SolutionEventRepository ;
1112use App \Service \QuestionDbRunnerService ;
1213use Doctrine \ORM \EntityManagerInterface ;
1314use Symfony \Component \HttpKernel \Exception \HttpException ;
@@ -26,6 +27,7 @@ final class Executor
2627
2728 public function __construct (
2829 private readonly QuestionDbRunnerService $ questionDbRunnerService ,
30+ private readonly SolutionEventRepository $ solutionEventRepository ,
2931 private readonly EntityManagerInterface $ entityManager ,
3032 ) {
3133 }
@@ -42,6 +44,16 @@ public function __construct(
4244 #[LiveProp(writable: true )]
4345 public string $ query ;
4446
47+ public function getPreviousQuery (): string
48+ {
49+ $ se = $ this ->solutionEventRepository ->findOneBy ([
50+ 'question ' => $ this ->question ,
51+ 'submitter ' => $ this ->user ,
52+ ], orderBy: ['id ' => 'DESC ' ]);
53+
54+ return $ se ?->getQuery() ?? '' ;
55+ }
56+
4557 #[LiveAction]
4658 public function execute (SerializerInterface $ serializer ): void
4759 {
Original file line number Diff line number Diff line change 1+ {% set previousQuery = this .previousQuery %}
2+
13<section {{ attributes.defaults ({class : ' challenge-sql-executor' }| merge(stimulus_controller(' challenge-executor' , {
24 modelName : ' query' ,
35 editorSelector : ' .challenge-sql-executor__editor' ,
4- }))) }}>
6+ }))) }} data-last-query = " {{ previousQuery }} " >
57 <section class =" challenge-sql-executor__actions hstack" >
68 <div class =" challenge-sql-executor__actions__left me-auto" >
79 {% block actions %}{% endblock %}
810 </div >
911
1012 <div class =" challenge-sql-executor__actions__right" >
11- <button type =" button" class =" btn btn-primary"
12- data-loading =" action(execute)|addAttribute(disabled)"
13- data-action =" live#action"
14- data-live-action-param =" execute" >
15- <i class =" bi bi-send" ></i >
16- 提交
17- </button >
13+ {% if query is not empty and query is not same as (previousQuery ) %}
14+ <button type =" button" class =" btn btn-primary"
15+ data-loading =" action(execute)|addAttribute(disabled)"
16+ data-action =" live#action"
17+ data-live-action-param =" execute" >
18+ <i class =" bi bi-send" ></i >
19+ 提交
20+ </button >
21+ {% else %}
22+ <button type =" button" class =" btn btn-primary" disabled >
23+ <i class =" bi bi-send" ></i >
24+ 提交
25+ </button >
26+ {% endif %}
1827 </div >
1928 </section >
2029 <hr >
You can’t perform that action at this time.
0 commit comments