diff --git a/Iceshrimp.Frontend/Components/NotificationComponent.razor b/Iceshrimp.Frontend/Components/NotificationComponent.razor new file mode 100644 index 00000000..5405ce5f --- /dev/null +++ b/Iceshrimp.Frontend/Components/NotificationComponent.razor @@ -0,0 +1,67 @@ +@using Iceshrimp.Shared.Schemas +@using Iceshrimp.Frontend.Components.Note +@using Iceshrimp.Frontend.Localization +@using Microsoft.Extensions.Localization +@inject IStringLocalizer Loc; +@inject NavigationManager NavigationManager + + +
+ @if (NotificationResponse is { User: not null, Type: "like" or "follow" }) + { + +
+ @(NotificationResponse.User.DisplayName ?? NotificationResponse.User.Username) + + @if (NotificationResponse is { Note: not null, Type: "like", User: not null }) + { + + @Loc["liked your post: \"{0}\"", NotificationResponse.Note.Text ?? NotificationResponse.Note.Cw ?? "This one!"] + + } + + @if (NotificationResponse is { Type: "follow", User: not null }) + { + @Loc["Followed you."] + } +
+ } + @if (NotificationResponse is { Type: "mention" }) + { +
+ +
+ } + @if (NotificationResponse is { Type: "reply" }) + { +
+ +
+ } + @if (NotificationResponse is { Type: "renote" }) + { +
+
@Loc["{0} boosted your post.", NotificationResponse.User!.DisplayName ?? NotificationResponse.User.Username]
+
+ +
+
+ } + @if (NotificationResponse is { Type: "quote" }) + { +
+ +
+ } + +
+ +@code { + [Parameter] public required NotificationResponse NotificationResponse { get; set; } + + private void OpenNote() + { + NavigationManager.NavigateTo($"/notes/{NotificationResponse.Note!.Id}"); + } + +} \ No newline at end of file diff --git a/Iceshrimp.Frontend/Components/NotificationComponent.razor.css b/Iceshrimp.Frontend/Components/NotificationComponent.razor.css new file mode 100644 index 00000000..94d76169 --- /dev/null +++ b/Iceshrimp.Frontend/Components/NotificationComponent.razor.css @@ -0,0 +1,34 @@ +.notification { + display: flex; + background-color: var(--foreground-color); + border-radius: 0.75rem; + padding: 1rem 1rem 1rem; /* top, left-right, bottom*/ + margin-bottom: 1rem; + max-width: 45rem; + width: 100%; +} +.notification-text { +} +.notification-note { + display: flex; + flex-direction: column; + width: 100%; +} + +.user-avatar { + border-radius: 8px; + object-fit: cover; + width: 3em; + height: 3em; + margin-right: 0.5em; +} +.display-name { + white-space: wrap; + text-overflow: ellipsis; + overflow: clip; +} +.notification-body { + display: flex; + flex-direction: column; + width: 100%; +} \ No newline at end of file diff --git a/Iceshrimp.Frontend/Components/NotificationList.razor b/Iceshrimp.Frontend/Components/NotificationList.razor new file mode 100644 index 00000000..1a5e19af --- /dev/null +++ b/Iceshrimp.Frontend/Components/NotificationList.razor @@ -0,0 +1,28 @@ +@using Iceshrimp.Frontend.Core.Miscellaneous +@using Iceshrimp.Frontend.Core.Services +@using Iceshrimp.Shared.Schemas + +@if (_state == State.Init) +{ +
+ @foreach (var el in Notifications) + { + + } +
+} + +@if (_state == State.Loading) +{ +
Loading!
+} + +@if (_state == State.Error) +{ +
Something went wrong!
+} + +@code { + +} + diff --git a/Iceshrimp.Frontend/Components/NotificationList.razor.cs b/Iceshrimp.Frontend/Components/NotificationList.razor.cs new file mode 100644 index 00000000..d244bedb --- /dev/null +++ b/Iceshrimp.Frontend/Components/NotificationList.razor.cs @@ -0,0 +1,61 @@ +using Iceshrimp.Frontend.Core.Miscellaneous; +using Iceshrimp.Frontend.Core.Services; +using Iceshrimp.Shared.Schemas; +using Microsoft.AspNetCore.Components; + +namespace Iceshrimp.Frontend.Components; + +public partial class NotificationList : IAsyncDisposable +{ + [Inject] private StreamingService StreamingService { get; set; } = null!; + [Inject] private ApiService Api { get; set; } = null!; + private List Notifications { get; set; } = []; + private State _state = State.Loading; + + private enum State + { + Loading, + Error, + Init + } + + private async Task GetNotifications() + { + try + { + var res = await Api.Notifications.GetNotifications(new PaginationQuery()); + Notifications = res; + foreach (var el in res) + { + Console.WriteLine(el.Type); + } + + _state = State.Init; + } + catch (ApiException) + { + _state = State.Error; + } + } + + protected override async Task OnInitializedAsync() + { + StreamingService.Notification += OnNotification; + await StreamingService.Connect(); + await GetNotifications(); + StateHasChanged(); + } + + private async void OnNotification(object? _, NotificationResponse notificationResponse) + { + Notifications.Insert(0, notificationResponse); + StateHasChanged(); + } + + public async ValueTask DisposeAsync() + { + StreamingService.Notification -= OnNotification; + + await StreamingService.DisposeAsync(); + } +} \ No newline at end of file diff --git a/Iceshrimp.Frontend/Components/NotificationList.razor.css b/Iceshrimp.Frontend/Components/NotificationList.razor.css new file mode 100644 index 00000000..f9bf46b7 --- /dev/null +++ b/Iceshrimp.Frontend/Components/NotificationList.razor.css @@ -0,0 +1,6 @@ +.scroller { + display: flex; + align-items: center; + flex-direction: column; + width: 100%; +} \ No newline at end of file