private Task RemoveItem(NotificationConfig option) { //avoid user do click and option.Duration toggle twice if (option.AnimationClass == AnimationType.Enter) { option.AnimationClass = AnimationType.Leave; StateHasChanged(); option.InvokeOnClose(); Debug.Assert(option.Placement != null, "option.Placement != null"); if (_configDict.TryGetValue(option.Placement.Value, out var configList)) { configList.Remove(option); } if (!string.IsNullOrWhiteSpace(option.Key)) { _configKeyDict.TryRemove(option.Key, out var _); } //when next notification item fade out or add new notice item, item will toggle StateHasChanged //StateHasChanged(); } return(Task.CompletedTask); }
private async Task Remove(NotificationConfig option) { if (option.Duration > 0) { await Task.Delay(TimeSpan.FromSeconds(option.Duration.Value)); await RemoveItem(option); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public async Task Warning(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Warning; await Open(config); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public async Task Info(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Info; await Open(config); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public async Task Error(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Error; await Open(config); } }
/// <summary> /// Open a notification box /// </summary> /// <param name="config"></param> public void Open([NotNull] NotificationConfig config) { if (config == null) { return; } OnNotice?.Invoke(config); }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Warning(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Warning; Open(config); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Info(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Info; Open(config); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Error(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Error; Open(config); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Success(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Success; Open(config); } }
private NotificationConfig ExtendConfig(NotificationConfig config) { config.Placement ??= _defaultPlacement; config.Duration ??= _defaultDuration; config.CloseIcon ??= _defaultCloseIcon; return(config); }
/// <summary> /// /// </summary> /// <param name="config"></param> public async Task Success(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Success; await Open(config); } }
/// <summary> /// Open a notification box /// </summary> /// <param name="config"></param> public async Task Open([NotNull] NotificationConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } var task = OnNoticing?.Invoke(config); if (task != null) { await task; } }
private async Task NotifyAsync(NotificationConfig option) { if (option == null) { return; } option = ExtendConfig(option); Debug.Assert(option.Placement != null, "option.Placement != null"); var placement = option.Placement.Value; bool canAdd = true; if (!_configDict.ContainsKey(placement)) { canAdd = _configDict.TryAdd(placement, new List <NotificationConfig>()); } if (canAdd) { if (!string.IsNullOrWhiteSpace(option.Key)) { if (_configKeyDict.TryGetValue(option.Key, out var oldConfig)) { oldConfig.Message = option.Message; oldConfig.Description = option.Description; await InvokeAsync(StateHasChanged); return; } canAdd = _configKeyDict.TryAdd(option.Key, option); } if (canAdd) { _configDict[placement].Add(option); await InvokeAsync(StateHasChanged); await Remove(option); } } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void Warn(NotificationConfig config) { Warning(config); }
private async void NotificationService_OnNotice(NotificationConfig e) { await NotifyAsync(e); }
/// <summary> /// /// </summary> /// <param name="config"></param> public async Task Warn(NotificationConfig config) { await Warning(config); }