Iceshrimp.NET/Iceshrimp.Frontend/Components/NotificationComponent.razor

92 lines
No EOL
3.6 KiB
Text

@* ReSharper disable once RedundantUsingDirective *@
@using Iceshrimp.Frontend.Components.Note
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<Localization> Loc;
@inject NavigationManager NavigationManager
<div class="notification">
@if (NotificationResponse is { User: not null, Type: "like" or "follow" or "reaction" or "followRequestReceived" or "followRequestAccepted"})
{
<img class="user-avatar" src="@NotificationResponse.User.AvatarUrl"/>
<div class="notification-body">
<span class="display-name">@(NotificationResponse.User.DisplayName ?? NotificationResponse.User.Username)</span>
@if (NotificationResponse is { Note: not null, Type: "like", User: not null })
{
<span @onclick="OpenNote" class="notification-text">
@Loc["liked your post: "]<MfmText Text="@NotificationResponse.Note.Text"></MfmText>
</span>
}
@if (NotificationResponse is { Note: not null, Type: "reaction" })
{
<span @onclick="OpenNote" class="notification-text">
@Loc["reacted to your post: "] <MfmText Text="@NotificationResponse.Note.Text"></MfmText>
</span>
}
@if (NotificationResponse is { Type: "follow", User: not null })
{
<span @onclick="OpenProfile" class="notification-text">@Loc["Followed you."]</span>
}
@if (NotificationResponse is { Type: "followRequestReceived" })
{
<div @onclick="OpenFollowRequests" class="notification-text">@Loc["Requested to follow you."]</div>
}
@if (NotificationResponse is { Type: "followRequestAccepted" })
{
<span @onclick="OpenProfile" class="notification-text">@Loc["Accepted your follow request."]</span>
}
</div>
}
@if (NotificationResponse is { Type: "mention" })
{
<div @onclick="OpenNote" class="notification-note">
<Note NoteResponse="NotificationResponse.Note"/>
</div>
}
@if (NotificationResponse is { Type: "reply" })
{
<div @onclick="OpenNote" class="notification-note">
<Note NoteResponse="NotificationResponse.Note"/>
</div>
}
@if (NotificationResponse is { Type: "renote" })
{
<div @onclick="OpenNote" class="notification-body">
<div class="renote-info">@Loc["{0} boosted your post.", NotificationResponse.User!.DisplayName ?? NotificationResponse.User.Username]</div>
<div class="notification-note">
<Note NoteResponse="NotificationResponse.Note"/>
</div>
</div>
}
@if (NotificationResponse is { Type: "quote" })
{
<div @onclick="OpenNote" class="notification-note">
<Note NoteResponse="NotificationResponse.Note"/>
</div>
}
</div>
@code {
[Parameter] public required NotificationResponse NotificationResponse { get; set; }
private void OpenNote()
{
NavigationManager.NavigateTo($"/notes/{NotificationResponse.Note!.Id}");
}
private void OpenFollowRequests()
{
NavigationManager.NavigateTo("/follow-requests");
}
private void OpenProfile()
{
var username = $"@{NotificationResponse.User?.Username}";
if (NotificationResponse.User?.Host != null) username += $"@{NotificationResponse.User.Host}";
NavigationManager.NavigateTo($"/{username}");
}
}