Closed vincejairam closed 1 year ago
This is a snippet in my detail component
protected override void OnInitialized()
{
Selected = HospitalState.Value.Selected.Data;
SubscribeToAction<SelectedHospitalSetDataAction>(SetSelected);
base.OnInitialized();
}
private void SetSelected(SelectedHospitalSetDataAction action)
{
Selected = action.Data;
}
/// <summary>
/// Callback fired when the form submitted is valid
/// </summary>
/// <param name="editContext"></param>
protected async Task OnFinishAsync(EditContext editContext)
{
var currentUser = await UtilityHelper.GetCurrentUserInfo(AuthenticationStateTask);
if (Selected.Id == 0)
{
Dispatcher.Dispatch(new SelectedHospitalInsertAction(Selected, currentUser));
}
else
{
Dispatcher.Dispatch(new SelectedHospitalUpdateAction(Selected, currentUser));
}
}
The HospitalListResponse has paging information etc...
public class HospitalListResponse : PagedResponse
{
public IEnumerable<HospitalListEntry> Hospitals { get; set; }
}
You'll have to put breakpoints on your reducers and see what changes it. I'm afraid I don't have time to debug other people's code, sorry.
The issue was when setting selected it still referred to the list item. I changed the action to construct a new item e.g.
public record SelectedHospitalSetDataAction
{
public HospitalListEntry Data { get; init; }
public bool ShowSelected { get; init; }
public SelectedHospitalSetDataAction(HospitalListEntry data, bool showSelected)
{
//create new object from orig
var jsonData = JsonSerializer.Serialize(data);
Data = JsonSerializer.Deserialize<HospitalListEntry>(jsonData);
ShowSelected = showSelected;
}
}
Not sure if this is the recommend way or should I do this prior to dispatching, but this corrected the issue..
I have a grid list list view where the the user clicks on a row (I fire a dispatch action for the selected item). In the grid view I also have a child component for a model component which is also has the same state to show. I am subscribing to the "set" action oninit which then sets the data for the component. It seems that when I update the view in the popmodel which triggers another action it is ALSO updating the list item
This is my store