[frontend] Add follow request page

This commit is contained in:
Lilian 2024-07-09 02:34:04 +02:00
parent f5f43d6264
commit 21e5e62266
No known key found for this signature in database
5 changed files with 170 additions and 0 deletions

View file

@ -0,0 +1,38 @@
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@using Microsoft.Extensions.Localization
@using Iceshrimp.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.Services
@inject IStringLocalizer<Localization> Loc;
@inject ApiService Api;
@inject NavigationManager NavigationManager;
<div class="follow-request-card">
<UserProfileCard User="FollowRequest.User"></UserProfileCard>
<div class="buttons">
<button @onclick="Accept" class="btn accept">
<Icon Name="Icons.Check"/>
</button>
<button @onclick="Reject" class="btn decline">
<Icon Name="Icons.X"/>
</button>
</div>
</div>
@code {
[Parameter] [EditorRequired] public required FollowRequestResponse FollowRequest { get; set; }
private async void Accept()
{
// FIXME: This should be a fancy animation instead of a reload
await Api.FollowRequests.AcceptFollowRequest(FollowRequest.Id);
NavigationManager.NavigateTo("/follow-requests");
}
private async void Reject()
{
// FIXME: This should be a fancy animation instead of a reloady
await Api.FollowRequests.RejectFollowRequest(FollowRequest.Id);
NavigationManager.NavigateTo("/follow-requests");
}
}

View file

@ -0,0 +1,25 @@
.follow-request-card {
display: flex;
align-items: center;
background-color: var(--foreground-color);
border-radius: 1rem;
justify-content: space-between;
max-width: 50rem;
width: 100%;
margin-bottom: 1rem;
}
.buttons {
display: flex;
}
.btn {
width: 4rem;
height: 4rem;
}
::deep {
.profile-card {
margin-top: 0 !important;
}
}

View file

@ -0,0 +1,93 @@
@using Iceshrimp.Frontend.Core.Miscellaneous
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@using Microsoft.Extensions.Localization
@inject ApiService Api;
@inject IStringLocalizer<Localization> Loc;
@if (_init == LoadState.Ready)
{
<div class="scroller">
@foreach (var el in FollowRequests)
{
<FollowRequestEntry FollowRequest="el"/>
}
<ScrollEnd IntersectionChange="LoadMore" ManualLoad="LoadMore"/>
</div>
}
@if (_init == LoadState.Loading)
{
<div>Loading!</div>
}
@if (_init == LoadState.Emtpy)
{
@Loc["All done!"]
}
@code {
private List<FollowRequestResponse> FollowRequests { get; set; } = [];
private LoadState _init;
private string? _minId;
protected override async Task OnInitializedAsync()
{
await Init();
}
private async Task Init()
{
try
{
var pq = new PaginationQuery { Limit = 20 };
FollowRequests = await Api.FollowRequests.GetFollowRequests(pq);
if (FollowRequests.Count == 0)
{
_init = LoadState.Emtpy;
return;
}
_minId = FollowRequests.Last().Id;
_init = LoadState.Ready;
}
catch (ApiException)
{
_init = LoadState.Error;
}
catch (HttpRequestException)
{
_init = LoadState.Error;
Console.WriteLine("Network error");
}
}
private async Task LoadMore()
{
var pq = new PaginationQuery { MaxId = _minId, Limit = 20 };
var res = await Api.FollowRequests.GetFollowRequests(pq);
if (res.Count > 0)
{
FollowRequests.AddRange(res);
_minId = res.Last().Id;
StateHasChanged();
}
}
protected override async Task OnParametersSetAsync()
{
_init = LoadState.Loading;
_minId = null;
FollowRequests = [];
StateHasChanged();
await Init();
StateHasChanged();
}
private enum LoadState
{
Loading,
Ready,
Emtpy,
Error
}
}

View file

@ -0,0 +1,8 @@
.scroller {
display: flex;
align-items: center;
flex-direction: column;
width: 100%;
overflow-x: scroll;
padding: 0.5rem;
}

View file

@ -0,0 +1,6 @@
@page "/follow-requests"
@using Iceshrimp.Frontend.Components
<FollowRequestList />
@code {
}