Files
decePubClient/Components/ActionBar.razor
T

106 lines
2.9 KiB
Plaintext
Raw Normal View History

2022-12-15 20:03:40 +01:00
@inherits LocalizableComponentBase
<section class="flex flex-col gap-4">
2022-02-14 01:51:52 +01:00
@if (isPosting)
{
<div class="block p-3 md:p-4 rounded-xl neo-raised neo-xs">
2022-02-14 01:51:52 +01:00
<MessageUpsertForm OnMessageSubmit="OnMessageSubmit" />
</div>
}
<div class="flex justify-between gap-3">
2022-02-14 01:51:52 +01:00
<EditForm Model="Filters">
<div class="flex flex-row gap-3">
2022-02-14 01:51:52 +01:00
@if (OnTimelineChanged.HasDelegate)
{
<DSelect TValue="TimelineType" class="w-auto" Value="Filters.TimelineType"
ValueChanged="async v => await OnTimelineChange(v)" ValueExpression="() => Filters.TimelineType">
<Prefix>
2022-02-14 01:51:52 +01:00
<i class="@Filters.TimelineType.GetTimelineTypeIcon()"></i>
</Prefix>
<ChildContent>
@foreach (var timelineType in Enum.GetValues<TimelineType>())
{
<option value="@timelineType">@Localizer[timelineType.ToString()]</option>
}
</ChildContent>
</DSelect>
2022-02-14 01:51:52 +01:00
}
@if (OnTimeSortingChanged.HasDelegate)
{
<DSelect TValue="TimeSortingType" class="w-auto" Value="Filters.TimeSortingType"
ValueChanged="async v => await OnTimeSortChange(v)" ValueExpression="() => Filters.TimeSortingType">
<Prefix>
2022-02-14 01:51:52 +01:00
<i class="ion-md-funnel"></i>
</Prefix>
<ChildContent>
@foreach (var timeSortingType in Enum.GetValues<TimeSortingType>())
{
<option value="@timeSortingType">@Localizer[timeSortingType.ToString()]</option>
}
</ChildContent>
</DSelect>
2022-02-14 01:51:52 +01:00
}
</div>
</EditForm>
@if (OnMessageSubmit.HasDelegate)
{
<div>
<DButton Active="isPosting" OnClick="OpenCloseMessageForm">
<i class="ion-md-create"></i>
2022-12-15 20:03:40 +01:00
<span>@Localizer["Post"]</span>
</DButton>
2022-02-14 01:51:52 +01:00
</div>
}
else
{
<div></div>
}
</div>
</section>
2022-02-14 01:51:37 +01:00
@code {
2022-02-14 01:51:52 +01:00
[Parameter] public EventCallback<MessageForm> OnMessageSubmit { get; set; }
[Parameter] public EventCallback<TimelineType> OnTimelineChanged { get; set; }
[Parameter] public EventCallback<TimeSortingType> OnTimeSortingChanged { get; set; }
[Inject] ILocalStorageService LocalStorage { get; set; }
bool isPosting;
2022-02-14 01:51:52 +01:00
ActionBarFilter Filters { get; set; } = new();
protected override async Task OnInitializedAsync()
{
var filters = await LocalStorage.GetItemAsync<ActionBarFilter>(nameof(ActionBarFilter));
IsLoading = false;
if (filters is not null)
{
2022-02-14 01:51:52 +01:00
Filters = filters;
return;
}
await LocalStorage.SetItemAsync(nameof(ActionBarFilter), Filters);
2022-02-14 01:51:52 +01:00
}
void OpenCloseMessageForm()
{
isPosting = !isPosting;
}
2022-02-14 01:51:52 +01:00
async Task OnTimelineChange(TimelineType timelineType)
{
Filters.TimelineType = timelineType;
await LocalStorage.SetItemAsync(nameof(ActionBarFilter), Filters);
await OnTimelineChanged.InvokeAsync(Filters.TimelineType);
}
2022-02-14 01:51:52 +01:00
async Task OnTimeSortChange(TimeSortingType timeSorting)
{
Filters.TimeSortingType = timeSorting;
await LocalStorage.SetItemAsync(nameof(ActionBarFilter), Filters);
await OnTimeSortingChanged.InvokeAsync(Filters.TimeSortingType);
}
2022-02-14 01:51:37 +01:00
}