Fixes user state not updating when editing channels.

This commit is contained in:
SergeantPanda 2025-05-04 09:45:55 -05:00
parent 42db972e07
commit 4803a3605e
2 changed files with 28 additions and 1 deletions

View file

@ -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;
}
}
}

View file

@ -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);
};