SharpRSS/SharpRSS.Blazor/Components/Layout/BaseLayout.razor
2024-06-17 14:47:10 +02:00

46 lines
1.1 KiB
Plaintext

@inherits LayoutComponentBase
<MudThemeProvider @ref="@_themeProvider" Theme="@MudTheme" IsDarkMode="@DarkTheme"/>
<MudDialogProvider/>
<MudSnackbarProvider/>
<CascadingValue Value="this">
<MudLayout>
<MudMainContent>
@Body
</MudMainContent>
</MudLayout>
</CascadingValue>
@code {
public readonly MudTheme MudTheme = new MudTheme();
private MudThemeProvider? _themeProvider;
private bool _isDarkTheme = true;
public event EventHandler<bool>? OnDarkThemeChanged;
public bool DarkTheme
{
get => _isDarkTheme;
set
{
_isDarkTheme = value;
ThemeChanged();
}
}
private async void ThemeChanged()
{
//TODO: Update user settings
StateHasChanged();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _themeProvider != null)
{
DarkTheme = await _themeProvider.GetSystemPreference();
_themeProvider.IsDarkModeChanged = EventCallback.Factory.Create<bool>(this, x => OnDarkThemeChanged?.Invoke(this, x));
}
}
}