Skip to content

Commit

Permalink
feat(frontend): add option to enable disable chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Thundernerd committed Jan 9, 2024
1 parent bd5fcef commit 1ec1260
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/Mangarr.Frontend/Api/BackendApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public Task<Result<JobsScheduleResponse>> GetJobSchedule() =>

public Task<Result<string>> TriggerJob(string group, string name) =>
_httpClient.Get($"jobs/{group}/{name}/trigger");

public Task<Result<ChapterEnableResponse>> EnableChapter(string id) =>
_httpClient.Post<ChapterEnableResponse>($"chapter/{id}/enable", new { });

public Task<Result<ChapterDisableResponse>> DisableChapter(string id) =>
_httpClient.Post<ChapterDisableResponse>($"chapter/{id}/disable", new { });

public Task<Result<MangaEnableChaptersResponse>> EnableMangaChapters(string id) =>
_httpClient.Post<MangaEnableChaptersResponse>($"manga/{id}/enable/chapters", new { });

public Task<Result<MangaDisableChaptersResponse>> DisableMangaChapters(string id) =>
_httpClient.Post<MangaDisableChaptersResponse>($"manga/{id}/disable/chapters", new { });
}
2 changes: 1 addition & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/Content.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ else
{
<div id="wrapper" class="overflow-auto d-flex flex-column">
<ContentHeader Item="@_mangaDetails"/>
<ContentList Items="@_mangaChapters"/>
<ContentList Id="@Id" Items="@_mangaChapters"/>
</div>
}
10 changes: 9 additions & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/ContentList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ else
<table class="table">
<thead>
<tr>
<th></th>
<th>
<svg xmlns="http://www.w3.org/2000/svg" @onclick="EnableChapters" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark-fill chapter-monitor">
<path d="M2 2v13.5a.5.5 0 0 0 .74.439L8 13.069l5.26 2.87A.5.5 0 0 0 14 15.5V2a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2z"></path>
</svg>
/
<svg xmlns="http://www.w3.org/2000/svg" @onclick="DisableChapters" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark chapter-monitor">
<path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.777.416L8 13.101l-5.223 2.815A.5.5 0 0 1 2 15.5V2zm2-1a1 1 0 0 0-1 1v12.566l4.723-2.482a.5.5 0 0 1 .554 0L13 14.566V2a1 1 0 0 0-1-1H4z"></path>
</svg>
</th>
<th>#</th>
<th>Chapter</th>
<th>Released</th>
Expand Down
48 changes: 47 additions & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/ContentList.razor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
using Mangarr.Shared.Models;
using FluentResults;
using Mangarr.Frontend.Api;
using Mangarr.Shared.Models;
using Mangarr.Shared.Responses;
using Microsoft.AspNetCore.Components;

namespace Mangarr.Frontend.Pages.Manga.Item;

public partial class ContentList
{
[Inject] public BackendApi BackendApi { get; set; } = null!;

[Parameter] public string? Id { get; set; }
[Parameter] public List<MangaChapterModel> Items { get; set; } = new();

private async Task EnableChapters()
{
Result<MangaEnableChaptersResponse> result = await BackendApi.EnableMangaChapters(Id);

if (result.IsFailed)
{
// TODO: Log error
}

await UpdateChapters();
}

private async Task DisableChapters()
{
Result<MangaDisableChaptersResponse> result = await BackendApi.DisableMangaChapters(Id);

if (result.IsFailed)
{
// TODO: Log error
}

await UpdateChapters();
}

private async Task UpdateChapters()
{
Result<MangaChaptersResponse> result = await BackendApi.GetMangaChapters(Id);

if (result.IsFailed)
{
// TODO: Log error
}
else
{
Items = result.Value.Data;
}

await InvokeAsync(StateHasChanged);
}
}
3 changes: 3 additions & 0 deletions src/Mangarr.Frontend/Pages/Manga/Item/ContentList.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.chapter-monitor {
cursor: pointer;
}
4 changes: 2 additions & 2 deletions src/Mangarr.Frontend/Pages/Manga/Item/ContentListItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<td>
@if (MarkedForDownload)
{
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark-fill chapter-monitor">
<svg xmlns="http://www.w3.org/2000/svg" @onclick="DisableChapter" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark-fill chapter-monitor">
<path d="M2 2v13.5a.5.5 0 0 0 .74.439L8 13.069l5.26 2.87A.5.5 0 0 0 14 15.5V2a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2z"></path>
</svg>
}
else
{
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark chapter-monitor">
<svg xmlns="http://www.w3.org/2000/svg" @onclick="EnableChapter" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bookmark chapter-monitor">
<path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.777.416L8 13.101l-5.223 2.815A.5.5 0 0 1 2 15.5V2zm2-1a1 1 0 0 0-1 1v12.566l4.723-2.482a.5.5 0 0 1 .554 0L13 14.566V2a1 1 0 0 0-1-1H4z"></path>
</svg>
}
Expand Down
39 changes: 38 additions & 1 deletion src/Mangarr.Frontend/Pages/Manga/Item/ContentListItem.razor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using Mangarr.Shared.Models;
using FluentResults;
using Mangarr.Frontend.Api;
using Mangarr.Shared.Models;
using Mangarr.Shared.Responses;
using Microsoft.AspNetCore.Components;

namespace Mangarr.Frontend.Pages.Manga.Item;

public partial class ContentListItem
{
[Inject] public BackendApi BackendApi { get; set; } = null!;

[Parameter] public MangaChapterModel? Item { get; set; }
[Parameter] public int Index { get; set; }

Expand All @@ -14,4 +19,36 @@ public partial class ContentListItem
private DateTime ReleaseDate => Item!.ReleaseDate;
private bool MarkedForDownload => Item!.MarkedForDownload;
private bool Downloaded => Item!.Downloaded;

private async Task EnableChapter()
{
Result<ChapterEnableResponse> result = await BackendApi.EnableChapter(Item!.Id);

if (result.IsFailed)
{
// TODO: Log error
}
else
{
Item = result.Value.Data;
}

await InvokeAsync(StateHasChanged);
}

private async Task DisableChapter()
{
Result<ChapterDisableResponse> result = await BackendApi.DisableChapter(Item!.Id);

if (result.IsFailed)
{
// TODO: Log error
}
else
{
Item = result.Value.Data;
}

await InvokeAsync(StateHasChanged);
}
}

0 comments on commit 1ec1260

Please sign in to comment.