update the code by following the review suggestions.
This commit is contained in:
parent
7b67c9aa8d
commit
fb3a27c02f
|
@ -114,14 +114,19 @@
|
|||
|
||||
if(PageState.User != null) //keep edit mode for authenticated users.
|
||||
{
|
||||
|
||||
var viewMode = PageState.EditMode ? ViewMode.Edit.ToString() : ViewMode.View.ToString();
|
||||
var userSettings = new Dictionary<string, string>
|
||||
if(PageState.EditMode)
|
||||
{
|
||||
{ UserSetting.ViewMode, viewMode }
|
||||
};
|
||||
var userSettings = new Dictionary<string, string>
|
||||
{
|
||||
{ UserSetting.LastViewPageId, PageState.Page.PageId.ToString() }
|
||||
};
|
||||
|
||||
await SettingService.UpdateUserSettingsAsync(userSettings, PageState.User.UserId);
|
||||
await SettingService.UpdateUserSettingsAsync(userSettings, PageState.User.UserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await SettingService.DeleteSettingAsync(EntityNames.User, PageState.User.UserId, UserSetting.LastViewPageId);
|
||||
}
|
||||
}
|
||||
|
||||
// preserve other querystring parameters
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
@inject ILogService LogService
|
||||
@inject ISettingService SettingService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@implements IHandleAfterRender
|
||||
@implements IDisposable
|
||||
|
||||
|
@ -62,17 +61,6 @@
|
|||
};
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var route = new Route(_absoluteUri, SiteState.Alias.Path);
|
||||
var lastViewPage = HttpContextAccessor.HttpContext.Request.Cookies[UserSetting.LastViewPage] ?? string.Empty;
|
||||
if (lastViewPage != route.PagePath)
|
||||
{
|
||||
HttpContextAccessor.HttpContext.Response.Cookies.Append(UserSetting.LastViewPage, route.PagePath);
|
||||
_pageChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
NavigationManager.LocationChanged -= LocationChanged;
|
||||
|
@ -183,19 +171,24 @@
|
|||
visitorId = PageState.VisitorId;
|
||||
}
|
||||
|
||||
|
||||
if (PageState?.Page.Path != route.PagePath || _pageChanged)
|
||||
bool? pageChanged = null;
|
||||
if(user != null && PageState?.Page != null)
|
||||
{
|
||||
var userSettings = await SettingService.GetUserSettingsAsync(user.UserId);
|
||||
if(userSettings.ContainsKey(UserSetting.LastViewPageId))
|
||||
{
|
||||
int.TryParse(userSettings.GetValueOrDefault(UserSetting.LastViewPageId), out int lastViewPageId);
|
||||
pageChanged = lastViewPageId != PageState.Page.PageId;
|
||||
}
|
||||
}
|
||||
|
||||
if (PageState?.Page.Path != route.PagePath || pageChanged.GetValueOrDefault(false))
|
||||
{
|
||||
editmode = false; // reset edit mode when navigating to different page
|
||||
|
||||
if (user != null) //keep edit mode for authenticated users.
|
||||
if (user != null)
|
||||
{
|
||||
var userSettings = new Dictionary<string, string>
|
||||
{
|
||||
{ UserSetting.ViewMode, ViewMode.View.ToString() }
|
||||
};
|
||||
|
||||
await SettingService.UpdateUserSettingsAsync(userSettings, user.UserId);
|
||||
await SettingService.DeleteSettingAsync(EntityNames.User, user.UserId, UserSetting.LastViewPageId);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -208,11 +201,7 @@
|
|||
//check edit mode for authenticated users.
|
||||
if (!editmode && user != null)
|
||||
{
|
||||
Enum.TryParse<ViewMode>(user.Settings.GetValueOrDefault(UserSetting.ViewMode, ViewMode.View.ToString()), true, out ViewMode viewMode);
|
||||
if (viewMode == ViewMode.Edit)
|
||||
{
|
||||
editmode = true;
|
||||
}
|
||||
editmode = pageChanged.HasValue && !pageChanged.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Enums
|
||||
{
|
||||
public enum ViewMode
|
||||
{
|
||||
View,
|
||||
Edit
|
||||
}
|
||||
}
|
|
@ -8,8 +8,6 @@ namespace Oqtane.Models
|
|||
{
|
||||
public class UserSetting
|
||||
{
|
||||
public const string ViewMode = "Page:ViewMode";
|
||||
|
||||
public const string LastViewPage = "LastViewed";
|
||||
public const string LastViewPageId = "Page:LastViewed";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user