Update front end when channels are edited.

This commit is contained in:
SergeantPanda 2025-06-26 13:30:52 -05:00
parent ba6012b28c
commit 00073698b3
3 changed files with 13 additions and 7 deletions

View file

@ -406,10 +406,7 @@ export default class API {
}
);
// Pass the channels array from the response, not the entire response
if (response.channels) {
useChannelsStore.getState().updateChannels(response.channels);
}
// Don't automatically update the store here - let the caller handle it
return response;
} catch (e) {
errorNotification('Failed to update channels', e);

View file

@ -78,6 +78,11 @@ const ChannelBatchForm = ({ channelIds, isOpen, onClose }) => {
try {
await API.updateChannels(channelIds, values);
// Refresh both the channels table data and the main channels store
await Promise.all([
API.requeryChannels(),
useChannelsStore.getState().fetchChannels()
]);
onClose();
} catch (error) {
console.error('Failed to update channels:', error);

View file

@ -152,14 +152,18 @@ const useChannelsStore = create((set, get) => ({
})),
updateChannels: (channels) => {
const channelsByUUID = {};
// Ensure channels is an array
if (!Array.isArray(channels)) {
console.error('updateChannels expects an array, received:', typeof channels, channels);
return;
} const channelsByUUID = {};
const updatedChannels = channels.reduce((acc, chan) => {
channelsByUUID[chan.uuid] = chan;
channelsByUUID[chan.uuid] = chan.id;
acc[chan.id] = chan;
return acc;
}, {});
return set((state) => ({
set((state) => ({
channels: {
...state.channels,
...updatedChannels,