mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
quiz form still works
This commit is contained in:
@@ -4,11 +4,16 @@
|
||||
[Parameter, EditorRequired]
|
||||
public LocalQuizQuestionAnswer Answer { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public int AnswerIndex { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public int QuestionIndex { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public LocalQuizQuestion Question { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Action<LocalQuizQuestionAnswer> SaveAnswer { get; set; } = (_) => {};
|
||||
public Action<LocalQuizQuestionAnswer, int> SaveAnswer { get; set; } = (_, _) => {};
|
||||
|
||||
private string label => "question_" + QuestionIndex + "_answer_" + AnswerIndex;
|
||||
private string _text { get; set; } = string.Empty;
|
||||
private string text
|
||||
{
|
||||
@@ -16,7 +21,7 @@
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
SaveAnswer(Answer with { Text = _text });
|
||||
SaveAnswer(Answer with { Text = _text }, AnswerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +34,7 @@
|
||||
|
||||
private void handleOneAnswerChange()
|
||||
{
|
||||
SaveAnswer(Answer with {Correct = !Answer.Correct});
|
||||
SaveAnswer(Answer with {Correct = !Answer.Correct}, AnswerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,14 +48,12 @@
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="@("answer_" + Answer.Id)"
|
||||
id="@label"
|
||||
checked="@Answer.Correct"
|
||||
@onchange="@(() => handleOneAnswerChange())"
|
||||
>
|
||||
<label
|
||||
class="form-check-label"
|
||||
for="@("answer_" + Answer.Id)"
|
||||
>
|
||||
class="form-check-label" for="@label">
|
||||
Is Correct
|
||||
</label>
|
||||
</div>
|
||||
@@ -61,16 +64,13 @@
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="radio"
|
||||
name="@("correct_answer_" + Question.Id)"
|
||||
id="@("answer_" + Answer.Id)"
|
||||
id="@label"
|
||||
checked="@Answer.Correct"
|
||||
|
||||
@onchange="@(() => handleOneAnswerChange())"
|
||||
>
|
||||
<label
|
||||
class="form-check-label"
|
||||
for="@("answer_" + Answer.Id)"
|
||||
>
|
||||
class="form-check-label" for="@label">
|
||||
Is Correct
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -145,10 +145,11 @@
|
||||
</div>
|
||||
<QuizSettings />
|
||||
|
||||
@foreach(var question in quizContext.Quiz.Questions)
|
||||
@foreach(var (question, i) in quizContext.Quiz.Questions.Select((q, i) => (q, i)))
|
||||
{
|
||||
<QuizQuestionForm
|
||||
@key="@question.Id"
|
||||
Index="i"
|
||||
Question="question"
|
||||
UpdateQuestion="updateQuestion"
|
||||
/>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
[Parameter, EditorRequired]
|
||||
public LocalQuizQuestion Question { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public int Index { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public Action<LocalQuizQuestion> UpdateQuestion { get; set; } = (_) => {};
|
||||
|
||||
protected override void OnParametersSet()
|
||||
@@ -57,8 +59,7 @@
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newAnswer = new LocalQuizQuestionAnswer
|
||||
{ Id = Guid.NewGuid().ToString() };
|
||||
var newAnswer = new LocalQuizQuestionAnswer();
|
||||
|
||||
answers = answers.Append(newAnswer);
|
||||
UpdateQuestion(Question with { Answers = answers });
|
||||
@@ -69,29 +70,26 @@
|
||||
{
|
||||
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newAnswer = new LocalQuizQuestionAnswer
|
||||
{ Id = Guid.NewGuid().ToString() };
|
||||
|
||||
{
|
||||
answers = answers.Take(Question.Answers.Count() - 1);
|
||||
UpdateQuestion(Question with { Answers = answers });
|
||||
}
|
||||
}
|
||||
|
||||
private void saveAnswer(LocalQuizQuestionAnswer newAnswer)
|
||||
private void saveAnswer(LocalQuizQuestionAnswer newAnswer, int index)
|
||||
{
|
||||
if(questionType == QuestionType.MULTIPLE_CHOICE && newAnswer.Correct)
|
||||
{
|
||||
answers = answers.Select(a =>
|
||||
a.Id == newAnswer.Id
|
||||
answers = answers.Select((a, i) =>
|
||||
index == i
|
||||
? newAnswer
|
||||
: a with { Correct = false }
|
||||
).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
answers = answers.Select(a =>
|
||||
a.Id == newAnswer.Id
|
||||
answers = answers.Select((a, i) =>
|
||||
index == i
|
||||
? newAnswer
|
||||
: a
|
||||
).ToArray();
|
||||
@@ -173,11 +171,13 @@
|
||||
+ Add Answer
|
||||
</button>
|
||||
|
||||
@foreach(var answer in answers)
|
||||
@foreach(var (answer, i) in answers.Select((a, i) => (a, i)))
|
||||
{
|
||||
<EditableQuizAnswer
|
||||
Answer="answer"
|
||||
SaveAnswer="saveAnswer"
|
||||
AnswerIndex="i"
|
||||
QuestionIndex="Index"
|
||||
SaveAnswer="saveAnswer"
|
||||
Question="Question"
|
||||
/>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user