diff --git a/apps/channels/api_views.py b/apps/channels/api_views.py index cec05ba1..78907f8f 100644 --- a/apps/channels/api_views.py +++ b/apps/channels/api_views.py @@ -649,7 +649,8 @@ class ChannelProfileViewSet(viewsets.ModelViewSet): class GetChannelStreamsAPIView(APIView): def get(self, request, channel_id): channel = get_object_or_404(Channel, id=channel_id) - streams = channel.streams + # Order the streams by channelstream__order to match the order in the channel view + streams = channel.streams.all().order_by('channelstream__order') serializer = StreamSerializer(streams, many=True) return Response(serializer.data) diff --git a/frontend/src/pages/Stats.jsx b/frontend/src/pages/Stats.jsx index 740f963a..4754f68a 100644 --- a/frontend/src/pages/Stats.jsx +++ b/frontend/src/pages/Stats.jsx @@ -98,14 +98,13 @@ const ChannelCard = ({ channel, clients, stopClient, stopChannel, logos, channel if (channelId) { const streamData = await API.getChannelStreams(channelId); - // Sort streams by ID to match the order in the channels view - const sortedStreamData = [...streamData].sort((a, b) => a.id - b.id); - setAvailableStreams(sortedStreamData); + // Use streams in the order returned by the API without sorting + setAvailableStreams(streamData); // If we have a channel URL, try to find the matching stream - if (channel.url && sortedStreamData.length > 0) { + if (channel.url && streamData.length > 0) { // Try to find matching stream based on URL - const matchingStream = sortedStreamData.find(stream => + const matchingStream = streamData.find(stream => channel.url.includes(stream.url) || stream.url.includes(channel.url) );