Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid the infinite loop issue of calling AddModuleMessage method. #3885

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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