+
diff --git a/Blink3.Web/Pages/Staff.razor b/Blink3.Web/Pages/Staff.razor
new file mode 100644
index 0000000..67a5ebd
--- /dev/null
+++ b/Blink3.Web/Pages/Staff.razor
@@ -0,0 +1,11 @@
+@page "/guilds/{GuildId}/Staff"
+
+
Staff settings
+
+
Staff settings
+
+@GuildId
+
+@code {
+ [Parameter] public string GuildId { get; set; }
+}
\ No newline at end of file
diff --git a/Blink3.Web/Pages/TempVC.razor b/Blink3.Web/Pages/TempVC.razor
new file mode 100644
index 0000000..41d53bd
--- /dev/null
+++ b/Blink3.Web/Pages/TempVC.razor
@@ -0,0 +1,11 @@
+@page "/guilds/{GuildId}/TempVC"
+
+
Temporary VC settings
+
+
Temporary VC settings
+
+@GuildId
+
+@code {
+ [Parameter] public string GuildId { get; set; }
+}
\ No newline at end of file
diff --git a/Blink3.Web/Pages/Wordle.razor b/Blink3.Web/Pages/Wordle.razor
new file mode 100644
index 0000000..a6ce64a
--- /dev/null
+++ b/Blink3.Web/Pages/Wordle.razor
@@ -0,0 +1,11 @@
+@page "/guilds/{GuildId}/Wordle"
+
+
Wordle settings
+
+
Wordle settings
+
+@GuildId
+
+@code {
+ [Parameter] public string GuildId { get; set; }
+}
\ No newline at end of file
From c99d82b17c53642d753448ac5320f9f5fd735cee Mon Sep 17 00:00:00 2001
From: EpicOfficer <9379778+EpicOfficer@users.noreply.github.com>
Date: Wed, 17 Apr 2024 16:36:56 +0100
Subject: [PATCH 09/19] Update CSS properties and remove border from headings
The CSS property for sidebar2 content border color is now linked to the Bootstrap border color variable. In the TempVC, Wordle, and Staff Razor pages, the border-bottom class has been removed from the h1 elements, hence these headings will no longer display a bottom border.
---
Blink3.Web/Pages/Staff.razor | 2 +-
Blink3.Web/Pages/TempVC.razor | 2 +-
Blink3.Web/Pages/Wordle.razor | 2 +-
Blink3.Web/wwwroot/css/app.css | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/Blink3.Web/Pages/Staff.razor b/Blink3.Web/Pages/Staff.razor
index 67a5ebd..308021a 100644
--- a/Blink3.Web/Pages/Staff.razor
+++ b/Blink3.Web/Pages/Staff.razor
@@ -2,7 +2,7 @@
Staff settings
-
Staff settings
+
Staff settings
@GuildId
diff --git a/Blink3.Web/Pages/TempVC.razor b/Blink3.Web/Pages/TempVC.razor
index 41d53bd..b48400d 100644
--- a/Blink3.Web/Pages/TempVC.razor
+++ b/Blink3.Web/Pages/TempVC.razor
@@ -2,7 +2,7 @@
Temporary VC settings
-
Temporary VC settings
+
Temporary VC settings
@GuildId
diff --git a/Blink3.Web/Pages/Wordle.razor b/Blink3.Web/Pages/Wordle.razor
index a6ce64a..99f6e61 100644
--- a/Blink3.Web/Pages/Wordle.razor
+++ b/Blink3.Web/Pages/Wordle.razor
@@ -2,7 +2,7 @@
Wordle settings
-
Wordle settings
+
Wordle settings
@GuildId
diff --git a/Blink3.Web/wwwroot/css/app.css b/Blink3.Web/wwwroot/css/app.css
index 437f99a..974f778 100644
--- a/Blink3.Web/wwwroot/css/app.css
+++ b/Blink3.Web/wwwroot/css/app.css
@@ -75,5 +75,5 @@ h1:focus {
:root {
--bb-sidebar2-background-color: transparent;
--bb-sidebar2-nav-item-text-color: var(--bs-nav-link-color);
- --bb-sidebar2-content-border-color: transparent;
+ --bb-sidebar2-content-border-color: var(--bs-border-color);
}
\ No newline at end of file
From 4ba0ba9e1654de20a3faef6d7fb1f1705c36842d Mon Sep 17 00:00:00 2001
From: EpicOfficer <9379778+EpicOfficer@users.noreply.github.com>
Date: Wed, 17 Apr 2024 18:26:03 +0100
Subject: [PATCH 10/19] Add new guild-related endpoints in GuildsController
This update adds multiple endpoints to GuildsController, including functionality to return all guilds, all categories for a guild, and all channels for a guild. To support this, a new DiscordPartialChannel model is also added to represent Discord channels in a simplified form.
---
Blink3.API/Controllers/GuildsController.cs | 58 ++++++++++++++++++++-
Blink3.Core/Models/DiscordPartialChannel.cs | 7 +++
2 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 Blink3.Core/Models/DiscordPartialChannel.cs
diff --git a/Blink3.API/Controllers/GuildsController.cs b/Blink3.API/Controllers/GuildsController.cs
index 2a3e962..74a5430 100644
--- a/Blink3.API/Controllers/GuildsController.cs
+++ b/Blink3.API/Controllers/GuildsController.cs
@@ -6,9 +6,17 @@
namespace Blink3.API.Controllers;
-public class GuildsController(DiscordSocketClient discordSocketClient, ICachingService cachingService) : ApiControllerBase(discordSocketClient, cachingService)
+[SwaggerTag("Endpoints for getting information on discord guilds")]
+public class GuildsController(DiscordSocketClient discordSocketClient, ICachingService cachingService)
+ : ApiControllerBase(discordSocketClient, cachingService)
{
[HttpGet]
+ [SwaggerOperation(
+ Summary = "Returns all Discord guilds",
+ Description = "Returns a list of Discord guilds the currently logged in user has access to manage.",
+ OperationId = "Guilds.GetAll",
+ Tags = ["Guilds"]
+ )]
[SwaggerResponse(StatusCodes.Status200OK, "Success", typeof(DiscordPartialGuild[]))]
public async Task
> GetAllGuilds()
{
@@ -16,4 +24,52 @@ public async Task> GetAllGuilds()
return Ok(guilds);
}
+
+ [HttpGet("{id}/categories")]
+ [SwaggerOperation(
+ Summary = "Returns all categories for a guild",
+ Description = "Returns a list of all Discord category channels for a given guild ID",
+ OperationId = "Guilds.GetCategories",
+ Tags = ["Guilds"]
+ )]
+ [SwaggerResponse(StatusCodes.Status200OK, "Success", typeof(DiscordPartialChannel[]))]
+ public async Task>> GetCategories(ulong id)
+ {
+ ObjectResult? accessCheckResult = await CheckGuildAccessAsync(id);
+ if (accessCheckResult is not null) return accessCheckResult;
+
+ return DiscordBotClient.GetGuild(id).CategoryChannels
+ .OrderBy(c => c.Position)
+ .Select(c =>
+ new DiscordPartialChannel
+ {
+ Id = c.Id,
+ Name = c.Name
+ })
+ .ToList();
+ }
+
+ [HttpGet("{id}/channels")]
+ [SwaggerOperation(
+ Summary = "Returns all chanels for a guild",
+ Description = "Returns a list of all Discord channels for a given guild ID",
+ OperationId = "Guilds.GetChannels",
+ Tags = ["Guilds"]
+ )]
+ [SwaggerResponse(StatusCodes.Status200OK, "Success", typeof(DiscordPartialChannel[]))]
+ public async Task>> GetChannels(ulong id)
+ {
+ ObjectResult? accessCheckResult = await CheckGuildAccessAsync(id);
+ if (accessCheckResult is not null) return accessCheckResult;
+
+ return DiscordBotClient.GetGuild(id).TextChannels
+ .OrderBy(c => c.Position)
+ .Select(c =>
+ new DiscordPartialChannel
+ {
+ Id = c.Id,
+ Name = c.Name
+ })
+ .ToList();
+ }
}
\ No newline at end of file
diff --git a/Blink3.Core/Models/DiscordPartialChannel.cs b/Blink3.Core/Models/DiscordPartialChannel.cs
new file mode 100644
index 0000000..c76f95c
--- /dev/null
+++ b/Blink3.Core/Models/DiscordPartialChannel.cs
@@ -0,0 +1,7 @@
+namespace Blink3.Core.Models;
+
+public class DiscordPartialChannel
+{
+ public ulong Id { get; set; }
+ public string Name { get; set; } = string.Empty;
+}
\ No newline at end of file
From cef3bd448ad16d812ed2aa15d02205cfde2f2102 Mon Sep 17 00:00:00 2001
From: EpicOfficer <9379778+EpicOfficer@users.noreply.github.com>
Date: Thu, 18 Apr 2024 13:27:52 +0100
Subject: [PATCH 11/19] Add Wordle settings page with color customization
options
This commit implements a Wordle settings page in the application that allows users to customize color attributes for different parts. A form has been added that lets the users specify their preferred background, text, correct, misplaced, or incorrect colors. These user preferences are now fetched from the API and saved upon submission. This required updates to the BlinkGuild entity and corresponding conversions, adjustments to NewtonsoftJson usage, and the addition of JsonPatch functionality.
---
Blink3.API/Blink3.API.csproj | 2 +
.../Controllers/BlinkGuildsController.cs | 39 ++++++
Blink3.API/Program.cs | 10 +-
Blink3.Core/Entities/BlinkGuild.cs | 35 +++--
Blink3.Core/Helpers/ULongToStringConverter.cs | 12 +-
Blink3.Web/Blink3.Web.csproj | 1 +
Blink3.Web/Pages/Staff.razor | 2 +-
Blink3.Web/Pages/TempVC.razor | 2 +-
Blink3.Web/Pages/Wordle.razor | 129 +++++++++++++++++-
Blink3.Web/Properties/launchSettings.json | 6 +-
10 files changed, 204 insertions(+), 34 deletions(-)
diff --git a/Blink3.API/Blink3.API.csproj b/Blink3.API/Blink3.API.csproj
index 2e03f16..59ac6c5 100644
--- a/Blink3.API/Blink3.API.csproj
+++ b/Blink3.API/Blink3.API.csproj
@@ -15,6 +15,8 @@
+
+
diff --git a/Blink3.API/Controllers/BlinkGuildsController.cs b/Blink3.API/Controllers/BlinkGuildsController.cs
index 9749b38..1c6a2ea 100644
--- a/Blink3.API/Controllers/BlinkGuildsController.cs
+++ b/Blink3.API/Controllers/BlinkGuildsController.cs
@@ -4,6 +4,7 @@
using Blink3.Core.Models;
using Blink3.Core.Repositories.Interfaces;
using Discord.WebSocket;
+using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
@@ -83,4 +84,42 @@ public async Task UpdateBlinkGuild(ulong id, [FromBody] BlinkGuild
return NoContent();
}
+
+ ///
+ /// Patches a specific BlinkGuild item.
+ /// Updates the content of a specific BlinkGuild item partially.
+ ///
+ /// The ID of the BlinkGuild item to patch.
+ /// The containing the partial update.
+ /// The cancellation token.
+ /// Returns 204 (No content) if the patch is successful.
+ [HttpPatch("{id}")]
+ [SwaggerOperation(
+ Summary = "Patches a specific BlinkGuild item",
+ Description = "Updates the content of a specific BlinkGuild item partially",
+ OperationId = "BlinkGuilds.Patch",
+ Tags = ["BlinkGuilds"]
+ )]
+ [SwaggerResponse(StatusCodes.Status204NoContent, "No content")]
+ public async Task PatchBlinkGuild(ulong id, [FromBody] JsonPatchDocument patchDoc,
+ CancellationToken cancellationToken)
+ {
+ ObjectResult? accessCheckResult = await CheckGuildAccessAsync(id);
+ if (accessCheckResult is not null) return accessCheckResult;
+
+ BlinkGuild? blinkGuild = await blinkGuildRepository.GetByIdAsync(id);
+ if (blinkGuild is null)
+ {
+ return NotFound();
+ }
+ patchDoc.ApplyTo(blinkGuild);
+
+ if (!TryValidateModel(blinkGuild))
+ {
+ return BadRequest(ModelState);
+ }
+
+ await blinkGuildRepository.UpdateAsync(blinkGuild, cancellationToken);
+ return NoContent();
+ }
}
\ No newline at end of file
diff --git a/Blink3.API/Program.cs b/Blink3.API/Program.cs
index f6725bd..414b450 100644
--- a/Blink3.API/Program.cs
+++ b/Blink3.API/Program.cs
@@ -8,7 +8,6 @@
using Blink3.DataAccess.Extensions;
using Discord;
using Discord.Addons.Hosting;
-using Discord.Rest;
using Discord.WebSocket;
using Microsoft.AspNetCore.HttpOverrides;
using Serilog;
@@ -31,11 +30,10 @@
builder.Services.AddProblemDetails();
// Controllers
- builder.Services.AddControllers()
- .AddJsonOptions(options =>
- {
- options.JsonSerializerOptions.Converters.Add(new ULongToStringConverter());
- });
+ builder.Services.AddControllers().AddNewtonsoftJson(options =>
+ {
+ options.SerializerSettings.Converters.Add(new ULongToStringConverter());
+ });
// Swagger docs
builder.Services.AddEndpointsApiExplorer();
diff --git a/Blink3.Core/Entities/BlinkGuild.cs b/Blink3.Core/Entities/BlinkGuild.cs
index 74e446e..aa8ba50 100644
--- a/Blink3.Core/Entities/BlinkGuild.cs
+++ b/Blink3.Core/Entities/BlinkGuild.cs
@@ -34,9 +34,10 @@ public class BlinkGuild : ICacheKeyIdentifiable
public string BackgroundColour
{
get => string.IsNullOrEmpty(_backgroundColour)
- ? WordleImageConstants.BackgroundColour.ToHex()
- : _backgroundColour;
- set => _backgroundColour = string.IsNullOrEmpty(value) ? null : value;
+ ? string.Concat("#", WordleImageConstants.BackgroundColour.ToHex().AsSpan(0, 6))
+ : '#' + _backgroundColour;
+ set => _backgroundColour = string.IsNullOrEmpty(value) ? null :
+ value.StartsWith('#') ? value.Substring(1, 6) : value[..6];
}
///
@@ -48,8 +49,11 @@ public string BackgroundColour
///
public string TextColour
{
- get => string.IsNullOrEmpty(_textColour) ? WordleImageConstants.TextColour.ToHex() : _textColour;
- set => _textColour = string.IsNullOrEmpty(value) ? null : value;
+ get => string.IsNullOrEmpty(_textColour)
+ ? string.Concat("#", WordleImageConstants.TextColour.ToHex().AsSpan(0, 6))
+ : '#' + _textColour;
+ set => _textColour = string.IsNullOrEmpty(value) ? null :
+ value.StartsWith('#') ? value.Substring(1, 6) : value[..6];
}
///
@@ -62,9 +66,10 @@ public string TextColour
public string CorrectTileColour
{
get => string.IsNullOrEmpty(_correctTileColour)
- ? WordleImageConstants.CorrectTileColour.ToHex()
- : _correctTileColour;
- set => _correctTileColour = string.IsNullOrEmpty(value) ? null : value;
+ ? string.Concat("#", WordleImageConstants.CorrectTileColour.ToHex().AsSpan(0, 6))
+ : '#' + _correctTileColour;
+ set => _correctTileColour = string.IsNullOrEmpty(value) ? null :
+ value.StartsWith('#') ? value.Substring(1, 6) : value[..6];
}
///
@@ -77,9 +82,10 @@ public string CorrectTileColour
public string MisplacedTileColour
{
get => string.IsNullOrEmpty(_misplacedTileColour)
- ? WordleImageConstants.MisplacedTileColour.ToHex()
- : _misplacedTileColour;
- set => _misplacedTileColour = string.IsNullOrEmpty(value) ? null : value;
+ ? string.Concat("#", WordleImageConstants.MisplacedTileColour.ToHex().AsSpan(0, 6))
+ : '#' + _misplacedTileColour;
+ set => _misplacedTileColour = string.IsNullOrEmpty(value) ? null :
+ value.StartsWith('#') ? value.Substring(1, 6) : value[..6];
}
///
@@ -92,9 +98,10 @@ public string MisplacedTileColour
public string IncorrectTileColour
{
get => string.IsNullOrEmpty(_incorrectTileColour)
- ? WordleImageConstants.IncorrectTileColour.ToHex()
- : _incorrectTileColour;
- set => _incorrectTileColour = string.IsNullOrEmpty(value) ? null : value;
+ ? string.Concat("#", WordleImageConstants.IncorrectTileColour.ToHex().AsSpan(0, 6))
+ : '#' + _incorrectTileColour;
+ set => _incorrectTileColour = string.IsNullOrEmpty(value) ? null :
+ value.StartsWith('#') ? value.Substring(1, 6) : value[..6];
}
///
diff --git a/Blink3.Core/Helpers/ULongToStringConverter.cs b/Blink3.Core/Helpers/ULongToStringConverter.cs
index d4a2c62..ffe7740 100644
--- a/Blink3.Core/Helpers/ULongToStringConverter.cs
+++ b/Blink3.Core/Helpers/ULongToStringConverter.cs
@@ -1,18 +1,16 @@
-using System.Text.Json;
-using System.Text.Json.Serialization;
+using Newtonsoft.Json;
namespace Blink3.Core.Helpers;
public class ULongToStringConverter : JsonConverter
{
- public override ulong Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ public override ulong ReadJson(JsonReader reader, Type objectType, ulong existingValue, bool hasExistingValue, JsonSerializer serializer)
{
- string? numberAsString = reader.GetString();
- return numberAsString is not null ? ulong.Parse(numberAsString) : 0;
+ return ulong.Parse((string)reader.Value!);
}
- public override void Write(Utf8JsonWriter writer, ulong value, JsonSerializerOptions options)
+ public override void WriteJson(JsonWriter writer, ulong value, JsonSerializer serializer)
{
- writer.WriteStringValue(value.ToString());
+ writer.WriteValue(value.ToString());
}
}
\ No newline at end of file
diff --git a/Blink3.Web/Blink3.Web.csproj b/Blink3.Web/Blink3.Web.csproj
index 0a368e6..75d5f19 100644
--- a/Blink3.Web/Blink3.Web.csproj
+++ b/Blink3.Web/Blink3.Web.csproj
@@ -13,6 +13,7 @@
+
diff --git a/Blink3.Web/Pages/Staff.razor b/Blink3.Web/Pages/Staff.razor
index 308021a..faf9f3a 100644
--- a/Blink3.Web/Pages/Staff.razor
+++ b/Blink3.Web/Pages/Staff.razor
@@ -7,5 +7,5 @@
@GuildId
@code {
- [Parameter] public string GuildId { get; set; }
+ [Parameter] public string? GuildId { get; set; }
}
\ No newline at end of file
diff --git a/Blink3.Web/Pages/TempVC.razor b/Blink3.Web/Pages/TempVC.razor
index b48400d..4d723d6 100644
--- a/Blink3.Web/Pages/TempVC.razor
+++ b/Blink3.Web/Pages/TempVC.razor
@@ -7,5 +7,5 @@
@GuildId
@code {
- [Parameter] public string GuildId { get; set; }
+ [Parameter] public string? GuildId { get; set; }
}
\ No newline at end of file
diff --git a/Blink3.Web/Pages/Wordle.razor b/Blink3.Web/Pages/Wordle.razor
index 99f6e61..1068252 100644
--- a/Blink3.Web/Pages/Wordle.razor
+++ b/Blink3.Web/Pages/Wordle.razor
@@ -1,11 +1,136 @@
@page "/guilds/{GuildId}/Wordle"
+@using Blink3.Core.Entities
+@using Microsoft.AspNetCore.JsonPatch
+@using Newtonsoft.Json
+@using System.Text
+@inject HttpClient HttpClient
Wordle settings
Wordle settings
-@GuildId
+@if (_blinkGuild is null)
+{
+ Loading...
+}
+else
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @if (!string.IsNullOrWhiteSpace(notificationMessage))
+ {
+
+ @notificationMessage
+
+ }
+}
@code {
- [Parameter] public string GuildId { get; set; }
+ [Parameter] public string? GuildId { get; set; }
+ private BlinkGuild? _initialGuild;
+ private BlinkGuild? _blinkGuild;
+
+ private string notificationMessage = string.Empty;
+
+ protected override async Task OnInitializedAsync()
+ {
+ await GetGuild();
+ }
+
+ protected override async Task OnParametersSetAsync()
+ {
+ await GetGuild();
+ }
+
+ private async Task GetGuild()
+ {
+ notificationMessage = string.Empty;
+ _blinkGuild = await HttpClient.GetFromJsonAsync($"api/BlinkGuilds/{GuildId}");
+
+ SetInitialGuild();
+ }
+
+ private void SetInitialGuild()
+ {
+ if (_blinkGuild is null) return;
+ _initialGuild = new BlinkGuild
+ {
+ Id = _blinkGuild.Id,
+ BackgroundColour = _blinkGuild.BackgroundColour,
+ TextColour = _blinkGuild.TextColour,
+ CorrectTileColour = _blinkGuild.CorrectTileColour,
+ MisplacedTileColour = _blinkGuild.MisplacedTileColour,
+ IncorrectTileColour = _blinkGuild.IncorrectTileColour
+ };
+ }
+
+ private async Task HandleValidSubmit()
+ {
+ HttpMethod method = new("PATCH");
+ JsonPatchDocument patchDocument = new();
+
+ if (_initialGuild?.BackgroundColour != _blinkGuild?.BackgroundColour)
+ patchDocument.Replace(x => x.BackgroundColour, _blinkGuild?.BackgroundColour);
+
+ if (_initialGuild?.TextColour != _blinkGuild?.TextColour)
+ patchDocument.Replace(x => x.TextColour, _blinkGuild?.TextColour);
+
+ if (_initialGuild?.CorrectTileColour != _blinkGuild?.CorrectTileColour)
+ patchDocument.Replace(x => x.CorrectTileColour, _blinkGuild?.CorrectTileColour);
+
+ if (_initialGuild?.MisplacedTileColour != _blinkGuild?.MisplacedTileColour)
+ patchDocument.Replace(x => x.MisplacedTileColour, _blinkGuild?.MisplacedTileColour);
+
+ if (_initialGuild?.IncorrectTileColour != _blinkGuild?.IncorrectTileColour)
+ patchDocument.Replace(x => x.IncorrectTileColour, _blinkGuild?.IncorrectTileColour);
+
+ HttpRequestMessage request = new(method, $"api/BlinkGuilds/{GuildId}")
+ {
+ Content = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json")
+ };
+
+ HttpResponseMessage httpResponseMessage = await HttpClient.SendAsync(request);
+
+ if (httpResponseMessage.IsSuccessStatusCode)
+ {
+ SetInitialGuild();
+ notificationMessage = "Changes have been saved successfully.";
+ }
+ else
+ {
+ notificationMessage = "Failed to save changes.";
+ }
+ }
+
}
\ No newline at end of file
diff --git a/Blink3.Web/Properties/launchSettings.json b/Blink3.Web/Properties/launchSettings.json
index 9e27c5f..b6d874d 100644
--- a/Blink3.Web/Properties/launchSettings.json
+++ b/Blink3.Web/Properties/launchSettings.json
@@ -12,7 +12,7 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
- "launchBrowser": true,
+ "launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5037",
"environmentVariables": {
@@ -22,7 +22,7 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
- "launchBrowser": true,
+ "launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7041;http://localhost:5037",
"environmentVariables": {
@@ -31,7 +31,7 @@
},
"IIS Express": {
"commandName": "IISExpress",
- "launchBrowser": true,
+ "launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
From ca2bf6d373f3dbda634f38b304513faf79947620 Mon Sep 17 00:00:00 2001
From: EpicOfficer <9379778+EpicOfficer@users.noreply.github.com>
Date: Thu, 18 Apr 2024 14:55:02 +0100
Subject: [PATCH 12/19] Update Wordle and TempVC pages
Refactored Wordle.razor and TempVC.razor pages in the Blink3.Web project. Changes include using Blink3.Core.Helpers, updating references to _notificationMessage, and employing ULongToStringConverter for proper JSON serialization. TempVC.razor is significantly expanded to handle guild settings.
---
Blink3.Web/Pages/TempVC.razor | 125 +++++++++++++++++++++++++++++++++-
Blink3.Web/Pages/Wordle.razor | 18 +++--
2 files changed, 135 insertions(+), 8 deletions(-)
diff --git a/Blink3.Web/Pages/TempVC.razor b/Blink3.Web/Pages/TempVC.razor
index 4d723d6..49e1f87 100644
--- a/Blink3.Web/Pages/TempVC.razor
+++ b/Blink3.Web/Pages/TempVC.razor
@@ -1,11 +1,134 @@
@page "/guilds/{GuildId}/TempVC"
+@using Blink3.Core.Entities
+@using Microsoft.AspNetCore.JsonPatch
+@using Newtonsoft.Json
+@using System.Text
+@using Blink3.Core.Extensions
+@using Blink3.Core.Helpers
+@using Blink3.Core.Models
+@inject HttpClient HttpClient
Temporary VC settings
Temporary VC settings
-@GuildId
+@if (_blinkGuild is null)
+{
+ Loading...
+}
+else
+{
+
+
+
+ @if (_categories is not null)
+ {
+
+
+
+
+ @foreach (DiscordPartialChannel category in _categories)
+ {
+
+ }
+
+
+ }
+
+
+
+
+
+
+ @if (!string.IsNullOrWhiteSpace(_notificationMessage))
+ {
+
+ @_notificationMessage
+
+ }
+}
@code {
[Parameter] public string? GuildId { get; set; }
+
+ private BlinkGuild? _initialGuild;
+ private BlinkGuild? _blinkGuild;
+ private IEnumerable? _categories;
+ private string? SelectedCategoryId { get; set; }
+
+ private string _notificationMessage = string.Empty;
+
+ protected override async Task OnInitializedAsync()
+ {
+ await GetCategories();
+ await GetGuild();
+ }
+
+ protected override async Task OnParametersSetAsync()
+ {
+ await GetCategories();
+ await GetGuild();
+ }
+
+ private async Task GetGuild()
+ {
+ _notificationMessage = string.Empty;
+ _blinkGuild = await HttpClient.GetFromJsonAsync($"api/BlinkGuilds/{GuildId}");
+ SelectedCategoryId = _blinkGuild?.TemporaryVcCategoryId?.ToString();
+
+ SetInitialGuild();
+ }
+
+ private async Task GetCategories()
+ {
+ _categories = await HttpClient.GetFromJsonAsync>($"/api/Guilds/{GuildId}/categories");
+ }
+
+ private void SetInitialGuild()
+ {
+ if (_blinkGuild is null) return;
+ _initialGuild = new BlinkGuild
+ {
+ Id = _blinkGuild.Id,
+ TemporaryVcCategoryId = _blinkGuild.TemporaryVcCategoryId
+ };
+ }
+
+ private async Task HandleValidSubmit()
+ {
+ HttpMethod method = new("PATCH");
+ JsonPatchDocument patchDocument = new();
+
+ if (_blinkGuild is null)
+ {
+ _notificationMessage = "An error occurred submitting data";
+ return;
+ }
+
+ _blinkGuild.TemporaryVcCategoryId = string.IsNullOrWhiteSpace(SelectedCategoryId) ? null : SelectedCategoryId?.ToUlong();
+
+ if (_initialGuild?.TemporaryVcCategoryId != _blinkGuild?.TemporaryVcCategoryId)
+ patchDocument.Replace(x => x.TemporaryVcCategoryId, _blinkGuild?.TemporaryVcCategoryId);
+
+ JsonSerializerSettings options = new();
+ options.Converters.Add(new ULongToStringConverter());
+
+ HttpRequestMessage request = new(method, $"api/BlinkGuilds/{GuildId}")
+ {
+ Content = new StringContent(JsonConvert.SerializeObject(patchDocument, options), Encoding.UTF8, "application/json-patch+json")
+ };
+
+ HttpResponseMessage httpResponseMessage = await HttpClient.SendAsync(request);
+
+ if (httpResponseMessage.IsSuccessStatusCode)
+ {
+ SetInitialGuild();
+ _notificationMessage = "Changes have been saved successfully.";
+ }
+ else
+ {
+ _notificationMessage = "Failed to save changes.";
+ }
+ }
}
\ No newline at end of file
diff --git a/Blink3.Web/Pages/Wordle.razor b/Blink3.Web/Pages/Wordle.razor
index 1068252..df3b6e6 100644
--- a/Blink3.Web/Pages/Wordle.razor
+++ b/Blink3.Web/Pages/Wordle.razor
@@ -3,6 +3,7 @@
@using Microsoft.AspNetCore.JsonPatch
@using Newtonsoft.Json
@using System.Text
+@using Blink3.Core.Helpers
@inject HttpClient HttpClient
Wordle settings
@@ -48,10 +49,10 @@ else
- @if (!string.IsNullOrWhiteSpace(notificationMessage))
+ @if (!string.IsNullOrWhiteSpace(_notificationMessage))
{