Skip to content

Commit

Permalink
Merge pull request #3885 from zyhfish/task/fix-infinite-loop-of-modul…
Browse files Browse the repository at this point in the history
…e-message

avoid the infinite loop issue of calling AddModuleMessage method.
  • Loading branch information
sbwalker authored Feb 24, 2024
2 parents 64df057 + fc0b326 commit 98de661
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
29 changes: 23 additions & 6 deletions Oqtane.Client/Modules/Controls/ModuleMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@inherits ModuleControlBase
@inject NavigationManager NavigationManager

@if (!string.IsNullOrEmpty(_message))
@if (Visible)
{
<div class="@_classname alert-dismissible fade show mb-3" role="alert">
@((MarkupString)_message)
@((MarkupString)Message)
@if (PageState != null)
{
@if (Type == MessageType.Error && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
Expand All @@ -21,7 +21,6 @@
}

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

Expand All @@ -31,6 +30,20 @@
[Parameter]
public MessageType Type { get; set; }

[Parameter]
public bool Visible { get; set; } = true;

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

UpdateClassName();

StateHasChanged();
}

protected override void OnInitialized()
{
if (ModuleState != null)
Expand All @@ -41,8 +54,12 @@

protected override void OnParametersSet()
{
_message = Message;
if (!string.IsNullOrEmpty(_message))
UpdateClassName();
}

private void UpdateClassName()
{
if (!string.IsNullOrEmpty(Message))
{
_classname = GetMessageType(Type);
}
Expand Down Expand Up @@ -72,6 +89,6 @@

private void DismissModal()
{
_message = "";
Message = "";
}
}
35 changes: 24 additions & 11 deletions Oqtane.Client/UI/RenderModeBoundary.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@
@if (ModuleType != null)
{
@((MarkupString)$"<!-- Render Mode: {ModuleState.RenderMode} -->")
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "top")
{
<ModuleMessage Message="@_messageContent" Type="@_messageType" />
}
<ModuleMessage @ref="moduleMessageTop" Message="@_messageContent" Type="@_messageType" Visible="@(!string.IsNullOrEmpty(_messageContent) && _messagePosition == "top")" />
@DynamicComponent
@if (_progressIndicator)
{
<div class="app-progress-indicator"></div>
}
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom")
{
<ModuleMessage Message="@_messageContent" Type="@_messageType" />
}
<ModuleMessage @ref="moduleMessageBottom" Message="@_messageContent" Type="@_messageType" Visible="@(!string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom")" />
}
}
else
Expand All @@ -48,6 +42,8 @@
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 @@ -112,26 +108,43 @@
_messageType = type;
_messagePosition = position;
_progressIndicator = false;
StateHasChanged();

Refresh();
}

public void ShowProgressIndicator()
{
_progressIndicator = true;
StateHasChanged();
Refresh();
}

public void HideProgressIndicator()
{
_progressIndicator = false;
StateHasChanged();
Refresh();
}

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

private void Refresh()
{
var messageTopVisible = !string.IsNullOrEmpty(_messageContent) && _messagePosition == "top";
var messageBottomVisible = !string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom";

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

if (moduleMessageBottom != null)
{
moduleMessageBottom.RefreshMessage(_messageContent, _messageType, messageBottomVisible);
}
}

protected override async Task OnErrorAsync(Exception exception)
{
// retrieve friendly localized error
Expand Down

0 comments on commit 98de661

Please sign in to comment.