-
Notifications
You must be signed in to change notification settings - Fork 9
/
MainLayout.razor
75 lines (67 loc) · 2.56 KB
/
MainLayout.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@using Trackor.Features.Theme
@inherits FluxorLayout
@using Trackor.Features.Database
@using Trackor.Features.Pomodoro.Components
@using Trackor.Features.Weather.Components
@inject IState<ThemeState> ThemeState
@inject NavigationManager NavigationManager
@inject IDispatcher Dispatcher
<MudThemeProvider @bind-IsDarkMode="@isDarkMode" />
<MudDialogProvider />
<MudSnackbarProvider />
<UpdateDetector />
@if (themeLoading)
{
<div class="splash-screen">
<div class="splash-container">
<img class="splash-image" src="loading-water.gif" />
<p class="splash-message">
<strong>Trackor</strong> theme is loading ...
</p>
</div>
</div>
}
else
{
<MudLayout>
<MudAppBar Elevation="1">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => drawerOpen = !drawerOpen)" />
<MudText Typo="Typo.h6"><MudButton Variant="Variant.Text" OnClick="NavigateHome" Color="Color.Inherit">Trackor</MudButton></MudText>
<MudSpacer />
<PomodoroWidget />
<MudSpacer />
<WeatherWidget />
<MudIconButton Icon="@themeIcon" Color="Color.Inherit" OnClick="ToggleThemeMode" Class="mr-3" />
<MudIconButton Icon="@Icons.Custom.Brands.GitHub" Color="Color.Inherit" Link="https://github.com/eric-king/trackor/" Target="_blank" />
</MudAppBar>
<MudDrawer @bind-Open="drawerOpen" Variant="DrawerVariant.Mini" ClipMode="DrawerClipMode.Always" Elevation="6">
<NavMenu />
</MudDrawer>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="mt-6">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>
}
@code {
bool themeLoading = true;
bool drawerOpen = false;
bool isDarkMode = false;
string themeIcon = Icons.Material.Filled.DarkMode;
protected override void OnInitialized()
{
SubscribeToAction<ThemeSetDarkModeAction>(SetDarkMode);
Dispatcher.Dispatch(new DatabaseSetUpDbAction());
base.OnInitialized();
}
private void NavigateHome() => NavigationManager.NavigateTo("/");
private void ToggleThemeMode() => Dispatcher.Dispatch(new ThemeToggleDarkModeAction());
private void SetDarkMode(ThemeSetDarkModeAction action)
{
themeLoading = false;
isDarkMode = action.IsDarkMode;
themeIcon = isDarkMode ? Icons.Material.Filled.LightMode : Icons.Material.Filled.DarkMode;
InvokeAsync(StateHasChanged);
}
}