If you want to update other components when an item is Saved, Changed or Deleted then you can use the AppState class.
Copy [ Inject ] public AppState AppState { get; set; } = default! ;
The AppState has several events you can subscribe to in your component, these are:
Copy public event Func < ContentType ?, string , Task > ? OnContentTypeChanged;
public event Func < Content . Models . Content ?, string , Task > ? OnContentChanged;
public event Func < User ?, string , Task > ? OnUserChanged;
public event Func < Media . Models . Media ?, string , Task > ? OnMediaChanged;
public event Func < ContentType ?, string , Task > ? OnContentTypeSaved;
public event Func < Content . Models . Content ?, string , Task > ? OnContentSaved;
public event Func < User ?, string , Task > ? OnUserSaved;
public event Func < Media . Models . Media ?, string , Task > ? OnMediaSaved;
public event Func < ContentType ?, string , Task > ? OnContentTypeDeleted;
public event Func < Content . Models . Content ?, string , Task > ? OnContentDeleted;
public event Func < User ?, string , Task > ? OnUserDeleted;
public event Func < Media . Models . Media ?, string , Task > ? OnMediaDeleted;
Copy protected override async Task OnInitializedAsync ()
{
await DataRefresh ();
AppState . OnUserChanged += HandleUsersChanged;
}
public void Dispose ()
{
AppState . OnUserChanged -= HandleUsersChanged;
}
private async Task HandleUsersChanged ( User ? user , string username)
{
await DataRefresh ();
StateHasChanged ();
}
As you can see, the item being changed or updated is passing in to most events, so you could update or check data when the events are triggered.
There may be times where you change some data and want to notify other components, this can be done like so (Example below is notifying a user change and passing in the User being updated and the current logged in User), you would do the same for Content, Media & ContentTypes
Copy await AppState . NotifyUserChanged (User , AuthState . User . Identity ? . Name ! );