SharpRSS/WebSharpRSS/Shared/CategoryGuide.razor

139 lines
4.5 KiB
Plaintext
Raw Normal View History

2023-04-30 20:13:14 +02:00
@using CodeHollow.FeedReader
2023-05-12 23:58:49 +02:00
@using SharpRss.Models
@using ToolQit
@using ToolQit.Containers
@using ToolQit.Extensions
2023-04-30 20:13:14 +02:00
<style>
.cat-item {
2023-05-04 20:59:25 +02:00
background: var(--background-color);
tab-index: 0;
width: 100%;
display: flex;
position: relative;
box-sizing: border-box;
text-align: start;
align-items: center;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 12px;
justify-content: flex-start;
text-decoration: none;
2023-04-30 20:13:14 +02:00
}
.cat-item:hover {
2023-05-04 20:59:25 +02:00
background: var(--hover-bg-color);
2023-04-30 20:13:14 +02:00
}
.cat-item-text {
2023-05-04 20:59:25 +02:00
flex: 1 1 auto;
min-width: 0;
2023-04-30 20:13:14 +02:00
}
.cat-item-icon {
2023-05-04 20:59:25 +02:00
display: inline-flex;
min-width: 56px;
flex-shrink: 0;
2023-04-30 20:13:14 +02:00
}
.feed-item {
2023-05-04 20:59:25 +02:00
background: var(--background-color);
tab-index: 0;
width: 100%;
display: flex;
position: relative;
box-sizing: border-box;
text-align: start;
align-items: center;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 30px;
justify-content: flex-start;
text-decoration: none;
2023-04-30 20:13:14 +02:00
}
.feed-item:hover {
2023-05-04 20:59:25 +02:00
background: var(--hover-bg-color);
2023-04-30 20:13:14 +02:00
}
2023-05-04 20:59:25 +02:00
.feed-item-text {
flex: 1 1 auto;
min-width: 0;
}
.feed-item-icon {
display: inline-flex;
min-width: 56px;
flex-shrink: 0;
}
2023-04-30 20:13:14 +02:00
</style>
<div>
<MudText>@HeaderText</MudText>
2023-05-12 23:58:49 +02:00
@foreach (CategoryModel guideCategory in Categories)
2023-04-30 20:13:14 +02:00
{
<div>
2023-05-12 23:58:49 +02:00
<div @onclick="@(() => ItemClicked(guideCategory))" class="cat-item mud-ripple" style="--hover-bg-color: @Colors.Blue.Accent1; --background-color: @(guideCategory.IsSelected ? Colors.Blue.Accent2 : "transparent")">
2023-04-30 20:13:14 +02:00
<div class="cat-item-icon">
2023-05-12 23:58:49 +02:00
<MudIcon Class="pointer-events-none" Icon="@Icons.Material.Filled.RssFeed" Size="Size.Medium"/>
2023-04-30 20:13:14 +02:00
</div>
<div class="cat-item-text">
2023-05-12 23:58:49 +02:00
<MudText Class="pointer-events-none" Typo="Typo.subtitle1">@guideCategory.Name</MudText>
2023-04-30 20:13:14 +02:00
</div>
</div>
@* Feeds *@
2023-05-12 23:58:49 +02:00
@if (guideCategory.IsExpanded && guideCategory.Feeds != null)
2023-04-30 20:13:14 +02:00
{
2023-05-12 23:58:49 +02:00
foreach (FeedModel feed in guideCategory.Feeds)
2023-04-30 20:13:14 +02:00
{
2023-05-12 23:58:49 +02:00
if (feed == null || feed.Base == null) continue;
<div @onclick="() => ItemClicked(feed)" class="feed-item mud-ripple" style="--hover-bg-color: @Colors.Blue.Accent1; --background-color: @(feed.IsSelected ? Colors.Blue.Accent2 : "transparent")">
2023-05-04 20:59:25 +02:00
<div class="feed-item-icon">
2023-05-12 23:58:49 +02:00
@*@if (!guideFeed.FaviconUrl.IsNullEmptyWhiteSpace())
{
<MudImage ObjectFit="ObjectFit.ScaleDown" Src="@guideFeed.FaviconUrl"/>
}
else
{
<MudIcon Icon="@Icons.Material.Filled.RssFeed" Size="Size.Medium"/>
}*@
<MudIcon Icon="@Icons.Material.Filled.RssFeed" Size="Size.Medium"/>
2023-05-04 20:59:25 +02:00
</div>
<div class="feed-item-text">
2023-05-12 23:58:49 +02:00
<MudText Class="pointer-events-none">@feed.Base.Title</MudText>
2023-04-30 20:13:14 +02:00
</div>
</div>
}
}
</div>
}
</div>
@code {
[Parameter]
public string HeaderText { get; set; }
[Parameter]
2023-05-12 23:58:49 +02:00
public HashSet<CategoryModel> Categories { get; set; } = new HashSet<CategoryModel>();
2023-04-30 20:13:14 +02:00
[Parameter]
2023-05-12 23:58:49 +02:00
public Action<CategoryModel>? CatItemClicked { get; set; }
2023-05-04 20:59:25 +02:00
[Parameter]
2023-05-12 23:58:49 +02:00
public Action<FeedModel>? FeedItemClicked { get; set; }
IGuideItem? _selectedItem;
2023-04-30 20:13:14 +02:00
2023-05-12 23:58:49 +02:00
void ItemClicked(IGuideItem categoryItem)
2023-04-30 20:13:14 +02:00
{
categoryItem.IsExpanded = !categoryItem.IsExpanded;
2023-05-12 23:58:49 +02:00
if (_selectedItem != categoryItem)
2023-04-30 20:13:14 +02:00
{
2023-05-12 23:58:49 +02:00
if (_selectedItem != null)
_selectedItem.IsSelected = false;
_selectedItem = categoryItem;
_selectedItem.IsSelected = true;
2023-04-30 20:13:14 +02:00
}
switch (categoryItem)
{
2023-05-12 23:58:49 +02:00
case CategoryModel catGuideItem:
CatItemClicked?.Invoke(catGuideItem);
break;
2023-05-12 23:58:49 +02:00
case FeedModel feedGuideItem:
FeedItemClicked?.Invoke(feedGuideItem);
break;
}
2023-04-30 20:13:14 +02:00
}
}