|
12 | 12 | @using EditorOptions = LearnJsonEverything.Services.EditorOptions
|
13 | 13 |
|
14 | 14 | @inject DataManager DataManager;
|
15 |
| -@inject NavigationManager NavigationManager; |
16 | 15 | @inject IJSRuntime JsRuntime;
|
17 | 16 | @inject HttpClient Client;
|
18 | 17 |
|
19 | 18 | <div id="layout" class="row fill-remaining row-margin-reset">
|
20 |
| - <div class="col-4 d-flex"> |
21 |
| - <div class="grid-panel flex-grow-1"> |
| 19 | + <div class="col-2 d-flex h-100"> |
| 20 | + <div class="grid-panel flex-grow-1 scroll"> |
| 21 | + <ul role="listbox"> |
| 22 | + @foreach (var lesson in _lessons) |
| 23 | + { |
| 24 | + <li id="@lesson.Id" role="option" @onclick="() => SelectLesson(lesson.Id)"> |
| 25 | + <span class="@(lesson.Achieved ? "" : "invisible")">@Iconography.SuccessIcon</span> |
| 26 | + @lesson.Title |
| 27 | + </li> |
| 28 | + } |
| 29 | + </ul> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + <div class="col-4 d-flex h-100"> |
| 33 | + <div class="grid-panel flex-grow-1 scroll"> |
22 | 34 | <MarkdownSpan Content="@Instructions"></MarkdownSpan>
|
23 | 35 | </div>
|
24 | 36 | </div>
|
25 |
| - <div class="col-8 d-flex"> |
| 37 | + <div class="col-6 d-flex"> |
26 | 38 | <div id="right-panel" class="row row-margin-reset flex-grow-1">
|
27 | 39 | <div id="workspace" class="col-12 d-flex flex-grow-1">
|
28 | 40 | <div class="grid-panel flex-grow-1">
|
|
32 | 44 | </div>
|
33 | 45 | <div id="controls" class="col-12">
|
34 | 46 | <div class="d-flex">
|
| 47 | + <button class="btn btn-primary m-1" @onclick="PreviousLesson">< Previous</button> |
35 | 48 | <button class="btn btn-primary m-1" @onclick="Run">Run</button>
|
36 |
| - <button class="btn btn-primary m-1">content</button> |
37 |
| - <button class="btn btn-primary m-1">content</button> |
| 49 | + <button class="btn btn-primary m-1" disabled="@_nextButtonDisabled" @onclick="NextLesson">Next ></button> |
38 | 50 | </div>
|
39 | 51 | </div>
|
40 | 52 | <div id="output" class="col-12 d-flex">
|
|
48 | 60 | </div>
|
49 | 61 |
|
50 | 62 | @code {
|
51 |
| -#pragma warning disable CS8618 |
| 63 | + #pragma warning disable CS8618 |
52 | 64 | private StandaloneCodeEditor _codeEditor;
|
53 | 65 | private StandaloneCodeEditor _outputEditor;
|
54 |
| - private LessonPlan _lessons; |
| 66 | + private LessonPlan _lessons = new([]); |
55 | 67 | private LessonData? _currentLesson;
|
| 68 | + private bool _nextButtonDisabled = true; |
56 | 69 |
|
57 | 70 | [Parameter]
|
58 | 71 | public string LessonSource { get; set; }
|
|
69 | 82 | {
|
70 | 83 | var userCode = await _codeEditor.GetValue();
|
71 | 84 |
|
72 |
| - await _outputEditor.SetValue(""); |
| 85 | + await _outputEditor.SetValue(string.Empty); |
| 86 | + |
73 | 87 | var results = SchemaRunner.Run(userCode, _currentLesson!);
|
| 88 | + |
74 | 89 | await _outputEditor.SetValue(string.Join(Environment.NewLine, results!));
|
| 90 | + _nextButtonDisabled = !CanMoveToNextLesson(); |
75 | 91 | }
|
76 | 92 | catch (Exception e)
|
77 | 93 | {
|
|
80 | 96 | }
|
81 | 97 | }
|
82 | 98 |
|
83 |
| - private void PreviousLesson() |
| 99 | + private Task PreviousLesson() |
84 | 100 | {
|
85 | 101 | _currentLesson = _lessons.GetPrevious(_currentLesson?.Id);
|
86 |
| - LoadLesson(); |
| 102 | + return LoadLesson(); |
87 | 103 | }
|
88 | 104 |
|
89 |
| - private void NextLesson() |
| 105 | + private Task NextLesson() |
90 | 106 | {
|
91 | 107 | _currentLesson = _lessons.GetNext(_currentLesson?.Id);
|
92 |
| - LoadLesson(); |
| 108 | + return LoadLesson(); |
93 | 109 | }
|
94 | 110 |
|
95 |
| - private void Reset() |
| 111 | + private Task Reset() |
96 | 112 | {
|
97 |
| - LoadLesson(); |
| 113 | + return LoadLesson(); |
98 | 114 | }
|
99 | 115 |
|
100 |
| - private void LoadLesson() |
| 116 | + private Task LoadLesson() |
101 | 117 | {
|
102 | 118 | _currentLesson ??= _lessons[0];
|
103 | 119 | Instructions = SchemaRunner.BuildInstructions(_currentLesson);
|
| 120 | + _nextButtonDisabled = !CanMoveToNextLesson(); |
| 121 | + return _outputEditor.SetValue(string.Empty); |
| 122 | + } |
| 123 | + |
| 124 | + private bool CanMoveToNextLesson() |
| 125 | + { |
| 126 | + if (_currentLesson is null) return false; |
| 127 | + if (_currentLesson.Index == _lessons.Count - 1) return false; |
| 128 | + return _currentLesson.Achieved; |
104 | 129 | }
|
105 | 130 |
|
106 | 131 | protected override async Task OnInitializedAsync()
|
107 | 132 | {
|
108 |
| - _ = await CompilationHelpers.LoadAssemblyReferences(Client); |
109 | 133 | await DownloadLessonPlan();
|
110 | 134 |
|
111 |
| - LoadLesson(); |
| 135 | + await LoadLesson(); |
112 | 136 |
|
113 | 137 | await base.OnInitializedAsync();
|
114 | 138 | }
|
|
121 | 145 | Console.WriteLine(json.AsJsonString());
|
122 | 146 | _lessons = json.Deserialize(SerializerContext.Default.LessonPlan)!;
|
123 | 147 | }
|
| 148 | + |
| 149 | + private async Task SelectLesson(Guid lessonId) |
| 150 | + { |
| 151 | + var index = _currentLesson?.Index ?? 0; |
| 152 | + if (index == 0 || _lessons[index - 1].Achieved) |
| 153 | + { |
| 154 | + _currentLesson = _lessons[lessonId]; |
| 155 | + await LoadLesson(); |
| 156 | + } |
| 157 | + } |
124 | 158 | }
|
0 commit comments