Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSee.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page "/test/client/saywhatyouee"
@using QuizModels = QuizExperiment.Models.Client
@layout QuizExperiment.Admin.Client.Shared.Client.Layout

<QuizExperiment.Admin.Client.Shared.Client.SayWhatYouSeeQuestion Question="@_currentQuestion"
OnAnswerSubmit="@AnswerQuestion" />

@code {
private QuizModels.ClientSayWhatYouSeeQuestion _currentQuestion = new QuizModels.ClientSayWhatYouSeeQuestion
{
Title = "This is a test Question, it goes on a bit, in fact it goes on for ages and ages and ages",
ImageUrl = "https://placehold.co/600x400"
};

private void AnswerQuestion(QuizModels.ClientAnswer answer)
{
Console.WriteLine($"User answered: {answer}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@page "/test/client/answersummary/saywhatyousee"
@using QuizModels = QuizExperiment.Models.Client
@layout QuizExperiment.Admin.Client.Shared.Client.Layout

<QuizExperiment.Admin.Client.Shared.Client.AnswerSummary MyAnswer="@myAnswer"
Question="@question"
IsLastQuestion="false"
CorrectAnswer="@correctAnswer"
CurrentScore="0"
Position="1"
/>

@code {
QuizModels.ClientSayWhatYouSeeAnswer myAnswer = new QuizModels.ClientSayWhatYouSeeAnswer
{
Answers = new List<string>
{
"Dog"
}
};

QuizModels.ClientSayWhatYouSeeQuestion question = new QuizModels.ClientSayWhatYouSeeQuestion
{
Title = "This is a test Question, it goes on a bit, in fact it goes on for ages and ages and ages",
ImageUrl = "https://imgur.com/NkMONh3",

};

QuizModels.ClientSayWhatYouSeeAnswer correctAnswer = new QuizModels.ClientSayWhatYouSeeAnswer
{
Answers = new List<string>
{
"One",
"Two",
"Three"
}
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@page "/test/present/saywhatyousee"
@using QuizModels = QuizExperiment.Models
@layout QuizExperiment.Admin.Client.Shared.Client.Layout

<QuizExperiment.Admin.Client.Shared.Present.SayWhatYouSeeQuestion Question="@_currentQuestion" QuestionEndTime="@QuestionEndTime" UserAnswerCount="@UserAnswerCount" />

@code {

private DateTime QuestionEndTime => DateTime.Now.AddMinutes(10);
private int UserAnswerCount => 0; // Placeholder for user answer count
private QuizModels.SayWhatYouSeeQuestion _currentQuestion = new QuizModels.SayWhatYouSeeQuestion
{
Title = "This is a test Question, it goes on a bit, in fact it goes on for ages and ages and ages",
ImageUrl = "https://placehold.co/600x400"
};

private void AnswerQuestion(QuizModels.Client.ClientAnswer answer)
{
Console.WriteLine($"User answered: {answer}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
<TrueFalseQuestion Question="@trueFalseQuestion" OnAnswerSubmit="@OnAnswerSubmit" />
}
else if(Question is ClientSayWhatYouSeeQuestion sayWhatYouSeeQuestion)
{
<SayWhatYouSeeQuestion Question="@sayWhatYouSeeQuestion" OnAnswerSubmit="@OnAnswerSubmit" />
}
else
{
<p class="text-warning">Unsupported question type.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@using QuizExperiment.Models.Client

@{
if(Question != null)
{
<div class="d-flex flex-column min-vh-100 justify-content-center align-items-center quiz-page">
<h1 class="h1 text-center px-3">@Question.Title</h1>
<img class="img-fluid rounded img-quiz my-3 px-3" src="@Question.ImageUrl" />
<div class="quiz-button-container swys-container d-flex flex-column align-items-center w-100 px-3" style="max-width: 400px;">
<input type="text" class="form-control quiz-edit-question-input-answer mb-2" placeholder="Type your answer..." @bind="UserAnswer" @bind:event="oninput" id="userAnswerInput" />
<button class="btn btn-success btn-primary-action w-100" @onclick="SubmitAnswer">Submit</button>
</div>
</div>
}
}

@code {
[Parameter]
public ClientSayWhatYouSeeQuestion? Question { get; set; }

[Parameter]
public EventCallback<ClientAnswer> OnAnswerSubmit { get; set; }

private string UserAnswer { get; set; } = string.Empty;

private async Task SubmitAnswer()
{
var answer = new ClientSayWhatYouSeeAnswer
{
Answers = new List<string> { UserAnswer }
};
await OnAnswerSubmit.InvokeAsync(answer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<span>True / False</span>
</button>
</div>
<div class="text-center">
<button class="btn btn-outline-success" @onclick="SayWhatYouSeeClicked">
<span class="oi oi-pencil" style="font-size:2rem;"></span><br />
<span>Type the Answer</span>
</button>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
Expand Down Expand Up @@ -49,6 +55,10 @@
{
await SelectType("trueFalse");
}
private async Task SayWhatYouSeeClicked()
{
await SelectType("sayWhatYouSee");
}
private async Task SelectType(string type)
{
IsVisible = false;
Expand Down
34 changes: 23 additions & 11 deletions QuizExperiment.Admin/Client/Shared/Edit/RootComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
{
<TrueFalseQuestion Question="_currentQuestion" />
}
else if (_currentQuestion is QuizModels.SayWhatYouSeeQuestion)
{
<SayWhatYouSeeQuestion Question="_currentQuestion" />
}
else
{
<div class="d-flex flex-column align-items-center">
Expand Down Expand Up @@ -133,27 +137,30 @@

private void OnAddQuestion(string questionType)
{
Question newQuestion;
if (questionType == "trueFalse")
Question newQuestion = questionType switch
{
newQuestion = new QuizModels.TrueFalseQuestion()
"trueFalse" => new QuizModels.TrueFalseQuestion()
{
Timeout = 20,
ImageUrl = "",
Title = ""
};
}
else // default to multipleChoice
{
newQuestion = new QuizModels.MultipleChoiceQuestion()
},
"sayWhatYouSee" => new QuizModels.SayWhatYouSeeQuestion()
{
Timeout = 40,
ImageUrl = "",
Title = "",
// Add any other default properties for SayWhatYouSeeQuestion here
},
_ => new QuizModels.MultipleChoiceQuestion()
{
Options = new[] {"","","",""},
Timeout = 20,
ImageUrl = "",
Title = "",
CorrectAnswerIndex = -1
};
}
}
};
_questions.Add(newQuestion);
_currentQuestion = newQuestion;
}
Expand Down Expand Up @@ -224,13 +231,18 @@

private async Task SaveAndPresent()
{
var query_string = "";
if (!string.IsNullOrWhiteSpace(FolderPath))
{
query_string = "?path=" + FolderPath;
}
if (!AreAllQuestionsValid)
{
ShowValidationAlertMessage();
return;
}
await Save();
NavigationManager.NavigateTo($"/present/{_questionSet?.Id}");
NavigationManager.NavigateTo($"/present/{_questionSet?.Id}{query_string}");
}

private async Task SaveAndContinue()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@using QuizModels = QuizExperiment.Models
@using System.Text.Json
@inject HttpClient Http

@if (Question is not null)
{
var sayWhatYouSeeQuestion = Question as QuizModels.SayWhatYouSeeQuestion;
if (sayWhatYouSeeQuestion is not null)
{
// Ensure Answers is initialized
if (sayWhatYouSeeQuestion.Answers == null)
{
sayWhatYouSeeQuestion.Answers = new List<string>();
}
<CommonQuestion Question="Question" />
<div class="quiz-edit-question-answers-table-container flex-fill flex-grow-1">
<table class="table table-bordered quiz-edit-question-answers-table">
<thead>
<tr>
<th style="width: 90%">ANSWER</th>
<th style="width: 10%"></th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < sayWhatYouSeeQuestion.Answers.Count; i++)
{
var answer = sayWhatYouSeeQuestion.Answers[i];
var index = i; // capture the current value of i
<tr>
<td class="quiz-edit-question-answers-table-answer">
<input type="text" class="form-control quiz-edit-question-input-answer"
placeholder="Possible answer..." required="required"
value="@answer"
@oninput="e => UpdateAnswer(index, e)" />
</td>
<td>
<button type="button" class="btn btn-danger" title="Remove answer" @onclick="() => RemoveAnswer(index)">✕</button>
</td>
</tr>
}
</tbody>
</table>
<button type="button" class="btn btn-primary" @onclick="AddAnswer">Add Answer</button>
</div>
}
}

@code {
[Parameter]
public QuizModels.Question? Question { get; set; }

private void AddAnswer()
{
if (Question is QuizModels.SayWhatYouSeeQuestion swysq)
{
if (swysq.Answers == null)
swysq.Answers = new List<string>();
swysq.Answers.Add("");
StateHasChanged();
}
}

private void RemoveAnswer(int index)
{
if (Question is QuizModels.SayWhatYouSeeQuestion swysq && swysq.Answers != null && index >= 0 && index < swysq.Answers.Count)
{
swysq.Answers.RemoveAt(index);
StateHasChanged();
}
}

private void UpdateAnswer(int index, ChangeEventArgs e)
{
if (Question is QuizModels.SayWhatYouSeeQuestion swysq && swysq.Answers != null && index >= 0 && index < swysq.Answers.Count)
{
swysq.Answers[index] = e.Value?.ToString() ?? string.Empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

var correctAnswerPercentage = ((int)Math.Round(totalAnswers > 0 ? (double)correctAnswerCount / totalAnswers * 100 : 0, 0)).ToString() + "%";
var fastestUserId = UserAnswers?.Where(r => r.Value.Answer == correctAnswer).OrderBy(r => r.Value.TimeTaken).FirstOrDefault();
var fastestUser = Users[fastestUserId?.Key];
var fastestUser = "";
if (fastestUserId != null && fastestUserId?.Key != null && Users.ContainsKey(fastestUserId?.Key))
{
fastestUser = Users[fastestUserId?.Key];
}


}

Expand All @@ -25,19 +30,27 @@
</button>
</div>
<div class="my-3 fs-4">The correct answer is</div>
<button class="btn btn-correct-answer btn-answer-@correctAnswerIndex" value="@correctButtonName"><span>@correctButtonName</span></button>
@if (!string.IsNullOrWhiteSpace(correctButtonName))
{
<button class="btn btn-correct-answer btn-answer-@correctAnswerIndex" value="@correctButtonName"><span>@correctButtonName</span></button>
}

@if(string.Compare(correctButtonName, correctAnswerText, true) != 0)
{
<div class="my-3 fs-2 fw-bold">@correctAnswerText</div>
}

@{
<div class="my-3 fs-3 fw-bold">@correctAnswerPercentage of people got the correct answer</div>
if(fastestUserId != null)
if (fastestUserId != null && fastestUserId?.Key != null)
{
<div class="my-3 fs-3 fw-bold">@correctAnswerPercentage of people got the correct answer</div>
<div class="my-3 fs-3 fw-bold">🏎️@fastestUser was the fastest!🏁</div>
}

else
{
<div class="my-3 fs-3 fw-bold">No one got the correct answer</div>
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
<QuizExperiment.Admin.Client.Shared.Present.TrueFalseQuestion Question="@trueFalseQuestion" QuestionEndTime="@QuestionEndTime" UserAnswerCount="@UserAnswerCount" />
}
else if (Question is QuizModels.SayWhatYouSeeQuestion sayWhatYouSeeQuestion)
{
<QuizExperiment.Admin.Client.Shared.Present.SayWhatYouSeeQuestion Question="@sayWhatYouSeeQuestion" QuestionEndTime="@QuestionEndTime" UserAnswerCount="@UserAnswerCount" />
}
else
{
<p class="text-warning">Unsupported question type.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@using QuizModels = QuizExperiment.Models

@{
if(Question != null)
{
<div class="d-flex flex-column min-vh-100 justify-content-center align-items-center quiz-page">
<div class="question-progress-container">
<div class="question-player-count">
<div class="fs-4">PLAYERS ANSWERED</div>
<div class="fs-4">@UserAnswerCount</div>
</div>
<CountDownTimer EndDate="@QuestionEndTime" />
</div>
<div class="question-container d-flex flex-column justify-content-center align-items-center">
<div class="quiz-admin-question-title my-3 fs-1 fw-bold px-3 text-center">@Question.Title</div>
<img class="img-fluid rounded img-quiz" src="@Question.ImageUrl" />
</div>
</div>
}
}

@code {
[Parameter]
public QuizModels.SayWhatYouSeeQuestion? Question { get; set; }

[Parameter]
public DateTime QuestionEndTime { get; set; }

[Parameter]
public int UserAnswerCount { get; set; }
}
Loading
Loading