load PageState in App component and pass to SiteRouter to optimize data loading
This commit is contained in:
		| @ -25,6 +25,7 @@ namespace Oqtane.UI | ||||
|         public string ReturnUrl { get; set; } | ||||
|         public bool IsInternalNavigation { get; set; } | ||||
|         public Guid RenderId { get; set; } | ||||
|         public bool Refresh {  get; set; } | ||||
|  | ||||
|         public List<Page> Pages | ||||
|         { | ||||
|  | ||||
| @ -16,8 +16,8 @@ | ||||
|         @if (string.IsNullOrEmpty(_installation.Message)) | ||||
|         { | ||||
|             <div style="@_display"> | ||||
|                 <CascadingValue Value="@PageState"> | ||||
|                     <SiteRouter RenderMode="@RenderMode" Runtime="@Runtime" VisitorId="@VisitorId" OnStateChange="@ChangeState" /> | ||||
|                 <CascadingValue Value="@_pageState"> | ||||
|                     <SiteRouter RenderMode="@RenderMode" Runtime="@Runtime" OnStateChange="@ChangeState" /> | ||||
|                 </CascadingValue> | ||||
|             </div> | ||||
|         } | ||||
| @ -32,7 +32,7 @@ | ||||
|  | ||||
| @code { | ||||
|     [Parameter] | ||||
|     public string AntiForgeryToken { get; set; } | ||||
|     public PageState PageState { get; set; } = null; | ||||
|  | ||||
|     [Parameter] | ||||
|     public string RenderMode { get; set; } | ||||
| @ -41,13 +41,10 @@ | ||||
|     public string Runtime { get; set; } | ||||
|  | ||||
|     [Parameter] | ||||
|     public int VisitorId { get; set; } | ||||
|     public string AntiForgeryToken { get; set; } = ""; | ||||
|  | ||||
|     [Parameter] | ||||
|     public string RemoteIPAddress { get; set; } | ||||
|  | ||||
|     [Parameter] | ||||
|     public string AuthorizationToken { get; set; } | ||||
|     public string AuthorizationToken { get; set; } = ""; | ||||
|  | ||||
|     [CascadingParameter] | ||||
|     HttpContext HttpContext { get; set; } | ||||
| @ -56,18 +53,23 @@ | ||||
|     private string _display = ""; | ||||
|     private Installation _installation = new Installation { Success = false, Message = "" }; | ||||
|  | ||||
|     private PageState PageState { get; set; } | ||||
|     private PageState _pageState { get; set; } | ||||
|  | ||||
|     protected override async Task OnParametersSetAsync() | ||||
|     { | ||||
|         if (PageState != null) | ||||
|         { | ||||
|             _pageState = PageState;             | ||||
|         } | ||||
|  | ||||
|         if (RenderMode == RenderModes.Interactive) | ||||
|         { | ||||
|             _display = "display: none;"; | ||||
|         } | ||||
|  | ||||
|         SiteState.RemoteIPAddress = RemoteIPAddress; | ||||
|         SiteState.AntiForgeryToken = AntiForgeryToken; | ||||
|         SiteState.AuthorizationToken = AuthorizationToken; | ||||
|         SiteState.RemoteIPAddress = (_pageState != null) ? _pageState.RemoteIPAddress : ""; | ||||
|         SiteState.IsPrerendering = (HttpContext != null) ? true : false; | ||||
|  | ||||
|         _installation = await InstallationService.IsInstalled(); | ||||
| @ -90,7 +92,7 @@ | ||||
|  | ||||
|     private void ChangeState(PageState pageState) | ||||
|     { | ||||
|         PageState = pageState; | ||||
|         _pageState = pageState; | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -35,9 +35,6 @@ | ||||
|     [Parameter] | ||||
|     public string Runtime { get; set; } | ||||
|  | ||||
|     [Parameter] | ||||
|     public int VisitorId { get; set; } | ||||
|  | ||||
|     [CascadingParameter] | ||||
|     PageState PageState { get; set; } | ||||
|  | ||||
| @ -68,7 +65,7 @@ | ||||
|  | ||||
|     protected override async Task OnParametersSetAsync() | ||||
|     { | ||||
|         if (PageState == null) | ||||
|         if (PageState == null || PageState.Refresh) | ||||
|         { | ||||
|             await Refresh(); | ||||
|         } | ||||
| @ -100,6 +97,7 @@ | ||||
|         var editmode = false; | ||||
|         var refresh = false; | ||||
|         var lastsyncdate = DateTime.MinValue; | ||||
|         var visitorId = -1; | ||||
|         _error = ""; | ||||
|  | ||||
|         Route route = new Route(_absoluteUri, SiteState.Alias.Path); | ||||
| @ -148,6 +146,7 @@ | ||||
|         { | ||||
|             editmode = PageState.EditMode; | ||||
|             lastsyncdate = PageState.LastSyncDate; | ||||
|             visitorId = PageState.VisitorId; | ||||
|         } | ||||
|         if (PageState?.Page.Path != route.PagePath) | ||||
|         { | ||||
| @ -159,7 +158,7 @@ | ||||
|         } | ||||
|  | ||||
|         // get user | ||||
|         if (PageState == null || refresh || PageState.Alias.SiteId != SiteState.Alias.SiteId) | ||||
|         if (PageState == null || PageState.Refresh || refresh || PageState.Alias.SiteId != SiteState.Alias.SiteId) | ||||
|         { | ||||
|             var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); | ||||
|             // verify user is authenticated for current site | ||||
| @ -293,11 +292,12 @@ | ||||
|                         LastSyncDate = lastsyncdate, | ||||
|                         RenderMode = RenderMode, | ||||
|                         Runtime = (Shared.Runtime)Enum.Parse(typeof(Shared.Runtime), Runtime), | ||||
| 						VisitorId = VisitorId, | ||||
| 						VisitorId = visitorId, | ||||
| 						RemoteIPAddress = SiteState.RemoteIPAddress, | ||||
| 						ReturnUrl = returnurl, | ||||
|                         IsInternalNavigation = _isInternalNavigation, | ||||
|                         RenderId = Guid.NewGuid() | ||||
|                         RenderId = Guid.NewGuid(), | ||||
|                         Refresh = false | ||||
|                     }; | ||||
|  | ||||
|                     OnStateChange?.Invoke(_pagestate); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 sbwalker
					sbwalker