mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
122 lines
2.4 KiB
Plaintext
122 lines
2.4 KiB
Plaintext
@using Management.Web.Shared.Components
|
|
|
|
@inject QuizEditorContext quizContext
|
|
|
|
|
|
@code {
|
|
private Modal? modal { get; set; }
|
|
|
|
private LocalQuiz testQuiz;
|
|
|
|
private string? error { get; set; } = null;
|
|
private string _quizMarkdownInput { get; set; } = "";
|
|
private string quizMarkdownInput
|
|
{
|
|
get => _quizMarkdownInput;
|
|
set
|
|
{
|
|
_quizMarkdownInput = value;
|
|
|
|
try
|
|
{
|
|
var newQuiz = LocalQuiz.ParseMarkdown(_quizMarkdownInput);
|
|
error = null;
|
|
testQuiz = newQuiz;
|
|
quizContext.SaveQuiz(newQuiz);
|
|
}
|
|
catch(QuizMarkdownParseException e)
|
|
{
|
|
error = e.Message;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
quizContext.StateHasChanged += reload;
|
|
}
|
|
private void reload()
|
|
{
|
|
if (quizContext.Quiz != null)
|
|
{
|
|
if(quizMarkdownInput == "")
|
|
{
|
|
quizMarkdownInput = quizContext.Quiz.ToMarkdown();
|
|
}
|
|
modal?.Show();
|
|
this.InvokeAsync(this.StateHasChanged);
|
|
}
|
|
}
|
|
public void Dispose()
|
|
{
|
|
quizContext.StateHasChanged -= reload;
|
|
}
|
|
|
|
private void deleteQuiz()
|
|
{
|
|
quizContext.DeleteQuiz();
|
|
modal?.Hide();
|
|
}
|
|
|
|
private async Task addToCanvas()
|
|
{
|
|
await quizContext.AddQuizToCanvas();
|
|
}
|
|
|
|
private void onHide()
|
|
{
|
|
_quizMarkdownInput = "";
|
|
quizContext.Quiz = null;
|
|
}
|
|
}
|
|
|
|
<Modal @ref="modal" OnHide="onHide" >
|
|
<Title>
|
|
<div class="row justify-content-between">
|
|
<div class="col-auto">
|
|
@quizContext.Quiz?.Name
|
|
</div>
|
|
<div class="col-auto me-3">
|
|
Points: @quizContext.Quiz?.Questions.Sum(q => q.Points)
|
|
</div>
|
|
</div>
|
|
</Title>
|
|
<Body>
|
|
<div class="row">
|
|
<div class="col-6">
|
|
<textarea
|
|
rows="30"
|
|
class="form-control"
|
|
@bind="quizMarkdownInput"
|
|
@bind:event="oninput"
|
|
/>
|
|
</div>
|
|
<div class="col-6">
|
|
@if(error != null)
|
|
{
|
|
<p class="text-danger text-truncate">Error: @error</p>
|
|
}
|
|
<QuizPreview Quiz="testQuiz" />
|
|
</div>
|
|
</div>
|
|
</Body>
|
|
<Footer>
|
|
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirm="deleteQuiz" />
|
|
|
|
|
|
<button
|
|
class="btn btn-outline-secondary"
|
|
@onclick="addToCanvas"
|
|
>
|
|
Add to Canvas
|
|
</button>
|
|
<button
|
|
class="btn btn-primary"
|
|
@onclick="() => modal?.Hide()"
|
|
>
|
|
Done
|
|
</button>
|
|
</Footer>
|
|
</Modal>
|