mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-04-22 00:34:43 +01:00
chore: refactor
This commit is contained in:
@@ -3,9 +3,12 @@ import { Text } from "@/components/common/Text";
|
||||
import ContinueWatchingPoster from "@/components/ContinueWatchingPoster";
|
||||
import { ItemCardText } from "@/components/ItemCardText";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { nextUp } from "@/utils/jellyfin";
|
||||
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { getItemsApi, getSuggestionsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import {
|
||||
getItemsApi,
|
||||
getSuggestionsApi,
|
||||
getTvShowsApi,
|
||||
} from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useRouter } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
@@ -19,22 +22,24 @@ import {
|
||||
} from "react-native";
|
||||
|
||||
export default function index() {
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const router = useRouter();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const { data, isLoading, isError } = useQuery<BaseItemDto[]>({
|
||||
queryKey: ["resumeItems", user?.Id],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const response = await getItemsApi(api).getResumeItems({
|
||||
userId: user.Id,
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
queryFn: async () =>
|
||||
(api &&
|
||||
(
|
||||
await getItemsApi(api).getResumeItems({
|
||||
userId: user?.Id,
|
||||
})
|
||||
).data.Items) ||
|
||||
[],
|
||||
enabled: !!api && !!user?.Id,
|
||||
staleTime: 60,
|
||||
});
|
||||
@@ -42,10 +47,14 @@ export default function index() {
|
||||
const { data: _nextUpData } = useQuery({
|
||||
queryKey: ["nextUp-all", user?.Id],
|
||||
queryFn: async () =>
|
||||
await nextUp({
|
||||
userId: user?.Id,
|
||||
api,
|
||||
}),
|
||||
(api &&
|
||||
(
|
||||
await getTvShowsApi(api).getNextUp({
|
||||
userId: user?.Id,
|
||||
fields: ["MediaSourceCount"],
|
||||
})
|
||||
).data.Items) ||
|
||||
[],
|
||||
enabled: !!api && !!user?.Id,
|
||||
staleTime: 0,
|
||||
});
|
||||
@@ -87,26 +96,20 @@ export default function index() {
|
||||
|
||||
const { data: suggestions } = useQuery<BaseItemDto[]>({
|
||||
queryKey: ["suggestions", user?.Id],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id) {
|
||||
return [];
|
||||
}
|
||||
const response = await getSuggestionsApi(api).getSuggestions({
|
||||
userId: user.Id,
|
||||
limit: 5,
|
||||
mediaType: ["Video"],
|
||||
});
|
||||
|
||||
return response.data.Items || [];
|
||||
},
|
||||
queryFn: async () =>
|
||||
(api &&
|
||||
(
|
||||
await getSuggestionsApi(api).getSuggestions({
|
||||
userId: user?.Id,
|
||||
limit: 5,
|
||||
mediaType: ["Video"],
|
||||
})
|
||||
).data.Items) ||
|
||||
[],
|
||||
enabled: !!api && !!user?.Id,
|
||||
staleTime: 60,
|
||||
});
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const refetch = useCallback(async () => {
|
||||
setLoading(true);
|
||||
await queryClient.refetchQueries({ queryKey: ["resumeItems", user?.Id] });
|
||||
|
||||
@@ -6,7 +6,8 @@ import { ItemCardText } from "@/components/ItemCardText";
|
||||
import MoviePoster from "@/components/MoviePoster";
|
||||
import Poster from "@/components/Poster";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { getPrimaryImage, getUserItemData } from "@/utils/jellyfin";
|
||||
import { getPrimaryImage } from "@/utils/jellyfin";
|
||||
import { getUserItemData } from "@/utils/jellyfin/items/getUserItemData";
|
||||
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { getSearchApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
@@ -146,21 +147,6 @@ export default function search() {
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* <Text>Series</Text>
|
||||
|
||||
<HorizontalScroll
|
||||
data={series}
|
||||
renderItem={(item, index) => <Poster itemId={item.Id} key={index} />}
|
||||
/>
|
||||
|
||||
<Text>Episodes</Text>
|
||||
<HorizontalScroll
|
||||
data={episodes}
|
||||
renderItem={(item, index) => (
|
||||
<ContinueWatchingPoster item={item} key={index} />
|
||||
)}
|
||||
/> */}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
@@ -187,13 +173,15 @@ const SearchItemWrapper: React.FC<Props> = ({ ids, renderItem }) => {
|
||||
api,
|
||||
userId: user.Id,
|
||||
itemId: id,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
const results = await Promise.all(itemPromises);
|
||||
|
||||
// Filter out null items
|
||||
return results.filter((item) => item !== null);
|
||||
return results.filter(
|
||||
(item) => item !== null,
|
||||
) as unknown as BaseItemDto[];
|
||||
},
|
||||
enabled: !!ids && ids.length > 0 && !!api && !!user?.Id,
|
||||
staleTime: Infinity,
|
||||
|
||||
@@ -25,19 +25,14 @@ const page: React.FC = () => {
|
||||
|
||||
const { data: collection } = useQuery({
|
||||
queryKey: ["collection", collectionId],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = (
|
||||
await getItemsApi(api).getItems({
|
||||
userId: user.Id,
|
||||
})
|
||||
).data;
|
||||
|
||||
return data.Items?.find((item) => item.Id == collectionId);
|
||||
},
|
||||
queryFn: async () =>
|
||||
(api &&
|
||||
(
|
||||
await getItemsApi(api).getItems({
|
||||
userId: user?.Id,
|
||||
})
|
||||
).data.Items?.find((item) => item.Id == collectionId)) ||
|
||||
null,
|
||||
enabled: !!api && !!user?.Id,
|
||||
staleTime: 0,
|
||||
});
|
||||
@@ -77,7 +72,7 @@ const page: React.FC = () => {
|
||||
headers: {
|
||||
Authorization: `MediaBrowser DeviceId="${api.deviceInfo.id}", Token="${api.accessToken}"`,
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return response.data || [];
|
||||
|
||||
@@ -7,11 +7,7 @@ import { CurrentSeries } from "@/components/series/CurrentSeries";
|
||||
import { SimilarItems } from "@/components/SimilarItems";
|
||||
import { VideoPlayer } from "@/components/VideoPlayer";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import {
|
||||
getBackdrop,
|
||||
getLogoImageById,
|
||||
getUserItemData,
|
||||
} from "@/utils/jellyfin";
|
||||
import { getBackdrop, getLogoImageById } from "@/utils/jellyfin";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Image } from "expo-image";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
@@ -24,6 +20,7 @@ import {
|
||||
View,
|
||||
} from "react-native";
|
||||
import { ParallaxScrollView } from "../../../../components/ParallaxPage";
|
||||
import { getUserItemData } from "@/utils/jellyfin/items/getUserItemData";
|
||||
|
||||
const page: React.FC = () => {
|
||||
const local = useLocalSearchParams();
|
||||
@@ -54,12 +51,12 @@ const page: React.FC = () => {
|
||||
quality: 90,
|
||||
width: 1000,
|
||||
}),
|
||||
[item]
|
||||
[item],
|
||||
);
|
||||
|
||||
const logoUrl = useMemo(
|
||||
() => (item?.Type === "Movie" ? getLogoImageById({ api, item }) : null),
|
||||
[item]
|
||||
[item],
|
||||
);
|
||||
|
||||
if (l1)
|
||||
|
||||
@@ -3,13 +3,8 @@ import { ParallaxScrollView } from "@/components/ParallaxPage";
|
||||
import { NextUp } from "@/components/series/NextUp";
|
||||
import { SeasonPicker } from "@/components/series/SeasonPicker";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import {
|
||||
getBackdrop,
|
||||
getLogoImageById,
|
||||
getPrimaryImage,
|
||||
getPrimaryImageById,
|
||||
getUserItemData,
|
||||
} from "@/utils/jellyfin";
|
||||
import { getBackdrop, getLogoImageById } from "@/utils/jellyfin";
|
||||
import { getUserItemData } from "@/utils/jellyfin/items/getUserItemData";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Image } from "expo-image";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
@@ -44,7 +39,7 @@ const page: React.FC = () => {
|
||||
quality: 90,
|
||||
width: 1000,
|
||||
}),
|
||||
[item]
|
||||
[item],
|
||||
);
|
||||
|
||||
const logoUrl = useMemo(
|
||||
@@ -53,7 +48,7 @@ const page: React.FC = () => {
|
||||
api,
|
||||
item,
|
||||
}),
|
||||
[item]
|
||||
[item],
|
||||
);
|
||||
|
||||
if (!item || !backdropUrl) return null;
|
||||
|
||||
@@ -2,13 +2,13 @@ import { Button } from "@/components/Button";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { ListItem } from "@/components/ListItem";
|
||||
import { apiAtom, useJellyfin, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useFiles } from "@/utils/files/useFiles";
|
||||
import { readFromLog } from "@/utils/log";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
import { useAtom } from "jotai";
|
||||
import { ScrollView, View } from "react-native";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import { useFiles } from "@/hooks/useFiles";
|
||||
|
||||
export default function settings() {
|
||||
const { logout } = useJellyfin();
|
||||
@@ -39,7 +39,9 @@ export default function settings() {
|
||||
color="red"
|
||||
onPress={async () => {
|
||||
await deleteAllFiles();
|
||||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success)
|
||||
Haptics.notificationAsync(
|
||||
Haptics.NotificationFeedbackType.Success,
|
||||
);
|
||||
}}
|
||||
>
|
||||
Delete all downloaded files
|
||||
|
||||
Reference in New Issue
Block a user