@page "/config/communityboard" @rendermode InteractiveServer Community Board

Community Board

Edit the community board content including featured players, announcements, Instagram images, and videos.

@if (loading) {
} else if (!string.IsNullOrEmpty(error)) {
@error
} else {
Current Announcement
Featured Player
Videos
@if (videos.Count == 0) {

No videos.

} @for (int i = 0; i < videos.Count; i++) { var idx = i;
}
@if (!string.IsNullOrEmpty(saveMessage)) { @saveMessage }
} @code { [Inject] private HttpClient Http { get; set; } = default!; private bool loading = true; private bool saving; private string? error; private string? saveMessage; private string announcementMessage = ""; private string announcementUrl = ""; private int featuredPlayerId; private string? featuredPlayerTitle; private string? featuredPlayerUrl; private List videos = new(); protected override async Task OnInitializedAsync() { try { var jsonContent = await Http.GetStringAsync("/admin/api/config/communityboard"); using var doc = JsonDocument.Parse(jsonContent); var root = doc.RootElement; if (root.TryGetProperty("currentAnnouncement", out var ann)) { announcementMessage = ann.TryGetProperty("message", out var m) ? m.GetString() ?? "" : ""; announcementUrl = ann.TryGetProperty("moreInfoUrl", out var u) ? u.GetString() ?? "" : ""; } if (root.TryGetProperty("featuredPlayer", out var fp)) { featuredPlayerId = fp.TryGetProperty("id", out var id) ? id.GetInt32() : 0; featuredPlayerTitle = fp.TryGetProperty("titleOverride", out var t) ? t.GetString() : null; featuredPlayerUrl = fp.TryGetProperty("urlOverride", out var url) ? url.GetString() : null; } if (root.TryGetProperty("videos", out var vids)) { videos = new List(); foreach (var v in vids.EnumerateArray()) { videos.Add(new VideoEntry { Title = v.TryGetProperty("title", out var title) ? title.GetString() ?? "" : "", Description = v.TryGetProperty("description", out var desc) ? desc.GetString() ?? "" : "", SourceUrl = v.TryGetProperty("sourceUrl", out var src) ? src.GetString() ?? "" : "", BlobName = v.TryGetProperty("blobName", out var blob) ? blob.GetString() ?? "" : "", ThumbnailBlobName = v.TryGetProperty("thumbnailBlobName", out var thumb) ? thumb.GetString() ?? "" : "" }); } } } catch (Exception ex) { error = $"Failed to load: {ex.Message}"; } finally { loading = false; } } private async Task SaveFromForm() { saving = true; saveMessage = null; try { var payload = new { featuredPlayer = new { id = featuredPlayerId, titleOverride = featuredPlayerTitle, urlOverride = featuredPlayerUrl }, featuredRoomGroup = new { featuredRoomGroupId = 2, name = "Featured Rooms", rooms = new List() }, currentAnnouncement = new { message = announcementMessage, moreInfoUrl = announcementUrl }, instagramImages = new List(), videos = videos.Select(v => new { blobName = v.BlobName, title = v.Title, description = v.Description, thumbnailBlobName = v.ThumbnailBlobName, sourceUrl = v.SourceUrl }).ToList() }; var content = new StringContent( System.Text.Json.JsonSerializer.Serialize(payload, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }), System.Text.Encoding.UTF8, "application/json"); var response = await Http.PutAsync("/admin/api/config/communityboard", content); response.EnsureSuccessStatusCode(); saveMessage = "Saved successfully!"; } catch (Exception ex) { saveMessage = $"Error: {ex.Message}"; } finally { saving = false; } } private class VideoEntry { public string Title { get; set; } = ""; public string Description { get; set; } = ""; public string SourceUrl { get; set; } = ""; public string BlobName { get; set; } = ""; public string ThumbnailBlobName { get; set; } = ""; } }