mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 02:20:20 +00:00 
			
		
		
		
	added warning messages to the message bus
This commit is contained in:
		
							parent
							
								
									8a890d2ed9
								
							
						
					
					
						commit
						844e305bb9
					
				@ -102,7 +102,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        // Register this component with the message bus:
 | 
					        // Register this component with the message bus:
 | 
				
			||||||
        this.MessageBus.RegisterComponent(this);
 | 
					        this.MessageBus.RegisterComponent(this);
 | 
				
			||||||
        this.MessageBus.ApplyFilters(this, [], [ Event.UPDATE_AVAILABLE, Event.CONFIGURATION_CHANGED, Event.COLOR_THEME_CHANGED, Event.SHOW_ERROR ]);
 | 
					        this.MessageBus.ApplyFilters(this, [], [ Event.UPDATE_AVAILABLE, Event.CONFIGURATION_CHANGED, Event.COLOR_THEME_CHANGED, Event.SHOW_ERROR, Event.SHOW_WARNING, Event.SHOW_SUCCESS, ]);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Set the snackbar for the update service:
 | 
					        // Set the snackbar for the update service:
 | 
				
			||||||
        UpdateService.SetBlazorDependencies(this.Snackbar);
 | 
					        UpdateService.SetBlazorDependencies(this.Snackbar);
 | 
				
			||||||
@ -174,11 +174,23 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis
 | 
				
			|||||||
                this.StateHasChanged();
 | 
					                this.StateHasChanged();
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					            case Event.SHOW_SUCCESS:
 | 
				
			||||||
 | 
					                if (data is Success success)
 | 
				
			||||||
 | 
					                    success.Show(this.Snackbar);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            case Event.SHOW_ERROR:
 | 
					            case Event.SHOW_ERROR:
 | 
				
			||||||
                if (data is Error error)
 | 
					                if (data is Error error)
 | 
				
			||||||
                    error.Show(this.Snackbar);
 | 
					                    error.Show(this.Snackbar);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            case Event.SHOW_WARNING:
 | 
				
			||||||
 | 
					                if (data is Warning warning)
 | 
				
			||||||
 | 
					                    warning.Show(this.Snackbar);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,21 @@ public readonly record struct Error(string Icon, string Message)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public readonly record struct Warning(string Icon, string Message)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public void Show(ISnackbar snackbar)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        var icon = this.Icon;
 | 
				
			||||||
 | 
					        snackbar.Add(this.Message, Severity.Warning, config =>
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            config.Icon = icon;
 | 
				
			||||||
 | 
					            config.IconSize = Size.Large;
 | 
				
			||||||
 | 
					            config.HideTransitionDuration = 600;
 | 
				
			||||||
 | 
					            config.VisibleStateDuration = 12_000;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public readonly record struct Success(string Icon, string Message)
 | 
					public readonly record struct Success(string Icon, string Message)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public void Show(ISnackbar snackbar)
 | 
					    public void Show(ISnackbar snackbar)
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ public enum Event
 | 
				
			|||||||
    COLOR_THEME_CHANGED,
 | 
					    COLOR_THEME_CHANGED,
 | 
				
			||||||
    PLUGINS_RELOADED,
 | 
					    PLUGINS_RELOADED,
 | 
				
			||||||
    SHOW_ERROR,
 | 
					    SHOW_ERROR,
 | 
				
			||||||
 | 
					    SHOW_WARNING,
 | 
				
			||||||
    SHOW_SUCCESS,
 | 
					    SHOW_SUCCESS,
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Update events:
 | 
					    // Update events:
 | 
				
			||||||
 | 
				
			|||||||
@ -68,6 +68,8 @@ public sealed class MessageBus
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public Task SendError(Error error) => this.SendMessage(null, Event.SHOW_ERROR, error);
 | 
					    public Task SendError(Error error) => this.SendMessage(null, Event.SHOW_ERROR, error);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    public Task SendWarning(Warning warning) => this.SendMessage(null, Event.SHOW_WARNING, warning);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public Task SendSuccess(Success success) => this.SendMessage(null, Event.SHOW_SUCCESS, success);
 | 
					    public Task SendSuccess(Success success) => this.SendMessage(null, Event.SHOW_SUCCESS, success);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void DeferMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data = default)
 | 
					    public void DeferMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data = default)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user