mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2026-01-05 21:30:53 -06:00
updating home screen playlist sort
This commit is contained in:
@@ -2,8 +2,15 @@ import Client from "../../client";
|
||||
import { BaseItemDto, ItemSortBy, SortOrder } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
|
||||
export function fetchUserPlaylists(): Promise<BaseItemDto[]> {
|
||||
console.debug("Fetching user playlists");
|
||||
export function fetchUserPlaylists(
|
||||
sortBy: ItemSortBy[] = []
|
||||
): Promise<BaseItemDto[]> {
|
||||
console.debug(`Fetching user playlists ${sortBy.length > 0 ? "sorting by " + sortBy.toString() : ""}`);
|
||||
|
||||
const defaultSorting : ItemSortBy[] = [
|
||||
ItemSortBy.IsFolder,
|
||||
ItemSortBy.SortName,
|
||||
]
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
getItemsApi(Client.api!)
|
||||
@@ -13,10 +20,7 @@ export function fetchUserPlaylists(): Promise<BaseItemDto[]> {
|
||||
fields: [
|
||||
"Path"
|
||||
],
|
||||
sortBy: [
|
||||
ItemSortBy.IsFolder,
|
||||
ItemSortBy.SortName
|
||||
],
|
||||
sortBy: defaultSorting.concat(sortBy),
|
||||
sortOrder: [
|
||||
SortOrder.Ascending
|
||||
]
|
||||
|
||||
@@ -2,14 +2,15 @@ import { QueryKeys } from "../../enums/query-keys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { fetchUserPlaylists } from "./functions/playlists";
|
||||
import { fetchFavoritePlaylists } from "./functions/favorites";
|
||||
import { ItemSortBy } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
|
||||
export const useFavoritePlaylists = () => useQuery({
|
||||
queryKey: [QueryKeys.FavoritePlaylists],
|
||||
queryFn: () => fetchFavoritePlaylists()
|
||||
});
|
||||
|
||||
export const useUserPlaylists = () => useQuery({
|
||||
export const useUserPlaylists = (sortBy: ItemSortBy[] = []) => useQuery({
|
||||
queryKey: [QueryKeys.UserPlaylists],
|
||||
queryFn: () => fetchUserPlaylists()
|
||||
queryFn: () => fetchUserPlaylists(sortBy)
|
||||
});
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ import React from "react";
|
||||
import { FlatList } from "react-native";
|
||||
import { getToken, View, XStack, YStack } from "tamagui";
|
||||
import Icon from "../../../components/Global/helpers/icon";
|
||||
import { ItemSortBy } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
|
||||
export default function Playlists({ navigation }: { navigation: NativeStackNavigationProp<StackParamList>}) : React.JSX.Element {
|
||||
|
||||
const { data: playlists } = useUserPlaylists();
|
||||
const { data: playlists } = useUserPlaylists([ItemSortBy.DatePlayed]);
|
||||
|
||||
return (
|
||||
<View>
|
||||
|
||||
Reference in New Issue
Block a user