private async 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();

                await Task.Delay(500);

                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;
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Success(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Success;
         await Open(config);
     }
 }
 private async Task Remove(NotificationConfig option)
 {
     if (option.Duration > 0)
     {
         await Task.Delay(TimeSpan.FromSeconds(option.Duration.Value));
         await RemoveItem(option);
     }
 }
        private NotificationConfig ExtendConfig(NotificationConfig config)
        {
            config.Placement ??= _defaultPlacement;
            config.Duration ??= _defaultDuration;
            config.CloseIcon ??= _defaultCloseIcon;

            return(config);
        }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Error(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Error;
         await Open(config);
     }
 }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Warning(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Warning;
         await Open(config);
     }
 }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Info(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Info;
         await Open(config);
     }
 }
Example #8
0
        /// <summary>
        /// open a notification box with NotificationType.Error style
        /// </summary>
        /// <param name="config"></param>
        public async Task <NotificationRef> Error(NotificationConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            config.NotificationType = NotificationType.Error;
            return(await Open(config));
        }
Example #9
0
        /// <summary>
        /// just create a NotificationRef without open it
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public Task <NotificationRef> CreateRefAsync([NotNull] NotificationConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            var notificationRef = new NotificationRef(this, config);

            return(Task.FromResult(notificationRef));
        }
Example #10
0
        /// <summary>
        /// open a notification box with NotificationType.Success style
        /// </summary>
        /// <param name="config"></param>
        public async Task <NotificationRef> Success(NotificationConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            config.NotificationType = NotificationType.Success;
            return(await Open(config));
        }
Example #11
0
 internal async Task InternalOpen(NotificationConfig config)
 {
     if (OnNoticing != null)
     {
         if (string.IsNullOrWhiteSpace(config.Key))
         {
             config.Key = Guid.NewGuid().ToString();
         }
         await OnNoticing.Invoke(config);
     }
 }
Example #12
0
        /// <summary>
        /// open a notification box with NotificationType.Warning style
        /// </summary>
        /// <param name="config"></param>
        public async Task <NotificationRef> Warning(NotificationConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            config.NotificationType = NotificationType.Warning;
            await Open(config);

            return(null);
        }
        /// <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));
            }

            if (OnNoticing != null)
            {
                await OnNoticing.Invoke(config);
            }
        }
Example #14
0
        /// <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;
            }
        }
Example #15
0
        /// <summary>
        /// Open a notification box
        /// </summary>
        /// <param name="config"></param>
        public async Task <NotificationRef> Open([NotNull] NotificationConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var notificationRef = await CreateRefAsync(config);

            await notificationRef.OpenAsync();

            return(notificationRef);
        }
Example #16
0
        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;

            option.AnimationClass = AnimationType.Enter;
            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);
                }
            }
        }
Example #17
0
 /// <summary>
 /// Equivalent to Warning method
 /// </summary>
 /// <param name="config"></param>
 public async Task <NotificationRef> Warn(NotificationConfig config)
 {
     return(await Warning(config));
 }
Example #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Warn(NotificationConfig config)
 {
     await Warning(config);
 }
 internal NotificationRef(NotificationService service, NotificationConfig config)
 {
     _service = service;
     Config   = config;
 }