diff --git a/src/Recollections.Blazor.UI/Accounts/Components/UserStateComponentBase.cs b/src/Recollections.Blazor.UI/Accounts/Components/UserStateComponentBase.cs new file mode 100644 index 0000000..38cfe35 --- /dev/null +++ b/src/Recollections.Blazor.UI/Accounts/Components/UserStateComponentBase.cs @@ -0,0 +1,16 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; + +namespace Neptuo.Recollections.Accounts.Components; + +public abstract class UserStateComponentBase : ComponentBase +{ + [CascadingParameter] + protected UserState UserState { get; set; } + + protected async override Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + await UserState.EnsureInitializedAsync(); + } +} \ No newline at end of file diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor b/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor index 270ad3f..1b8211a 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor @@ -1,6 +1,7 @@ @using Neptuo.Recollections.Accounts @page "/connections" @layout Commons.Layouts.MainLayout +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor.cs b/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor.cs index 1d150b4..1f33004 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor.cs +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Connections.razor.cs @@ -15,9 +15,6 @@ public partial class Connections [Inject] protected Api Api { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - protected Modal ShareModal { get; set; } protected ConnectionModel ShareConnection { get; set; } @@ -30,11 +27,7 @@ public partial class Connections protected async override Task OnInitializedAsync() { - IsLoading = true; - await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); - await LoadDataAsync(); } diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor b/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor index 37e7027..f130257 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor @@ -1,4 +1,5 @@ @page "/login" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor.cs b/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor.cs index 0e6f952..7849462 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor.cs +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Login.razor.cs @@ -19,9 +19,6 @@ public partial class Login [Inject] protected ILog Log { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - [Required] protected string UserName { get; set; } @@ -34,8 +31,7 @@ public partial class Login protected async override Task OnInitializedAsync() { await base.OnInitializedAsync(); - - await UserState.EnsureInitializedAsync(); + if (UserState.IsAuthenticated) Navigator.OpenTimeline(); } diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor b/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor index 3212b4d..e50f3fe 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor @@ -1,5 +1,6 @@ @page "/users/{UserId}" @layout Commons.Layouts.MainLayout +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor.cs b/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor.cs index b58621d..f77f26e 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor.cs +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Profile.razor.cs @@ -19,9 +19,6 @@ public partial class Profile [Inject] protected UiOptions UiOptions { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - [Parameter] public string UserId { get; set; } @@ -29,12 +26,6 @@ public partial class Profile protected OwnerModel Owner { get; set; } protected PermissionContainerState Permissions { get; } = new PermissionContainerState(); - protected async override Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); - } - public async override Task SetParametersAsync(ParameterView parameters) { var oldUserId = UserId; diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor b/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor index b74b20e..9084996 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor @@ -1,4 +1,5 @@ -@page "/register" +@page "/register" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor.cs b/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor.cs index 33fbeb8..2907bc1 100644 --- a/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor.cs +++ b/src/Recollections.Blazor.UI/Accounts/Pages/Register.razor.cs @@ -17,9 +17,6 @@ public partial class Register [Inject] protected Navigator Navigator { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - public List ErrorMessages { get; } = new List(); public string UserName { get; set; } @@ -29,7 +26,6 @@ protected async override Task OnInitializedAsync() { await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); if (UserState.IsAuthenticated) Navigator.OpenTimeline(); } diff --git a/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor b/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor index 260639e..f04f343 100644 --- a/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor +++ b/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor @@ -1,4 +1,6 @@ - +@inherits UserStateComponentBase + +
diff --git a/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor.cs b/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor.cs index 4557eff..eca47c5 100644 --- a/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Components/EntryPicker.razor.cs @@ -21,9 +21,6 @@ public partial class EntryPicker [Parameter] public Action Selected { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - protected Modal Modal { get; set; } private int offset; diff --git a/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor b/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor index 60bd6c0..e28f19a 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor @@ -1,4 +1,5 @@ @page "/beings/{BeingId}" +@inherits UserStateComponentBase @if (Model != null) { diff --git a/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor.cs index 5841dad..9b8b927 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/BeingDetail.razor.cs @@ -21,9 +21,6 @@ public partial class BeingDetail [Inject] protected Navigator Navigator { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - private string previousBeingId; [Parameter] @@ -36,12 +33,6 @@ public partial class BeingDetail protected BeingIconPicker IconPicker { get; set; } - protected async override Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); - } - public override Task SetParametersAsync(ParameterView parameters) { previousBeingId = BeingId; diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor b/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor index 421e8ff..ae4e04c 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor @@ -1,4 +1,5 @@ @page "/beings" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor.cs index 8deb9dc..a9806b5 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Beings.razor.cs @@ -21,9 +21,6 @@ public partial class Beings [Inject] protected Api Api { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - protected bool IsLoading { get; set; } public string Name { get; set; } @@ -36,8 +33,6 @@ protected async override Task OnInitializedAsync() IsLoading = true; await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); - await LoadDataAsync(); } diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor b/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor index 94d6a42..a0d82cf 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor @@ -1,6 +1,7 @@ @page "/calendar" @page "/calendar/{Year:int}" @page "/calendar/{Year:int}/{Month:int}" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor.cs index 866d414..c999904 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Calendar.razor.cs @@ -23,9 +23,6 @@ public partial class Calendar [Inject] protected Navigator Navigator { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - [Parameter] public int? Year { get; set; } @@ -44,12 +41,6 @@ public partial class Calendar protected List Models { get; } = new List(); - protected override async Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); - } - public override async Task SetParametersAsync(ParameterView parameters) { int? prevYear = Year; diff --git a/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor b/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor index 3202dd6..8038405 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor @@ -1,4 +1,5 @@ @page "/entries/{EntryId}" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor.cs index 05ef57a..30d584d 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/EntryDetail.razor.cs @@ -43,9 +43,6 @@ public partial class EntryDetail [Inject] protected IExceptionHandler ExceptionHandler { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - private string previousEntryId; [Parameter] @@ -90,7 +87,6 @@ protected async override Task OnInitializedAsync() Log.Debug("OnInitializedAsync"); await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); if (UserState.IsAuthenticated) PoiToggleButton = new PoiToggleButton(Navigator, Properties, UserState); diff --git a/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor b/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor index 6fd4c1f..e810ba2 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor @@ -1,4 +1,5 @@ @page "/entries/{EntryId}/images/{ImageId}" +@inherits UserStateComponentBase @if (Model != null) { diff --git a/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor.cs index 70840cb..789acf9 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/ImageDetail.razor.cs @@ -37,9 +37,6 @@ public partial class ImageDetail [Parameter] public string ImageId { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - private ImageModel original; protected ImageModel Model { get; set; } protected OwnerModel Owner { get; set; } @@ -47,12 +44,6 @@ public partial class ImageDetail protected PermissionContainerState Permissions { get; } = new PermissionContainerState(); - protected async override Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); - } - public override Task SetParametersAsync(ParameterView parameters) { previousImageId = ImageId; diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Map.razor b/src/Recollections.Blazor.UI/Entries/Pages/Map.razor index ed23ce6..b0ed0a1 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Map.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Map.razor @@ -1,5 +1,6 @@ -@layout Commons.Layouts.HeadLayout -@page "/map" +@page "/map" +@layout Commons.Layouts.HeadLayout +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Map.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Map.razor.cs index 02a9b4e..96304bd 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Map.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Map.razor.cs @@ -23,9 +23,6 @@ public partial class Map [Inject] protected PropertyCollection Properties { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - protected List Entries { get; set; } = new List(); protected List Markers { get; } = new List(); @@ -37,7 +34,6 @@ protected async override Task OnInitializedAsync() PoiToggleButton = new PoiToggleButton(Navigator, Properties, UserState); await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); await LoadAsync(); } diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Search.razor b/src/Recollections.Blazor.UI/Entries/Pages/Search.razor index a78db19..bc4a8a9 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Search.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Search.razor @@ -1,4 +1,5 @@ @page "/search" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Search.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Search.razor.cs index f93dc31..59448e9 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Search.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Search.razor.cs @@ -21,9 +21,6 @@ public partial class Search : IDisposable [Inject] protected ILog Log { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - [Inject] protected Api Api { get; set; } @@ -49,7 +46,6 @@ public partial class Search : IDisposable protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); Navigator.LocationChanged += OnLocationChanged; } diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor b/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor index d25c402..10a60a1 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor @@ -1,4 +1,5 @@ @page "/stories" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor.cs index 21ef54b..a75135e 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Stories.razor.cs @@ -21,9 +21,6 @@ public partial class Stories [Inject] protected Api Api { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - protected bool IsLoading { get; set; } public string Title { get; set; } @@ -36,8 +33,6 @@ protected async override Task OnInitializedAsync() IsLoading = true; await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); - await LoadDataAsync(); } diff --git a/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor b/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor index 0be8ae5..6c29970 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor @@ -1,4 +1,5 @@ @page "/stories/{StoryId}" +@inherits UserStateComponentBase @if (Model != null) { diff --git a/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor.cs index 617ec31..15c0e5b 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/StoryDetail.razor.cs @@ -30,9 +30,6 @@ public partial class StoryDetail [Inject] protected IExceptionHandler ExceptionHandler { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - private string previousStoryId; [Parameter] @@ -43,12 +40,6 @@ public partial class StoryDetail protected OwnerModel Owner { get; set; } protected PermissionContainerState Permissions { get; } = new PermissionContainerState(); - protected async override Task OnInitializedAsync() - { - await base.OnInitializedAsync(); - await UserState.EnsureInitializedAsync(); - } - public override Task SetParametersAsync(ParameterView parameters) { previousStoryId = StoryId; diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor b/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor index 0083301..e138f64 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor +++ b/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor @@ -1,4 +1,5 @@ @page "/" +@inherits UserStateComponentBase diff --git a/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor.cs b/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor.cs index ef38c7e..56335da 100644 --- a/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor.cs +++ b/src/Recollections.Blazor.UI/Entries/Pages/Timeline.razor.cs @@ -28,9 +28,6 @@ public partial class Timeline [Inject] protected ILog Log { get; set; } - [CascadingParameter] - protected UserState UserState { get; set; } - [Parameter] public bool AllowCreate { get; set; } = true; @@ -51,7 +48,6 @@ protected async override Task OnInitializedAsync() Log.Debug("Timeline.Init"); await base.OnInitializedAsync(); - await UserState.EnsureAuthenticatedAsync(); Log.Debug("Timeline.Load"); await LoadAsync();