* PATCHes only the stream order for a channel * without triggering requeryStreams or requeryChannels. The caller is * responsible for optimistic UI updates.
(channelId, streamIds)
| 716 | * responsible for optimistic UI updates. |
| 717 | */ |
| 718 | static async reorderChannelStreams(channelId, streamIds) { |
| 719 | try { |
| 720 | await request(`${host}/api/channels/channels/${channelId}/`, { |
| 721 | method: 'PATCH', |
| 722 | body: { id: channelId, streams: streamIds }, |
| 723 | }); |
| 724 | // Update the channelsTable store in-place with the new stream order |
| 725 | const store = useChannelsTableStore.getState(); |
| 726 | const channel = store.channels.find((c) => c.id === channelId); |
| 727 | if (channel) { |
| 728 | // Reorder the existing stream objects to match streamIds |
| 729 | const streamMap = new Map(channel.streams.map((s) => [s.id, s])); |
| 730 | const reorderedStreams = streamIds |
| 731 | .map((id) => streamMap.get(id)) |
| 732 | .filter(Boolean); |
| 733 | store.updateChannel({ ...channel, streams: reorderedStreams }); |
| 734 | } |
| 735 | } catch (e) { |
| 736 | errorNotification('Failed to reorder streams', e); |
| 737 | // On failure, requery to restore correct state |
| 738 | await API.requeryChannels(); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * PATCHes the channel with the |
no test coverage detected