Skip to content

Commit

Permalink
Merge pull request #10 from 0phois/Limit-Reloads
Browse files Browse the repository at this point in the history
[Fix] Only reload page if a static component exists
  • Loading branch information
Anu6is authored Aug 19, 2024
2 parents 4402295 + e52fd02 commit 54f13c8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Components/MudStaticButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ else
/// </summary>
[Parameter] public string SubmitUrl { get; set; } = string.Empty;

protected override void OnParametersSet()
{
UserAttributes["data-static-component"] = true;

base.OnParametersSet();
}

private string GetButtonType() => FormAction switch
{
FormAction.Submit => ButtonType.Submit.ToDescriptionString(),
Expand Down
8 changes: 7 additions & 1 deletion src/Components/MudStaticCheckBox.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
private string _name = string.Empty;
private readonly string _elementId = Guid.NewGuid().ToString()[..8];

protected override void OnParametersSet()
{
UserAttributes["data-static-component"] = true;

base.OnParametersSet();
}

protected override void OnInitialized()
{
var expression = ValueExpression?.ToString();
Expand All @@ -51,7 +58,6 @@

base.OnInitialized();
}

}

<script>
Expand Down
7 changes: 7 additions & 0 deletions src/Components/MudStaticSwitch.razor
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
private string _name = string.Empty;
private readonly string _elementId = Guid.NewGuid().ToString()[..8];

protected override void OnParametersSet()
{
UserAttributes["data-static-component"] = true;

base.OnParametersSet();
}

protected override void OnInitialized()
{
var expression = ValueExpression?.ToString();
Expand Down
1 change: 1 addition & 0 deletions src/Components/MudStaticTextField.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

protected override void OnParametersSet()
{
UserAttributes["data-static-component"] = true;
UserAttributes["data-static-id"] = _elementId;
UserAttributes["name"] = _name;

Expand Down
7 changes: 6 additions & 1 deletion src/wwwroot/NavigationObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ let hasInitialized = false;

if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
window.location.reload();

const hasStaticComponent = document.body.querySelector('[data-static-component]') !== null;

if (hasStaticComponent) {
window.location.reload();
}
}
hasInitialized = true;
}
Expand Down

0 comments on commit 54f13c8

Please sign in to comment.