Merge pull request #3885 from zyhfish/task/fix-infinite-loop-of-module-message
avoid the infinite loop issue of calling AddModuleMessage method.
This commit is contained in:
commit
98de661868
|
@ -2,10 +2,10 @@
|
||||||
@inherits ModuleControlBase
|
@inherits ModuleControlBase
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(_message))
|
@if (Visible)
|
||||||
{
|
{
|
||||||
<div class="@_classname alert-dismissible fade show mb-3" role="alert">
|
<div class="@_classname alert-dismissible fade show mb-3" role="alert">
|
||||||
@((MarkupString)_message)
|
@((MarkupString)Message)
|
||||||
@if (PageState != null)
|
@if (PageState != null)
|
||||||
{
|
{
|
||||||
@if (Type == MessageType.Error && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
@if (Type == MessageType.Error && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string _message = string.Empty;
|
|
||||||
private string _classname = string.Empty;
|
private string _classname = string.Empty;
|
||||||
private string _formname = "ModuleMessageForm";
|
private string _formname = "ModuleMessageForm";
|
||||||
|
|
||||||
|
@ -31,6 +30,20 @@
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public MessageType Type { get; set; }
|
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()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
if (ModuleState != null)
|
if (ModuleState != null)
|
||||||
|
@ -41,8 +54,12 @@
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
_message = Message;
|
UpdateClassName();
|
||||||
if (!string.IsNullOrEmpty(_message))
|
}
|
||||||
|
|
||||||
|
private void UpdateClassName()
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Message))
|
||||||
{
|
{
|
||||||
_classname = GetMessageType(Type);
|
_classname = GetMessageType(Type);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +89,6 @@
|
||||||
|
|
||||||
private void DismissModal()
|
private void DismissModal()
|
||||||
{
|
{
|
||||||
_message = "";
|
Message = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,13 @@
|
||||||
@if (ModuleType != null)
|
@if (ModuleType != null)
|
||||||
{
|
{
|
||||||
@((MarkupString)$"<!-- Render Mode: {ModuleState.RenderMode} -->")
|
@((MarkupString)$"<!-- Render Mode: {ModuleState.RenderMode} -->")
|
||||||
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "top")
|
<ModuleMessage @ref="moduleMessageTop" Message="@_messageContent" Type="@_messageType" Visible="@(!string.IsNullOrEmpty(_messageContent) && _messagePosition == "top")" />
|
||||||
{
|
|
||||||
<ModuleMessage Message="@_messageContent" Type="@_messageType" />
|
|
||||||
}
|
|
||||||
@DynamicComponent
|
@DynamicComponent
|
||||||
@if (_progressIndicator)
|
@if (_progressIndicator)
|
||||||
{
|
{
|
||||||
<div class="app-progress-indicator"></div>
|
<div class="app-progress-indicator"></div>
|
||||||
}
|
}
|
||||||
@if (!string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom")
|
<ModuleMessage @ref="moduleMessageBottom" Message="@_messageContent" Type="@_messageType" Visible="@(!string.IsNullOrEmpty(_messageContent) && _messagePosition == "bottom")" />
|
||||||
{
|
|
||||||
<ModuleMessage Message="@_messageContent" Type="@_messageType" />
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -48,6 +42,8 @@
|
||||||
private string _messagePosition;
|
private string _messagePosition;
|
||||||
private bool _progressIndicator = false;
|
private bool _progressIndicator = false;
|
||||||
private string _error;
|
private string _error;
|
||||||
|
private ModuleMessage moduleMessageTop;
|
||||||
|
private ModuleMessage moduleMessageBottom;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public SiteState SiteState { get; set; }
|
public SiteState SiteState { get; set; }
|
||||||
|
@ -112,19 +108,20 @@
|
||||||
_messageType = type;
|
_messageType = type;
|
||||||
_messagePosition = position;
|
_messagePosition = position;
|
||||||
_progressIndicator = false;
|
_progressIndicator = false;
|
||||||
StateHasChanged();
|
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowProgressIndicator()
|
public void ShowProgressIndicator()
|
||||||
{
|
{
|
||||||
_progressIndicator = true;
|
_progressIndicator = true;
|
||||||
StateHasChanged();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideProgressIndicator()
|
public void HideProgressIndicator()
|
||||||
{
|
{
|
||||||
_progressIndicator = false;
|
_progressIndicator = false;
|
||||||
StateHasChanged();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DismissMessage()
|
private void DismissMessage()
|
||||||
|
@ -132,6 +129,22 @@
|
||||||
_messageContent = "";
|
_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)
|
protected override async Task OnErrorAsync(Exception exception)
|
||||||
{
|
{
|
||||||
// retrieve friendly localized error
|
// retrieve friendly localized error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user