From 4803a3605e489510c4b7c2009f13e188de4ee28d Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sun, 4 May 2025 09:45:55 -0500 Subject: [PATCH] Fixes user state not updating when editing channels. --- frontend/src/api.js | 10 ++++++++++ .../src/components/tables/ChannelsTable.jsx | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index b2ecf820..323c3e40 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1321,4 +1321,14 @@ export default class API { errorNotification('Failed to update channel EPGs', e); } } + + static async getChannel(id) { + try { + const response = await request(`${host}/api/channels/channels/${id}/?include_streams=true`); + return response; + } catch (e) { + errorNotification('Failed to fetch channel details', e); + return null; + } + } } diff --git a/frontend/src/components/tables/ChannelsTable.jsx b/frontend/src/components/tables/ChannelsTable.jsx index 9d08a541..b3aa3ff1 100644 --- a/frontend/src/components/tables/ChannelsTable.jsx +++ b/frontend/src/components/tables/ChannelsTable.jsx @@ -352,10 +352,27 @@ const ChannelsTable = ({ }) => { const editChannel = async (ch = null) => { if (ch) { console.log(`Opening editor for channel: ${ch.name} (${ch.id})`); + + try { + // Fetch the full channel with streams data directly from the API instead of the store + const fullChannelData = await API.getChannel(ch.id); + if (fullChannelData) { + setChannel(fullChannelData); + } else { + // Fallback to store data if API call fails + const latestChannel = useChannelsStore.getState().channels[ch.id]; + setChannel(latestChannel); + } + } catch (error) { + console.error("Error fetching channel data:", error); + // Fallback to store data if API call fails + const latestChannel = useChannelsStore.getState().channels[ch.id]; + setChannel(latestChannel); + } } else { console.log('Creating new channel'); + setChannel(null); } - setChannel(ch); setChannelModalOpen(true); };