[frontend] Add notification panel to appropriate places

This commit is contained in:
Lilian 2024-06-28 21:35:39 +02:00 committed by Laura Hausmann
parent da124c5c98
commit ffe56307f3
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 35 additions and 6 deletions

View file

@ -9,6 +9,7 @@
{ {
<NotificationComponent NotificationResponse="el" @key="el.Id"/> <NotificationComponent NotificationResponse="el" @key="el.Id"/>
} }
<ScrollEnd ManualLoad="LoadMore" IntersectionChange="LoadMore"></ScrollEnd>
</div> </div>
} }

View file

@ -11,6 +11,7 @@ public partial class NotificationList : IAsyncDisposable
[Inject] private ApiService Api { get; set; } = null!; [Inject] private ApiService Api { get; set; } = null!;
private List<NotificationResponse> Notifications { get; set; } = []; private List<NotificationResponse> Notifications { get; set; } = [];
private State _state = State.Loading; private State _state = State.Loading;
private string? _minId;
private enum State private enum State
{ {
@ -24,12 +25,17 @@ public partial class NotificationList : IAsyncDisposable
try try
{ {
var res = await Api.Notifications.GetNotifications(new PaginationQuery()); var res = await Api.Notifications.GetNotifications(new PaginationQuery());
Notifications = res; if (res.Count > 0)
foreach (var el in res)
{ {
Console.WriteLine(el.Type); Notifications = res;
_minId = res.Last().Id;
foreach (var el in res)
{
Console.WriteLine(el.Type);
}
} }
_state = State.Init; _state = State.Init;
} }
catch (ApiException) catch (ApiException)
@ -38,6 +44,18 @@ public partial class NotificationList : IAsyncDisposable
} }
} }
private async Task LoadMore()
{
var pq = new PaginationQuery { MaxId = _minId, Limit = 20 };
var res = await Api.Notifications.GetNotifications(pq);
if (res.Count > 0)
{
Notifications.AddRange(res);
_minId = res.Last().Id;
StateHasChanged();
}
}
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
StreamingService.Notification += OnNotification; StreamingService.Notification += OnNotification;

View file

@ -3,4 +3,5 @@
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
width: 100%; width: 100%;
overflow-x: scroll;;
} }

View file

@ -1,5 +1,6 @@
@using Iceshrimp.Frontend.Components
<div class="widget-panel"> <div class="widget-panel">
Widget Panel goes here. <NotificationList />
</div> </div>
@code { @code {

View file

@ -1,7 +1,9 @@
.widget-panel{ .widget-panel{
display: flex; display: flex;
max-width: 20rem; max-width: 23rem;
min-width: 20rem; min-width: 23rem;
position: sticky; position: sticky;
top: 0; top: 0;
max-height: 100vh;
padding-left: 1rem;
} }

View file

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