feat: improve channel deletion logic
This commit is contained in:
@@ -62,8 +62,9 @@ app.use('/proxy', proxyRouter);
|
||||
const PORT = 5000;
|
||||
const server = app.listen(PORT, async () => {
|
||||
console.log(`Server listening on Port ${PORT}`);
|
||||
if (ChannelService.getCurrentChannel().restream()) {
|
||||
await streamController.start(ChannelService.getCurrentChannel());
|
||||
const currentChannel = ChannelService.getCurrentChannel();
|
||||
if (currentChannel && currentChannel.restream()) {
|
||||
await streamController.start(currentChannel);
|
||||
}
|
||||
PlaylistUpdater.startScheduler();
|
||||
PlaylistUpdater.registerChannelsPlaylist(ChannelService.getChannels());
|
||||
|
||||
@@ -88,10 +88,17 @@ class ChannelService {
|
||||
throw new Error('Channel does not exist');
|
||||
}
|
||||
|
||||
// Prevent deleting the last channel
|
||||
if (this.channels.length === 1) {
|
||||
throw new Error('Cannot delete the last channel');
|
||||
}
|
||||
|
||||
const [deletedChannel] = this.channels.splice(channelIndex, 1);
|
||||
|
||||
// If we deleted the current channel, switch to another one
|
||||
if (this.currentChannel.id === id) {
|
||||
await this.setCurrentChannel(0);
|
||||
const nextChannel = this.channels[0];
|
||||
await this.setCurrentChannel(nextChannel.id);
|
||||
}
|
||||
|
||||
if(save) ChannelStorage.save(this.channels);
|
||||
|
||||
@@ -155,17 +155,17 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
|
||||
|
||||
const handleDelete = () => {
|
||||
if (channel) {
|
||||
addToast({
|
||||
type: "error",
|
||||
title: `Deleting ${type}`,
|
||||
duration: 3000,
|
||||
});
|
||||
if (type === 'channel') {
|
||||
socketService.deleteChannel(channel.id);
|
||||
} else if (type === 'playlist') {
|
||||
socketService.deletePlaylist(channel.playlist);
|
||||
}
|
||||
}
|
||||
addToast({
|
||||
type: 'error',
|
||||
title: `${type} deleted`,
|
||||
duration: 3000,
|
||||
});
|
||||
onClose();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user