From ce4a832aee5f208234ce27511f6f4da4fb976aa2 Mon Sep 17 00:00:00 2001 From: Matthew Fortunka <1851394+fortunkam@users.noreply.github.com> Date: Fri, 13 Jun 2025 17:07:33 +0100 Subject: [PATCH 1/5] Add "Say What You See" question type support Implemented a new question type, "Say What You See," across the application. This includes updates to UI components, data models, and serialization logic. Key changes include: - Conditional rendering for `ClientSayWhatYouSeeQuestion` in `QuestionPicker.razor`. - New button and handler for selecting the question type in `QuestionTypePickerModal.razor`. - Updated rendering logic in `RootComponent.razor`. - Enhanced question addition method to include the new type. - Registered new types for JSON serialization in `ClientAnswer.cs` and `ClientQuestion.cs`. - Updated `PolymorphicQuestionConverter.cs` for deserialization. - Created `SayWhatYouSeeQuestion` and `ClientSayWhatYouSeeAnswer` classes with validation and equality logic. - Added new Razor components for user interaction with the question type. - Implemented a custom string equality comparer for answer comparison. - Improved CSS styles for the new components. - Added unit tests to validate functionality and answer logic. --- .../Pages/Tests/Client/SayWhatYouSee.razor | 19 +++++ .../Client/SayWhatYouSeeAnswerSummary.razor | 39 +++++++++ .../Pages/Tests/Present/SayWhatYouSee.razor | 21 +++++ .../Client/Shared/Client/QuestionPicker.razor | 4 + .../Shared/Client/SayWhatYouSeeQuestion.razor | 34 ++++++++ .../Shared/Edit/QuestionTypePickerModal.razor | 10 +++ .../Client/Shared/Edit/RootComponent.razor | 27 ++++--- .../Shared/Edit/SayWhatYouSeeQuestion.razor | 79 +++++++++++++++++++ .../Shared/Present/QuestionPicker.razor | 4 + .../Present/SayWhatYouSeeQuestion.razor | 31 ++++++++ .../Client/wwwroot/css/app.css | 9 +++ .../ClientQuestionSerializationTests.cs | 39 +++++++++ QuizExperiment.Models/Client/ClientAnswer.cs | 1 + .../Client/ClientQuestion.cs | 1 + .../Client/ClientSayWhatYouSeeAnswer.cs | 61 ++++++++++++++ .../Client/ClientSayWhatYouSeeQuestion.cs | 12 +++ .../SayWhatYouSeeStringEqualityComparer.cs | 22 ++++++ .../PolymorphicQuestionConverter.cs | 4 + QuizExperiment.Models/Question.cs | 1 + .../SayWhatYouSeeQuestion.cs | 34 ++++++++ 20 files changed, 442 insertions(+), 10 deletions(-) create mode 100644 QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSee.razor create mode 100644 QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSeeAnswerSummary.razor create mode 100644 QuizExperiment.Admin/Client/Pages/Tests/Present/SayWhatYouSee.razor create mode 100644 QuizExperiment.Admin/Client/Shared/Client/SayWhatYouSeeQuestion.razor create mode 100644 QuizExperiment.Admin/Client/Shared/Edit/SayWhatYouSeeQuestion.razor create mode 100644 QuizExperiment.Admin/Client/Shared/Present/SayWhatYouSeeQuestion.razor create mode 100644 QuizExperiment.Models/Client/ClientSayWhatYouSeeAnswer.cs create mode 100644 QuizExperiment.Models/Client/ClientSayWhatYouSeeQuestion.cs create mode 100644 QuizExperiment.Models/Client/SayWhatYouSeeStringEqualityComparer.cs create mode 100644 QuizExperiment.Models/SayWhatYouSeeQuestion.cs diff --git a/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSee.razor b/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSee.razor new file mode 100644 index 0000000..06c8b13 --- /dev/null +++ b/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSee.razor @@ -0,0 +1,19 @@ +@page "/test/client/saywhatyouee" +@using QuizModels = QuizExperiment.Models.Client +@layout QuizExperiment.Admin.Client.Shared.Client.Layout + + + +@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}"); + } +} \ No newline at end of file diff --git a/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSeeAnswerSummary.razor b/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSeeAnswerSummary.razor new file mode 100644 index 0000000..c1bc7f8 --- /dev/null +++ b/QuizExperiment.Admin/Client/Pages/Tests/Client/SayWhatYouSeeAnswerSummary.razor @@ -0,0 +1,39 @@ +@page "/test/client/answersummary/saywhatyousee" +@using QuizModels = QuizExperiment.Models.Client +@layout QuizExperiment.Admin.Client.Shared.Client.Layout + + + +@code { + QuizModels.ClientSayWhatYouSeeAnswer myAnswer = new QuizModels.ClientSayWhatYouSeeAnswer + { + Answers = new List + { + "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 + { + "One", + "Two", + "Three" + } + }; + +} \ No newline at end of file diff --git a/QuizExperiment.Admin/Client/Pages/Tests/Present/SayWhatYouSee.razor b/QuizExperiment.Admin/Client/Pages/Tests/Present/SayWhatYouSee.razor new file mode 100644 index 0000000..2ae5f6d --- /dev/null +++ b/QuizExperiment.Admin/Client/Pages/Tests/Present/SayWhatYouSee.razor @@ -0,0 +1,21 @@ +@page "/test/present/saywhatyouee" +@using QuizModels = QuizExperiment.Models +@layout QuizExperiment.Admin.Client.Shared.Client.Layout + + + +@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}"); + } +} \ No newline at end of file diff --git a/QuizExperiment.Admin/Client/Shared/Client/QuestionPicker.razor b/QuizExperiment.Admin/Client/Shared/Client/QuestionPicker.razor index 739bbde..ca39148 100644 --- a/QuizExperiment.Admin/Client/Shared/Client/QuestionPicker.razor +++ b/QuizExperiment.Admin/Client/Shared/Client/QuestionPicker.razor @@ -15,6 +15,10 @@ { } + else if(Question is ClientSayWhatYouSeeQuestion sayWhatYouSeeQuestion) + { + + } else {

