Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,57 @@ else
<!-- Grid to Solar -->
@if (GridLocation != default && InverterLocation != default)
{
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@InverterLocation.X" y2="@InverterLocation.Y" stroke="black" />
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@InverterLocation.X" y2="@InverterLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Grid to House -->
@if (GridLocation != default && HomeLocation != default)
{
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@HomeLocation.X" y2="@HomeLocation.Y" stroke="black" />
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@HomeLocation.X" y2="@HomeLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Solar to House -->
@if (InverterLocation != default && HomeLocation != default)
{
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@HomeLocation.X" y2="@HomeLocation.Y" stroke="black" />
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@HomeLocation.X" y2="@HomeLocation.Y" stroke="var(--mud-palette-text-primary)" />
}

<!-- Solar to Home Battery -->
@if (InverterLocation != default && BatteryLocation != default)
{
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="black" />
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Home Battery to House -->
@if (HomeLocation != default && BatteryLocation != default)
{
<line x1="@HomeLocation.X" y1="@HomeLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="black" />
<line x1="@HomeLocation.X" y1="@HomeLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Grid to Home Battery -->
@if (GridLocation != default && BatteryLocation != default)
{
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="black" />
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="var(--mud-palette-text-primary)" />
}

<!-- Home to Charger -->
@if (HomeLocation != default && EvChargerLocation != default)
{
<line x1="@HomeLocation.X" y1="@HomeLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="black" />
<line x1="@HomeLocation.X" y1="@HomeLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="var(--mud-palette-text-primary)" />
}

@if (HomeLocation == default)
{
<!-- Grid to EvCharger -->
@if (GridLocation != default && EvChargerLocation != default)
{
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="black" />
<line x1="@GridLocation.X" y1="@GridLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Solar to EVCharger -->
@if (InverterLocation != default && EvChargerLocation != default)
{
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="black" />
<line x1="@InverterLocation.X" y1="@InverterLocation.Y" x2="@EvChargerLocation.X" y2="@EvChargerLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
<!-- Home Battery to EVCharger -->
@if (EvChargerLocation != default && BatteryLocation != default)
{
<line x1="@EvChargerLocation.X" y1="@EvChargerLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="black" />
<line x1="@EvChargerLocation.X" y1="@EvChargerLocation.Y" x2="@BatteryLocation.X" y2="@BatteryLocation.Y" stroke="var(--mud-palette-text-primary)" />
}
}

Expand All @@ -95,35 +95,35 @@ else
@if (GridLocation != default)
{
<circle cx="@GridLocation.X" cy="@GridLocation.Y" r="40"
fill="@(_pvValues.GridPower == 0 ? "white" : (_pvValues.GridPower > 0 ? Constants.FeedInColor : Constants.ConsumptionColor))"
fill="@(_pvValues.GridPower == 0 ? "var(--mud-palette-background)" : (_pvValues.GridPower > 0 ? Constants.FeedInColor : Constants.ConsumptionColor))"
stroke="@Constants.GridColor" stroke-width="4" />
}
<!-- Solar -->
@if (InverterLocation != default)
{
<circle cx="@InverterLocation.X" cy="@InverterLocation.Y" r="40"
fill="@(_pvValues.InverterPower == 0 ? "white" : Constants.SolarPowerColor)"
fill="@(_pvValues.InverterPower == 0 ? "var(--mud-palette-background)" : Constants.SolarPowerColor)"
stroke="@Constants.SolarPowerColor" stroke-width="4" />
}
<!-- Home Battery -->
@if (BatteryLocation != default)
{
<circle cx="@BatteryLocation.X" cy="@BatteryLocation.Y" r="40"
fill="@(_pvValues.HomeBatteryPower == 0 ? "white" : (_pvValues.HomeBatteryPower > 0 ? Constants.FeedInColor : Constants.ConsumptionColor))"
fill="@(_pvValues.HomeBatteryPower == 0 ? "var(--mud-palette-background)" : (_pvValues.HomeBatteryPower > 0 ? Constants.FeedInColor : Constants.ConsumptionColor))"
stroke="@Constants.BatteryColor" stroke-width="4" />
}
<!-- House -->
@if (HomeLocation != default)
{
<circle cx="@HomeLocation.X" cy="@HomeLocation.Y" r="40"
fill="@(CalculateHomePower() == 0 ? "white" : Constants.HomeConsumptionColor)"
fill="@(CalculateHomePower() == 0 ? "var(--mud-palette-background)" : Constants.HomeConsumptionColor)"
stroke="@Constants.HomeConsumptionColor" stroke-width="4" />
}
<!-- EVCharger -->
@if (EvChargerLocation != default)
{
<circle cx="@EvChargerLocation.X" cy="@EvChargerLocation.Y" r="40"
fill="@(_pvValues.CarCombinedChargingPowerAtHome == 0 ? "white" : Constants.EvChargingColor)"
fill="@(_pvValues.CarCombinedChargingPowerAtHome == 0 ? "var(--mud-palette-background)" : Constants.EvChargingColor)"
stroke="@Constants.EvChargingColor" stroke-width="4" />
}

Expand Down
26 changes: 25 additions & 1 deletion TeslaSolarCharger/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@inject IConstants Constants
@inject ITextLocalizationService TextLocalizer

<MudThemeProvider @ref="@_mudThemeProvider" Theme="_tscTheme" />
<MudThemeProvider @ref="@_mudThemeProvider" @bind-IsDarkMode="_isDarkMode" Theme="_tscTheme" />
<MudPopoverProvider />
<MudDialogProvider FullWidth="true"
MaxWidth="MaxWidth.Medium" />
Expand Down Expand Up @@ -41,10 +41,28 @@
TextLocalizer.Get<SharedComponentLocalizationRegistry>(key)
?? key;

private bool _isDarkMode;
private MudThemeProvider? _mudThemeProvider;

private MudTheme? _tscTheme;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _mudThemeProvider != null)
{
_isDarkMode = await _mudThemeProvider.GetSystemPreference();
await _mudThemeProvider.WatchSystemPreference(OnSystemPreferenceChanged);
StateHasChanged();
}
}

private Task OnSystemPreferenceChanged(bool newValue)
{
_isDarkMode = newValue;
StateHasChanged();
return Task.CompletedTask;
}
Comment on lines +59 to +64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better thread safety and adherence to Blazor's best practices, it's recommended to wrap UI state updates that originate from outside Blazor's UI event loop (like this callback from JavaScript interop) in InvokeAsync. This ensures the update is safely dispatched to the component's synchronization context.

    private Task OnSystemPreferenceChanged(bool newValue)
    {
        _isDarkMode = newValue;
        return InvokeAsync(StateHasChanged);
    }


protected override void OnInitialized()
{
_tscTheme = new MudTheme
Expand All @@ -55,6 +73,12 @@
Secondary = Constants.SecondaryColor,
AppbarBackground = Constants.PrimaryColor, // or a const you define
},
PaletteDark = new PaletteDark
{
Primary = Constants.PrimaryColor,
Secondary = Constants.SecondaryColor,
AppbarBackground = Constants.PrimaryColor,
},
};
}
}
Loading