Skip to content

Commit

Permalink
Fix oqtane#3885: only re-render the component when message changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyhfish committed May 18, 2024
1 parent 4b1f23a commit 2b32f31
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
33 changes: 17 additions & 16 deletions Oqtane.Client/Modules/Controls/ModuleMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
{
<NavLink class="ms-2" href="@NavigateUrl("admin/log")">View Details</NavLink>
}
<a href="@NavigationManager.Uri" class="btn-close" data-dismiss="alert" aria-label="close"></a>
<button type="button" class="btn-close" data-dismiss="alert" aria-label="close" @onclick="CloseMessage"></button>
}
</div>
}

@code {
private string _message = string.Empty;
private string _classname = string.Empty;
private string _formname = "ModuleMessageForm";

Expand All @@ -27,15 +28,8 @@
[Parameter]
public MessageType Type { get; set; }

public void RefreshMessage(string message, MessageType type)
{
Message = message;
Type = type;

UpdateClassName();

StateHasChanged();
}
[Parameter]
public RenderModeBoundary Parent { get; set; }

protected override void OnInitialized()
{
Expand All @@ -47,12 +41,8 @@

protected override void OnParametersSet()
{
UpdateClassName();
}

private void UpdateClassName()
{
if (!string.IsNullOrEmpty(Message))
_message = Message;
if (!string.IsNullOrEmpty(_message))
{
_classname = GetMessageType(Type);
}
Expand All @@ -79,4 +69,15 @@

return classname;
}
private void CloseMessage(MouseEventArgs e)
{
if(Parent != null)
{
Parent.DismissMessage();
}
else
{
NavigationManager.NavigateTo(NavigationManager.Uri);
}
}
}
1 change: 0 additions & 1 deletion Oqtane.Client/Modules/ModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ public void AddModuleMessage(string message, MessageType type)

public void AddModuleMessage(string message, MessageType type, string position)
{
ClearModuleMessage();
RenderModeBoundary.AddModuleMessage(message, type, position);
}

Expand Down
46 changes: 20 additions & 26 deletions Oqtane.Client/UI/RenderModeBoundary.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
{
@if (ModuleType != null)
{
<ModuleMessage @ref="moduleMessageTop" Message="@_messageContent" Type="@_messageType" />
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "top")
{
<ModuleMessage Message="@_messageContent" Type="@_messageType" Parent="@this" />
}
@DynamicComponent
@if (_progressIndicator)
{
<div class="app-progress-indicator"></div>
}
<ModuleMessage @ref="moduleMessageBottom" Message="@_messageContent" Type="@_messageType" />
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom")
{
<ModuleMessage Message="@_messageContent" Type="@_messageType" Parent="@this" />
}
}
}
else
Expand All @@ -41,8 +47,6 @@
private string _messagePosition;
private bool _progressIndicator = false;
private string _error;
private ModuleMessage moduleMessageTop;
private ModuleMessage moduleMessageBottom;

[Parameter]
public SiteState SiteState { get; set; }
Expand Down Expand Up @@ -103,12 +107,17 @@

public void AddModuleMessage(string message, MessageType type, string position)
{
_messageContent = message;
_messageType = type;
_messagePosition = position;
_progressIndicator = false;
if(message != _messageContent
|| type != _messageType
|| position != _messagePosition)
{
_messageContent = message;
_messageType = type;
_messagePosition = position;
_progressIndicator = false;

Refresh();
StateHasChanged();
}
}

public void ShowProgressIndicator()
Expand All @@ -123,25 +132,10 @@
StateHasChanged();
}

private void DismissMessage()
public void DismissMessage()
{
_messageContent = "";
}

private void Refresh()
{
var updateTop = string.IsNullOrEmpty(_messageContent) || _messagePosition == "top";
var updateBottom = string.IsNullOrEmpty(_messageContent) || _messagePosition == "bottom";

if (updateTop && moduleMessageTop != null)
{
moduleMessageTop.RefreshMessage(_messageContent, _messageType);
}

if (updateBottom && moduleMessageBottom != null)
{
moduleMessageBottom.RefreshMessage(_messageContent, _messageType);
}
StateHasChanged();
}

protected override async Task OnErrorAsync(Exception exception)
Expand Down

0 comments on commit 2b32f31

Please sign in to comment.