@page "/rooms/edit/{RoomId:int}" @rendermode InteractiveServer @inject ImageUrlService Img Edit Room @RoomId

Edit Room #@RoomId

@if (loading) {
} else if (!string.IsNullOrEmpty(error)) {
@error
} else if (roomData == null) {
Room not found.
} else {
Room Info
@if (!string.IsNullOrEmpty(editImageName)) { preview }
Settings
Flags

Platform Support
@if (roomData.SubRooms?.Count > 0) {
SubRooms (@roomData.SubRooms.Count)
@foreach (var sub in roomData.SubRooms) { }
IDSubRoomIdNameMax PlayersIs SandboxAccessibility
@sub.Id @sub.SubRoomId @sub.Name @sub.MaxPlayers @sub.IsSandbox @sub.Accessibility
} @if (roomData.LoadScreens?.Count > 0) {
Load Screens (@roomData.LoadScreens.Count)
@foreach (var ls in roomData.LoadScreens) {
@ls.ImageUrl - @ls.Tooltip
}
}
Back to Search
@if (!string.IsNullOrEmpty(saveMessage)) {
@saveMessage
}
} @code { [Parameter] public int RoomId { get; set; } private bool loading = true; private bool saving; private bool deleting; private string? error; private string? saveMessage; private RoomDetails? roomData; private int editRoomId; private string editName = ""; private string editDescription = ""; private string editImageName = ""; private int editCreatorAccountId; private string editTags = "[]"; private int editState; private int editAccessibility; private int editMinLevel; private int editWarningMask; private string? editCustomWarning; private bool editIsDorm; private bool editIsRRO; private bool editCloningAllowed; private bool editSupportsVRLow; private bool editSupportsQuest2; private bool editSupportsMobile; private bool editSupportsScreens; private bool editSupportsWalkVR; private bool editSupportsTeleportVR; private bool editSupportsJuniors; protected override async Task OnInitializedAsync() { await LoadRoom(); } private async Task LoadRoom() { loading = true; error = null; try { roomData = await Http.GetFromJsonAsync($"/admin/api/rooms/{RoomId}"); if (roomData?.Room != null) { var r = roomData.Room; editRoomId = r.RoomId; editName = r.Name; editDescription = r.Description; editImageName = r.ImageName ?? ""; editCreatorAccountId = r.CreatorAccountId; editTags = r.Tags ?? "[]"; editState = r.State; editAccessibility = r.Accessibility; editMinLevel = r.MinLevel; editWarningMask = r.WarningMask; editCustomWarning = r.CustomWarning; editIsDorm = r.IsDorm; editIsRRO = r.IsRRO; editCloningAllowed = r.CloningAllowed; editSupportsVRLow = r.SupportsVRLow; editSupportsQuest2 = r.SupportsQuest2; editSupportsMobile = r.SupportsMobile; editSupportsScreens = r.SupportsScreens; editSupportsWalkVR = r.SupportsWalkVR; editSupportsTeleportVR = r.SupportsTeleportVR; editSupportsJuniors = r.SupportsJuniors; } } catch (Exception ex) { error = $"Failed to load room: {ex.Message}"; } finally { loading = false; } } private async Task SaveChanges() { saving = true; saveMessage = null; try { var payload = new { name = editName, description = editDescription, imageName = editImageName, state = editState, accessibility = editAccessibility, isDorm = editIsDorm, isRRO = editIsRRO, cloningAllowed = editCloningAllowed, minLevel = editMinLevel, warningMask = editWarningMask, customWarning = editCustomWarning, supportsVRLow = editSupportsVRLow, supportsQuest2 = editSupportsQuest2, supportsMobile = editSupportsMobile, supportsScreens = editSupportsScreens, supportsWalkVR = editSupportsWalkVR, supportsTeleportVR = editSupportsTeleportVR, supportsJuniors = editSupportsJuniors, tags = editTags }; var response = await Http.PutAsJsonAsync($"/admin/api/rooms/{RoomId}", payload); response.EnsureSuccessStatusCode(); saveMessage = "Room updated successfully!"; } catch (Exception ex) { saveMessage = $"Error: {ex.Message}"; } finally { saving = false; } } private async Task DeleteRoom() { if (!await ConfirmDelete()) return; deleting = true; saveMessage = null; try { var response = await Http.DeleteAsync($"/admin/api/rooms/{RoomId}"); response.EnsureSuccessStatusCode(); saveMessage = "Room deleted successfully!"; } catch (Exception ex) { saveMessage = $"Error: {ex.Message}"; } finally { deleting = false; } } private async Task ConfirmDelete() { var confirmed = await JSRuntime.InvokeAsync("confirm", $"Are you sure you want to delete room #{RoomId} and all its subrooms, load screens, promotions, and roles? This cannot be undone."); return confirmed; } [Inject] private IJSRuntime JSRuntime { get; set; } = default!; [Inject] private HttpClient Http { get; set; } = default!; private class RoomDetails { public Room? Room { get; set; } public List? SubRooms { get; set; } public List? LoadScreens { get; set; } } }