Skip to content

Commit

Permalink
Revert "feat: Global Navigation Layer (#708)"
Browse files Browse the repository at this point in the history
This reverts commit 676b773.
  • Loading branch information
capdiem authored Jul 11, 2024
1 parent 676b773 commit 4384b0e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 94 deletions.
58 changes: 15 additions & 43 deletions src/Masa.Stack.Components/Configs/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

public class GlobalConfig : IScopedDependency
{
private const string DarkStoreKey = "GlobalConfig_IsDark";
private const string MiniStoreKey = "GlobalConfig_NavigationMini";
private const string FavoriteStoreKey = "GlobalConfig_Favorite";
private const string LangStoreKey = "GlobalConfig_Lang";
private const string NavLayerStoreKey = "GlobalConfig_NavLayer";
private const string DarkCookieKey = "GlobalConfig_IsDark";
private const string MiniCookieKey = "GlobalConfig_NavigationMini";
private const string FavoriteCookieKey = "GlobalConfig_Favorite";
private const string LangCookieKey = "GlobalConfig_Lang";

private readonly LocalStorage _localStore;
private readonly CookieStorage _cookieStorage;
private readonly I18n _i18N;
private bool _dark;
private bool _mini;
private string _favorite;
private Guid _currentTeamId;
private int _navLayer = 2;

public List<int> NavLayerItems = new List<int> { 1, 2, 3 };

public delegate void GlobalConfigChanged();

Expand All @@ -26,14 +22,10 @@ public class GlobalConfig : IScopedDependency

public event CurrentTeamChanged? OnCurrentTeamChanged;

public delegate Task NavLayerChanged();

public event NavLayerChanged? OnNavLayerChanged;

public GlobalConfig(I18n i18n, LocalStorage localStore)
public GlobalConfig(CookieStorage cookieStorage, I18n i18n)
{
_cookieStorage = cookieStorage;
_i18N = i18n;
_localStore = localStore;
}

public CultureInfo Culture
Expand All @@ -42,7 +34,7 @@ public CultureInfo Culture
set
{
_i18N.SetCulture(new CultureInfo("en-US"), value);
_localStore.SetItemAsync(LangStoreKey, value.Name);
_cookieStorage.SetAsync(LangCookieKey, value.Name);
OnLanguageChanged?.Invoke();
}
}
Expand All @@ -69,7 +61,7 @@ public bool Dark
set
{
_dark = value;
_localStore.SetItemAsync(DarkStoreKey, value);
_cookieStorage.SetAsync(DarkCookieKey, value);
}
}

Expand All @@ -81,7 +73,7 @@ public bool Mini
set
{
_mini = value;
_localStore?.SetItemAsync(MiniStoreKey, value);
_cookieStorage?.SetAsync(MiniCookieKey, value);
}
}

Expand All @@ -91,40 +83,20 @@ public string Favorite
set
{
_favorite = value;
_localStore?.SetItemAsync(FavoriteStoreKey, value);
}
}

public int NavLayer
{
get => _navLayer;
set
{
if (_navLayer != value)
{
_navLayer = value;
OnNavLayerChanged?.Invoke();
_localStore.SetItemAsync(NavLayerStoreKey, value);
}
_cookieStorage?.SetAsync(FavoriteCookieKey, value);
}
}

