about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor')
-rw-r--r--MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor83
1 files changed, 83 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
new file mode 100644

index 0000000..2b1d90a --- /dev/null +++ b/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateInitialStateOptions.razor
@@ -0,0 +1,83 @@ +@using System.Text.Json +@using ArcaneLibs.Extensions +@using LibMatrix +@using LibMatrix.Helpers +<tr> + <td style="vertical-align: top;">Initial room state:</td> + <td> + @foreach (var (displayName, events) in new Dictionary<string, List<MatrixEvent>>() { + { "Important room state (before final access rules)", roomBuilder.ImportantState }, + { "Additional room state (after final access rules)", roomBuilder.InitialState }, + }) { + <details open> + + @code + { + // private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", "m.room.server_acl" }; + } + + @* <summary>@displayName: @events.Count(x => !ImplementedStates.Contains(x.Type)) events</summary> *@ + <summary>@displayName: @events.Count events</summary> + <LinkButton OnClick="@(() => { + events.Clear(); + StateHasChanged(); + })">Remove all + </LinkButton> + <LinkButton OnClick="@(() => { + events.Insert(0, new() { + Type = "", + StateKey = "", + RawContent = new(), + }); + StateHasChanged(); + })">Add new event + </LinkButton> + <br/> + @if (events.Count > 1000) { + <span style="color: red;">Warning: Too many initial state events! (more than 1000) - Please use the save/load feature in the state panel instead.</span> + } + else { + int i = 0; + @foreach (var initialState in events) { + <div id="@(initialState.Type + "/" + initialState.StateKey)"> + <span>Event @(++i) (@GetRemoveButton(events, initialState))</span> + <br/> + @* <FancyTextBox Multiline="true" Value="@initialState.ToJson(ignoreNull: true)" *@ + @* ValueChanged="@(json => { *@ + @* if (string.IsNullOrWhiteSpace(json)) *@ + @* events.Remove(initialState); *@ + @* else *@ + @* events.Replace(initialState, JsonSerializer.Deserialize<MatrixEvent>(json)); *@ + @* StateHasChanged(); *@ + @* })"></FancyTextBox> *@ + <FancyTextBoxLazyJson T="MatrixEvent" Value="@initialState" ValueChanged="@(evt => { events.Replace(initialState, evt); })"></FancyTextBoxLazyJson> + <br/> + </div> + } + } + </details> + } + </td> +</tr> + +@code { + + [Parameter] + public required RoomBuilder roomBuilder { get; set; } + + [Parameter] + public required Action PageStateHasChanged { get; set; } + + [Parameter] + public AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private RenderFragment GetRemoveButton(List<MatrixEvent> events, MatrixEvent initialState) { + return @<span> + <LinkButton InlineText="true" OnClick="@(() => { + events.Remove(initialState); + PageStateHasChanged(); + })">Remove</LinkButton> + </span>; + } + +} \ No newline at end of file