Unsupported question type.

diff --git a/QuizExperiment.Admin/Client/Shared/Client/SayWhatYouSeeQuestion.razor b/QuizExperiment.Admin/Client/Shared/Client/SayWhatYouSeeQuestion.razor new file mode 100644 index 0000000..9678a8d --- /dev/null +++ b/QuizExperiment.Admin/Client/Shared/Client/SayWhatYouSeeQuestion.razor @@ -0,0 +1,34 @@ +@using QuizExperiment.Models.Client + +@{ + if(Question != null) + { +
+

@Question.Title

+ +
+ + +
+
+ } +} + +@code { + [Parameter] + public ClientSayWhatYouSeeQuestion? Question { get; set; } + + [Parameter] + public EventCallback OnAnswerSubmit { get; set; } + + private string UserAnswer { get; set; } = string.Empty; + + private async Task SubmitAnswer() + { + var answer = new ClientSayWhatYouSeeAnswer + { + Answers = new List { UserAnswer } + }; + await OnAnswerSubmit.InvokeAsync(answer); + } +} diff --git a/QuizExperiment.Admin/Client/Shared/Edit/QuestionTypePickerModal.razor b/QuizExperiment.Admin/Client/Shared/Edit/QuestionTypePickerModal.razor index a6dd90e..d4e0edc 100644 --- a/QuizExperiment.Admin/Client/Shared/Edit/QuestionTypePickerModal.razor +++ b/QuizExperiment.Admin/Client/Shared/Edit/QuestionTypePickerModal.razor @@ -22,6 +22,12 @@ True / False +
+ +