public async void Initialization()
{
_dark = Convert.ToBoolean(await _localStore.GetItemAsync(DarkStoreKey));
bool.TryParse(await _localStore.GetItemAsync(MiniStoreKey), out _mini);
_favorite = await _localStore.GetItemAsync(FavoriteStoreKey) ?? string.Empty;
_dark = Convert.ToBoolean(await _cookieStorage.GetAsync(DarkCookieKey));
bool.TryParse(await _cookieStorage.GetAsync(MiniCookieKey), out _mini);
_favorite = await _cookieStorage.GetAsync(FavoriteCookieKey);

var lang = await _localStore.GetItemAsync(LangStoreKey);
var lang = await _cookieStorage.GetAsync(LangCookieKey);
if (!string.IsNullOrWhiteSpace(lang))
{
_i18N.SetCulture(new CultureInfo("en-US"), new CultureInfo(lang));
}

var navLayer = await _localStore.GetItemAsync<int>(NavLayerStoreKey);
if (navLayer > 0)
{
_navLayer = navLayer;
}
}
}
4 changes: 1 addition & 3 deletions src/Masa.Stack.Components/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,5 @@
},
"403Tips": "You are not authorized! ",
"404Tips": "The requested URL was not found.",
"BackToHome": "Back to home",
"NavigationLayerLabel": "Menu display",
"Layer": "layer"
"BackToHome": "Back to home"
}
4 changes: 1 addition & 3 deletions src/Masa.Stack.Components/Locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,5 @@
"Create": "Создать",
"403Tips": "У вас нет разрешения!",
"404Tips": "Не найден запрашиваемый URL.",
"BackToHome": "Вернуться на главную",
"NavigationLayerLabel": "Меню Показать",
"Layer": "Слой"
"BackToHome": "Вернуться на главную"
}
4 changes: 1 addition & 3 deletions src/Masa.Stack.Components/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,5 @@
"Create": "新建",
"403Tips": "您未经授权!",
"404Tips": "找不到请求的URL。",
"BackToHome": "回到主页",
"NavigationLayerLabel": "菜单显示",
"Layer": ""
"BackToHome": "回到主页"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@

@code {

private RenderFragment RenderNestNav(ExpansionMenu menu, int layer = 1) => __builder =>
private RenderFragment RenderNestNav(ExpansionMenu menu) => __builder =>
{
@RenderNav(menu)

if (GlobalConfig.NavLayer <= layer)
{
return;
}

if (menu.Children.Count != 0)
{
foreach (var child in menu.Children)
{
layer++;
@RenderNestNav(child, layer)
@RenderNestNav(child)
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ public partial class ExpansionAppWrapper
[Parameter]
public EventCallback<ExpansionMenu> OnItemOperClick { get; set; }

[Inject]
public GlobalConfig GlobalConfig { get; set; } = null!;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

GlobalConfig.OnNavLayerChanged += Changed;
}

private async Task ItemOperClick()
{
await OnItemOperClick.InvokeAsync(Value);
Expand Down Expand Up @@ -53,15 +43,4 @@ private static string GetClass(ExpansionMenu menu)

return string.Join(" ", css);
}

async Task Changed()
{
await InvokeAsync(StateHasChanged);
}

protected override ValueTask DisposeAsyncCore()
{
GlobalConfig.OnNavLayerChanged -= Changed;
return base.DisposeAsyncCore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@
<div class="d-flex">
<span class="global-nav-header__title">@T("GlobalNavigation")</span>
<MSpacer />
<div style="width: 140px;" Class="mr-6">
<SSelect @bind-Value="GlobalConfig.NavLayer" Items="GlobalConfig.NavLayerItems" ItemText="@(v => $"{v.ToWords()} {T("Layer")}")" ItemValue="v=> v" Label="@T("NavigationLayerLabel")" Small />
</div>

<SSearch Dense Class="mr-6" Value="@_search" ValueChanged="SearchChanged" />
<MButton Icon OnClick="() => _visible = false">
<MIcon>mdi-close</MIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public partial class GlobalNavigation : MasaComponentBase
[Parameter]
public Func<string, Task>? OnFavoriteRemove { get; set; }

[Inject]
public GlobalConfig GlobalConfig { get; set; } = null!;

private bool _visible;
private List<(string name, string url)>? _recentVisits;
private List<KeyValuePair<string, string>>? _recommendApps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ async Task Changed()
await InvokeAsync(StateHasChanged);
}

protected override async ValueTask DisposeAsyncCore()
public async void Dispose()
{
NoticeState.OnNoticeChanged -= Changed;
if (HubConnection != null)
{
await HubConnection.DisposeAsync();
}
await base.DisposeAsyncCore();
await HubConnection.DisposeAsync();
}
}

0 comments on commit 4384b0e

Please sign in to comment.