39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
@using Butter.Dtos.Settings
|
|
@using MilkStream.Services
|
|
@inherits SettingBox
|
|
@inject SettingsService SettingsService
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header">@(Setting?.Name ?? "NO NAME")</div>
|
|
<div class="card-body d-flex justify-content-between align-items-center">
|
|
<p class="card-text">@(Setting?.Description ?? "No description provided")</p>
|
|
<div class="d-flex">
|
|
<div class="mx-2">@(IsPowerOfTwo ? Math.Pow(2, currentValue) : currentValue)</div>
|
|
<input type="range" id="@Setting?.Name" class="form-range" @bind="@currentValue" min="@MinValue" max="@MaxValue"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public int MinValue {get; set;}
|
|
[Parameter]
|
|
public int MaxValue {get; set;} = 100;
|
|
[Parameter]
|
|
public bool IsPowerOfTwo {get; set;}
|
|
[Parameter]
|
|
public int Step {get; set;} = 1;
|
|
private int currentValue;
|
|
|
|
protected override void OnInitialized() {
|
|
SettingsService.BeginSave += (_, _) => SettingsService.UpdateSetting(GetSetting());
|
|
currentValue = int.TryParse(Setting?.Value, out int value) ? value : 0; // Default value if parsing fails
|
|
}
|
|
|
|
protected override SettingDto? GetSetting() {
|
|
if (Setting == null) return null;
|
|
Setting.Value = IsPowerOfTwo ? ((int)Math.Pow(2, currentValue)).ToString() : currentValue.ToString();
|
|
return Setting;
|
|
}
|
|
|
|
} |