Skip to content

Commit

Permalink
Partial fix and prep for scroll jumping on navigate
Browse files Browse the repository at this point in the history
Issue described in dotnet/aspnetcore#53863 and for MudBlazor at MudBlazor/MudBlazor#8151.

The MudBlazor part was remedied for MudButton with MudBlazor/MudBlazor#8203 in 6.17.0 but MudIconButton and MudMenuItem were not impacted and are awaiting MudBlazor/MudBlazor#8281
  • Loading branch information
danielchalmers committed Mar 7, 2024
1 parent b8cb844 commit 814750d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
9 changes: 7 additions & 2 deletions JournalApp/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@
AppDbContext db;
bool _disposed;
Day _day;
DateTimeOffset _stoppedDate;
bool _leaving;
IDisposable locationChangingRegistration;
DateTimeOffset _stoppedDate;

[Parameter]
public string OpenToDateString { get; set; }

protected override async Task OnInitializedAsync()
{
logger.LogDebug("Initializing asynchronously");
logger.LogDebug("Initializing asynchronously");
db = await DbFactory.CreateDbContextAsync();
await base.OnInitializedAsync();

Expand Down Expand Up @@ -294,6 +295,7 @@

ValueTask OnLocationChanging(LocationChangingContext e)
{
_leaving = true;
SavePage();
return ValueTask.CompletedTask;
}
Expand Down Expand Up @@ -322,4 +324,7 @@
locationChangingRegistration?.Dispose();
db?.Dispose();
}

// https://github.com/dotnet/aspnetcore/issues/53863
protected override bool ShouldRender() => !_leaving;
}
4 changes: 4 additions & 0 deletions JournalApp/Components/Pages/ManageCategoriesPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

@code {
AppDbContext db;
bool _leaving;

[Parameter]
public string Group { get; set; }
Expand Down Expand Up @@ -131,6 +132,7 @@
void Submit()
{
logger.LogInformation("Going to index");
_leaving = true;
NavigationManager.NavigateTo("/", false, true);
}

Expand All @@ -140,4 +142,6 @@
db?.Dispose();
Snackbar.Clear();
}

protected override bool ShouldRender() => !_leaving;
}
9 changes: 7 additions & 2 deletions JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
</div>

@code {
MoodGridSwitcher _switcher;
DataPointCategory _moodCategory;
GridYear? _gridYear = null;
bool _leaving;
DataPointCategory _moodCategory;
MoodGridSwitcher _switcher;

[Parameter]
public string OpenToDateString { get; set; }
Expand Down Expand Up @@ -217,6 +218,7 @@
void Close()
{
logger.LogInformation("Going to index");
_leaving = true;
NavigationManager.NavigateTo("/", false, true);
}

Expand All @@ -226,6 +228,7 @@
return;

Snackbar.TeachingTipActionTaken("click_mood_grid_day");
_leaving = true;
NavigationManager.NavigateTo($"/{date:yyyyMMdd}", false, true);
}

Expand All @@ -234,4 +237,6 @@
KeyEventService.Exited();
Snackbar.Clear();
}

protected override bool ShouldRender() => !_leaving;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
</div>

@code {
bool _leaving;

public SafetyPlan Plan { get; set; }

protected override void OnInitialized()
Expand All @@ -75,6 +77,7 @@
void Submit()
{
logger.LogInformation("Going to index");
_leaving = true;
NavigationManager.NavigateTo("/", false, true);
}

Expand All @@ -88,4 +91,6 @@
else
Preferences.Default.SetJson("safety_plan", Plan);
}

protected override bool ShouldRender() => !_leaving;
}
17 changes: 11 additions & 6 deletions JournalApp/Components/Pages/SettingsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@inject IDialogService DialogService
@inject AppThemeService AppThemeService

@if (_isBusy)
@if (_busy)
{
@* TODO: Replace with separate page so we can change state of inline fields and have it updated properly in settings *@
<div class="d-flex justify-center">
Expand Down Expand Up @@ -69,7 +69,8 @@ else
}

@code {
bool _isBusy;
bool _leaving;
bool _busy;

public string CreditsText { get; private set; }

Expand Down Expand Up @@ -106,6 +107,7 @@ else
void SetUpSafetyPlan()
{
logger.LogInformation("Setting up Safety Plan");
_leaving = true;
NavigationManager.NavigateTo($"/safetyplan", false, true);
}

Expand Down Expand Up @@ -135,7 +137,7 @@ else
{
try
{
_isBusy = true;
_busy = true;
StateHasChanged();

var path = App.ActivatedFilePath;
Expand All @@ -145,22 +147,22 @@ else
finally
{
App.ActivatedFilePath = null;
_isBusy = false;
_busy = false;
}
}

async Task StartExport()
{
try
{
_isBusy = true;
_busy = true;
StateHasChanged();

await AppDataService.StartExportWizard(DialogService);
}
finally
{
_isBusy = false;
_busy = false;
}
}

Expand All @@ -176,11 +178,14 @@ else
void Close()
{
logger.LogInformation("Going to index");
_leaving = true;
NavigationManager.NavigateTo("/", false, true);
}

public void Dispose()
{
KeyEventService.Exited();
}

protected override bool ShouldRender() => !_leaving;
}
5 changes: 5 additions & 0 deletions JournalApp/Components/Pages/Trends/TrendsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
</div>

@code {
bool _leaving;

[Parameter]
public string OpenToDateString { get; set; }

Expand Down Expand Up @@ -99,11 +101,14 @@
void Close()
{
logger.LogInformation("Going to index");
_leaving = true;
NavigationManager.NavigateTo("/", false, true);
}

public void Dispose()
{
KeyEventService.Exited();
}

protected override bool ShouldRender() => !_leaving;
}

0 comments on commit 814750d

Please sign in to comment.