-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Dashboard and notifications
1 parent
8d1549f
commit b8579c6
Showing
7 changed files
with
230 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@using System.Globalization | ||
|
||
<time datetime="@DateTimeOffset.ToString("o", CultureInfo.InvariantCulture)" | ||
data-relative="@ToTimeAgo(DateTimeOffset)" | ||
data-initial="@Format" | ||
@attributes="InputAttributes"> | ||
@GetDisplayDate() | ||
</time> | ||
|
||
@code { | ||
public enum DateDisplayFormat | ||
{ | ||
Relative, | ||
Localized | ||
} | ||
|
||
[Parameter, EditorRequired] | ||
public DateTimeOffset DateTimeOffset { get; set; } | ||
|
||
[Parameter] | ||
public DateDisplayFormat Format { get; set; } | ||
|
||
[Parameter(CaptureUnmatchedValues = true)] | ||
public Dictionary<string, object>? InputAttributes { get; set; } | ||
|
||
private static string ToTimeAgo(DateTimeOffset date) => ToTimeAgo(DateTimeOffset.UtcNow - date); | ||
|
||
private static string ToTimeAgo(DateTime date) => ToTimeAgo(DateTimeOffset.UtcNow - date); | ||
|
||
private static string ToTimeAgo(TimeSpan diff) => | ||
diff.TotalSeconds > 0 ? $"{TimeString(diff)} ago" : $"in {TimeString(diff.Negate())}"; | ||
|
||
private static string TimeString(TimeSpan timeSpan) | ||
{ | ||
if (timeSpan.TotalMinutes < 1) | ||
{ | ||
return $"{(int)timeSpan.TotalSeconds} second{Plural((int)timeSpan.TotalSeconds)}"; | ||
} | ||
if (timeSpan.TotalHours < 1) | ||
{ | ||
return $"{(int)timeSpan.TotalMinutes} minute{Plural((int)timeSpan.TotalMinutes)}"; | ||
} | ||
return timeSpan.Days < 1 | ||
? $"{(int)timeSpan.TotalHours} hour{Plural((int)timeSpan.TotalHours)}" | ||
: $"{(int)timeSpan.TotalDays} day{Plural((int)timeSpan.TotalDays)}"; | ||
} | ||
|
||
private static string Plural(int value) | ||
{ | ||
return value == 1 ? string.Empty : "s"; | ||
} | ||
|
||
private string GetDisplayDate() => | ||
Format == DateDisplayFormat.Relative | ||
? ToTimeAgo(DateTimeOffset) | ||
: DateTimeOffset.ToString("g", CultureInfo.InvariantCulture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<a href="#" class="notification d-flex align-items-center dropdown-item border-bottom border-light gap-3 py-3 px-4 @(Seen ? null : "bg-light")"> | ||
<div> | ||
<Icon Symbol="@NotificationIcon(Type)" /> | ||
</div> | ||
<div class="content"> | ||
<div class="fw-semibold text-wrap"> | ||
@Body | ||
</div> | ||
<small class="text-muted"> | ||
<DateDisplay DateTimeOffset="Created" /> | ||
</small> | ||
</div> | ||
</a> | ||
|
||
@code { | ||
[Parameter, EditorRequired] | ||
public string? Id { get; set; } | ||
|
||
[Parameter, EditorRequired] | ||
public string? Type { get; set; } | ||
|
||
[Parameter, EditorRequired] | ||
public DateTimeOffset Created { get; set; } | ||
|
||
[Parameter, EditorRequired] | ||
public string? Body { get; set; } | ||
|
||
[Parameter] | ||
public bool Seen { get; set; } | ||
|
||
private static string NotificationIcon(string type) | ||
{ | ||
return type switch | ||
{ | ||
"invoice_expired" => "notifications-invoice-failure", | ||
"invoice_expiredpaidpartial" => "notifications-invoice-failure", | ||
"invoice_failedtoconfirm" => "notifications-invoice-failure", | ||
"invoice_confirmed" => "notifications-invoice-settled", | ||
"invoice_paidafterexpiration" => "notifications-invoice-settled", | ||
"external-payout-transaction" => "notifications-payout", | ||
"payout_awaitingapproval" => "notifications-payout", | ||
"payout_awaitingpayment" => "notifications-payout-approved", | ||
"newversion" => "notifications-new-version", | ||
_ => "note" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
::deep .icon { | ||
--icon-size: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
h2 { | ||
font-size: var(--btcpay-font-size-m); | ||
font-weight: var(--btcpay-font-weight-semibold); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters