From 00073698b3f2ecd32a431dbc268dce457355209d Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 26 Jun 2025 13:30:52 -0500 Subject: [PATCH] Update front end when channels are edited. --- frontend/src/api.js | 5 +---- frontend/src/components/forms/ChannelBatch.jsx | 5 +++++ frontend/src/store/channels.jsx | 10 +++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index cd9d21ca..391eaae9 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -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); diff --git a/frontend/src/components/forms/ChannelBatch.jsx b/frontend/src/components/forms/ChannelBatch.jsx index e26dba38..e5b4504e 100644 --- a/frontend/src/components/forms/ChannelBatch.jsx +++ b/frontend/src/components/forms/ChannelBatch.jsx @@ -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); diff --git a/frontend/src/store/channels.jsx b/frontend/src/store/channels.jsx index 54b1b20f..beb62fe1 100644 --- a/frontend/src/store/channels.jsx +++ b/frontend/src/store/channels.jsx @@ -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,