Skip to content

Commit e432b95

Browse files
committed
feat: live refresh in the download/upload/task info modals
The info modals held a live reference to their model but only rendered a snapshot taken when opened, so progress, state, duration and speed froze until the modal was reopened. Subscribe each modal to the aggregated throttled TransactionsChanged event while it is visible (subscribed on ShowModal, unsubscribed on HideModal and Dispose) and re-render on the UI thread, following the same pattern the transfer tables use.
1 parent 8ff954e commit e432b95

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

TelegramDownloader/Pages/Modals/InfoModals/DownloadFileInfoModal.razor

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@using TelegramDownloader.Models
22
@using TelegramDownloader.Services
3+
@implements IDisposable
4+
5+
@inject TransactionInfoService tis
36

47
<style>
58
.download-info-modal-overlay {
@@ -416,13 +419,19 @@
416419
this.downloadModel = downloadModel;
417420
if (this.downloadModel != null)
418421
{
422+
// Live refresh while the modal is open: the model reference is live,
423+
// so re-rendering on the aggregated (throttled) transactions event
424+
// keeps progress, state, duration and speed up to date.
425+
tis.TransactionsChanged -= OnTransactionsChanged;
426+
tis.TransactionsChanged += OnTransactionsChanged;
419427
isVisible = true;
420428
StateHasChanged();
421429
}
422430
}
423431

424432
private async Task HideModal()
425433
{
434+
tis.TransactionsChanged -= OnTransactionsChanged;
426435
isVisible = false;
427436
StateHasChanged();
428437

@@ -432,6 +441,21 @@
432441
}
433442
}
434443

444+
private async void OnTransactionsChanged(object sender, System.EventArgs e)
445+
{
446+
if (!isVisible) return;
447+
try
448+
{
449+
await InvokeAsync(StateHasChanged);
450+
}
451+
catch { }
452+
}
453+
454+
public void Dispose()
455+
{
456+
tis.TransactionsChanged -= OnTransactionsChanged;
457+
}
458+
435459
private async Task OnOverlayClick()
436460
{
437461
await HideModal();

TelegramDownloader/Pages/Modals/InfoModals/TaskInfoModal.razor

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@using TelegramDownloader.Models
22
@using TelegramDownloader.Services
3+
@implements IDisposable
4+
5+
@inject TransactionInfoService tis
36

47
<style>
58
.task-info-modal-overlay {
@@ -465,13 +468,19 @@
465468
this.taskModel = taskModel;
466469
if (this.taskModel != null)
467470
{
471+
// Live refresh while the modal is open: the model reference is live,
472+
// so re-rendering on the aggregated (throttled) transactions event
473+
// keeps progress, state, duration and file counters up to date.
474+
tis.TransactionsChanged -= OnTransactionsChanged;
475+
tis.TransactionsChanged += OnTransactionsChanged;
468476
isVisible = true;
469477
StateHasChanged();
470478
}
471479
}
472480

473481
private async Task HideModal()
474482
{
483+
tis.TransactionsChanged -= OnTransactionsChanged;
475484
isVisible = false;
476485
StateHasChanged();
477486

@@ -481,6 +490,21 @@
481490
}
482491
}
483492

493+
private async void OnTransactionsChanged(object sender, System.EventArgs e)
494+
{
495+
if (!isVisible) return;
496+
try
497+
{
498+
await InvokeAsync(StateHasChanged);
499+
}
500+
catch { }
501+
}
502+
503+
public void Dispose()
504+
{
505+
tis.TransactionsChanged -= OnTransactionsChanged;
506+
}
507+
484508
private async Task OnOverlayClick()
485509
{
486510
await HideModal();

TelegramDownloader/Pages/Modals/InfoModals/UploadFileInfoModal.razor

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@using TelegramDownloader.Models
22
@using TelegramDownloader.Services
3+
@implements IDisposable
4+
5+
@inject TransactionInfoService tis
36

47
<style>
58
.upload-modal-overlay {
@@ -422,13 +425,19 @@
422425
this.uploadModel = uploadModel;
423426
if (this.uploadModel != null)
424427
{
428+
// Live refresh while the modal is open: the model reference is live,
429+
// so re-rendering on the aggregated (throttled) transactions event
430+
// keeps progress, state, duration and speed up to date.
431+
tis.TransactionsChanged -= OnTransactionsChanged;
432+
tis.TransactionsChanged += OnTransactionsChanged;
425433
isVisible = true;
426434
StateHasChanged();
427435
}
428436
}
429437

430438
private async Task HideModal()
431439
{
440+
tis.TransactionsChanged -= OnTransactionsChanged;
432441
isVisible = false;
433442
StateHasChanged();
434443

@@ -438,6 +447,21 @@
438447
}
439448
}
440449

450+
private async void OnTransactionsChanged(object sender, System.EventArgs e)
451+
{
452+
if (!isVisible) return;
453+
try
454+
{
455+
await InvokeAsync(StateHasChanged);
456+
}
457+
catch { }
458+
}
459+
460+
public void Dispose()
461+
{
462+
tis.TransactionsChanged -= OnTransactionsChanged;
463+
}
464+
441465
private async Task OnOverlayClick()
442466
{
443467
await HideModal();

0 commit comments

Comments
 (0)