fix custom playlist sortorder handling

This commit is contained in:
Simon
2025-07-12 22:24:02 +07:00
parent 2b709ce9c1
commit 454952d9dd
5 changed files with 36 additions and 25 deletions

View File

@@ -160,6 +160,7 @@ class SearchProcess:
"playlist_last_refresh": playlist_last_refresh, "playlist_last_refresh": playlist_last_refresh,
} }
) )
print(playlist_dict)
return dict(sorted(playlist_dict.items())) return dict(sorted(playlist_dict.items()))

View File

@@ -325,6 +325,7 @@ class YoutubePlaylist(YouTubeItem):
self.delete_metadata() self.delete_metadata()
def create(self, name): def create(self, name):
"""create custom playlist"""
self.json_data = { self.json_data = {
"playlist_id": self.youtube_id, "playlist_id": self.youtube_id,
"playlist_active": False, "playlist_active": False,
@@ -337,6 +338,7 @@ class YoutubePlaylist(YouTubeItem):
"playlist_description": False, "playlist_description": False,
"playlist_thumbnail": False, "playlist_thumbnail": False,
"playlist_subscribed": False, "playlist_subscribed": False,
"playlist_sort_order": "top",
} }
self.upload_to_es() self.upload_to_es()
self.get_playlist_art() self.get_playlist_art()

View File

@@ -45,7 +45,7 @@ class QueryBuilder:
type_parsed = getattr(PlaylistTypesEnum, playlist_type.upper()).value type_parsed = getattr(PlaylistTypesEnum, playlist_type.upper()).value
return {"match": {"playlist_type.keyword": type_parsed}} return {"match": {"playlist_types": type_parsed}}
def parse_sort(self) -> dict: def parse_sort(self) -> dict:
"""return sort""" """return sort"""

View File

@@ -239,6 +239,12 @@ class PlaylistApiView(ApiBaseView):
error = ErrorResponseSerializer({"error": "playlist not found"}) error = ErrorResponseSerializer({"error": "playlist not found"})
return Response(error.data, status=404) return Response(error.data, status=404)
if self.response["playlist_type"] == "custom":
error = ErrorResponseSerializer(
{"error": f"playlist with ID {playlist_id} is custom"}
)
return Response(error.data, status=400)
subscribed = validated_data.get("playlist_subscribed") subscribed = validated_data.get("playlist_subscribed")
sort_order = validated_data.get("playlist_sort_order") sort_order = validated_data.get("playlist_sort_order")

View File

@@ -288,31 +288,33 @@ const Playlist = () => {
/> />
</div> </div>
)} )}
<div className="toggle"> {playlist.playlist_type !== 'custom' && (
<span>Switch sort order:</span> <div className="toggle">
<div className="toggleBox"> <span>Switch sort order:</span>
<input <div className="toggleBox">
id="playlist_sort_order" <input
type="checkbox" id="playlist_sort_order"
checked={playlist.playlist_sort_order === 'bottom'} type="checkbox"
onChange={async () => { checked={playlist.playlist_sort_order === 'bottom'}
const newSortOrder = onChange={async () => {
playlist.playlist_sort_order === 'top' ? 'bottom' : 'top'; const newSortOrder =
await updatePlaylistSortOrder(playlist.playlist_id, newSortOrder); playlist.playlist_sort_order === 'top' ? 'bottom' : 'top';
setRefresh(true); await updatePlaylistSortOrder(playlist.playlist_id, newSortOrder);
}} setRefresh(true);
/> }}
{playlist.playlist_sort_order === 'bottom' ? ( />
<label htmlFor="" className="onbtn"> {playlist.playlist_sort_order === 'bottom' ? (
On <label htmlFor="" className="onbtn">
</label> On
) : ( </label>
<label htmlFor="" className="ofbtn"> ) : (
Off <label htmlFor="" className="ofbtn">
</label> Off
)} </label>
)}
</div>
</div> </div>
</div> )}
</div> </div>
</div> </div>
</div> </div>