Skip to content

Commit

Permalink
#370 - Allow to disable bottom menu by configuring zero items.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 7, 2021
1 parent caa6b99 commit 0595a45
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
56 changes: 30 additions & 26 deletions src/Money.Blazor.Host/Layouts/BottomMenu.razor
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
@if (Items != null)
@if (Items != null && Items.Count > 0)
{
<div class="row my-2 items-@Items.Count">
@foreach (var item in Items)
{
<div class="col">
@if (item.Url != null)
<nav class="fixed-bottom d-block d-sm-none bottom-bar">
<div class="container">
<div class="row my-2 items-@Items.Count">
@foreach (var item in Items)
{
<Match Url="@item.Url" PageType="@item.PageType" Context="IsActive">
<a href="@item.Url" class="btn btn-block @(IsActive ? "btn-primary" : "btn-light")">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</a>
</Match>
}
else
{
<button @onclick="@item.OnClick" class="btn btn-block btn-light">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</button>
<div class="col">
@if (item.Url != null)
{
<Match Url="@item.Url" PageType="@item.PageType" Context="IsActive">
<a href="@item.Url" class="btn btn-block @(IsActive ? "btn-primary" : "btn-light")">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</a>
</Match>
}
else
{
<button @onclick="@item.OnClick" class="btn btn-block btn-light">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</button>
}
</div>
}
</div>
}
</div>
}
</div>
</nav>
}
11 changes: 4 additions & 7 deletions src/Money.Blazor.Host/Layouts/Layout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
<div class="container body-content">
@Body
</div>
<nav class="fixed-bottom d-block d-sm-none bottom-bar">
<div class="container">
<AuthenticatedView>
<BottomMenu />
</AuthenticatedView>
</div>
</nav>
<AuthenticatedView>
<BottomMenu />
</AuthenticatedView>

<footer class="navbar navbar-light d-none d-sm-block">
<div class="container">
<span class="navbar-text">
Expand Down
16 changes: 13 additions & 3 deletions src/Money.Blazor.Host/MenuItems/MenuItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ async Task<object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, Ht
if (query is ListBottomMenuItem)
{
var value = await dispatcher.QueryAsync(new FindUserProperty("MobileMenu"));
var selectedItems = value.Split(',');

Console.WriteLine($"MM: (1) '{value}', {value == null}, {value == String.Empty}");

var selectedItems = value != null ? value.Split(',') : Array.Empty<string>();

return storage.Where(m => selectedItems.Contains(m.Identifier)).ToList<IActionMenuItemModel>();
}
Expand All @@ -76,14 +79,21 @@ async Task<object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, Ht
else if (query is FindUserProperty findProperty && findProperty.Key == "MobileMenu")
{
var value = (string)await next(findProperty);
if (String.IsNullOrEmpty(value))

Console.WriteLine($"MM: (2) '{value}', {value == null}, {value == String.Empty}");

if (value == null)
return DefaultValue;

return value;
}
else if (query is ListUserProperty listProperty)
{
var value = (List<UserPropertyModel>)await next(listProperty);
var property = value.FirstOrDefault(p => p.Key == "MobileMenu");
if (property != null && String.IsNullOrEmpty(property.Value))

Console.WriteLine($"MM: (3) '{property.Value}', {property.Value == null}, {property.Value == String.Empty}");
if (property != null && property.Value == null)
property.Value = DefaultValue;

return value;
Expand Down
4 changes: 3 additions & 1 deletion src/Money.Blazor.Host/Pages/Users/Settings.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ protected async override Task OnInitializedAsync()

await LoadAsync();

MobileSelectedIdentifiers = MobileMenu.CurrentValue.Split(',').ToList();
MobileSelectedIdentifiers = MobileMenu.CurrentValue != null
? MobileMenu.CurrentValue.Split(',').ToList()
: new List<string>(0);
}

public void Dispose()
Expand Down

0 comments on commit 0595a45

Please sign in to comment.