[frontend/components] Fix note timestamp not updating
This commit is contained in:
parent
5a54da365c
commit
cd0149cfeb
2 changed files with 43 additions and 43 deletions
|
@ -1,4 +1,3 @@
|
||||||
@using System.Timers
|
|
||||||
@using Iceshrimp.Assets.PhosphorIcons
|
@using Iceshrimp.Assets.PhosphorIcons
|
||||||
@using Iceshrimp.Frontend.Localization
|
@using Iceshrimp.Frontend.Localization
|
||||||
@using Iceshrimp.Shared.Schemas.Web
|
@using Iceshrimp.Shared.Schemas.Web
|
||||||
|
@ -46,44 +45,4 @@
|
||||||
[Parameter] [EditorRequired] public required NoteVisibility Visibility { get; set; }
|
[Parameter] [EditorRequired] public required NoteVisibility Visibility { get; set; }
|
||||||
[Parameter] [EditorRequired] public required string? InstanceName { get; set; }
|
[Parameter] [EditorRequired] public required string? InstanceName { get; set; }
|
||||||
[Parameter] public string? OpenNoteId { get; set; }
|
[Parameter] public string? OpenNoteId { get; set; }
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
ResetTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateDisplay(object? _, ElapsedEventArgs elapsedEventArgs)
|
|
||||||
{
|
|
||||||
StateHasChanged();
|
|
||||||
ResetTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ResetTimer()
|
|
||||||
{
|
|
||||||
var diff = DateTime.Now - CreatedAt;
|
|
||||||
if (diff.TotalMinutes < 1) // Default of 2 seconds
|
|
||||||
{
|
|
||||||
SetTimer();
|
|
||||||
}
|
|
||||||
else if (diff.TotalHours < 1)
|
|
||||||
{
|
|
||||||
SetTimer(20000); // 20 seconds
|
|
||||||
}
|
|
||||||
else if (diff.TotalDays < 1 && diff.TotalHours > 1)
|
|
||||||
{
|
|
||||||
SetTimer(600000); // 10 minutes
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetTimer(3600000); // 1 hour
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetTimer(int duration = 2000)
|
|
||||||
{
|
|
||||||
var timer = new Timer(duration);
|
|
||||||
timer.Elapsed += UpdateDisplay;
|
|
||||||
timer.AutoReset = false;
|
|
||||||
timer.Enabled = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
@using System.Timers
|
||||||
@using Iceshrimp.Frontend.Localization
|
@using Iceshrimp.Frontend.Localization
|
||||||
@using Microsoft.Extensions.Localization
|
@using Microsoft.Extensions.Localization
|
||||||
@inject IStringLocalizer<Localization> Loc;
|
@inject IStringLocalizer<Localization> Loc;
|
||||||
|
@ -23,4 +24,44 @@
|
||||||
_ => Loc["now"]
|
_ => Loc["now"]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
ResetTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateDisplay(object? _, ElapsedEventArgs elapsedEventArgs)
|
||||||
|
{
|
||||||
|
StateHasChanged();
|
||||||
|
ResetTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetTimer()
|
||||||
|
{
|
||||||
|
var diff = DateTime.Now - Date;
|
||||||
|
if (diff.TotalMinutes < 1) // Default of 1 seconds
|
||||||
|
{
|
||||||
|
SetTimer();
|
||||||
|
}
|
||||||
|
else if (diff.TotalHours < 1)
|
||||||
|
{
|
||||||
|
SetTimer(20000); // 20 seconds
|
||||||
|
}
|
||||||
|
else if (diff.TotalDays < 1 && diff.TotalHours > 1)
|
||||||
|
{
|
||||||
|
SetTimer(600000); // 10 minutes
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetTimer(3600000); // 1 hour
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetTimer(int duration = 1000)
|
||||||
|
{
|
||||||
|
var timer = new Timer(duration);
|
||||||
|
timer.Elapsed += UpdateDisplay;
|
||||||
|
timer.AutoReset = false;
|
||||||
|
timer.Enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue