mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2026-01-05 21:30:53 -06:00
adjust image calls to make them more consistent and concise
This commit is contained in:
@@ -4,7 +4,7 @@ import _ from "lodash"
|
||||
import Client from "../../../api/client"
|
||||
import { Dirs, FileSystem } from 'react-native-file-access'
|
||||
|
||||
export function fetchItemImage(itemId: string, imageType: ImageType = ImageType.Primary, width: number = 150, height: number = 150) {
|
||||
export function fetchItemImage(itemId: string, imageType: ImageType = ImageType.Primary, width: number, height: number) {
|
||||
|
||||
return new Promise<string>(async (resolve, reject) => {
|
||||
|
||||
@@ -21,8 +21,8 @@ export function fetchItemImage(itemId: string, imageType: ImageType = ImageType.
|
||||
.getItemImage({
|
||||
itemId,
|
||||
imageType,
|
||||
width: Math.ceil(width) * 2,
|
||||
height: Math.ceil(width) * 2,
|
||||
width: Math.ceil(width / 100) * 100 * 2, // Round to the nearest 100 for simplicity and to avoid
|
||||
height: Math.ceil(height / 100) * 100 * 2, // redundant images in storage, then double it to make sure it's crispy
|
||||
format: ImageFormat.Png
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3,8 +3,14 @@ import { QueryKeys } from "../../enums/query-keys";
|
||||
import { fetchItemImage } from "./functions/images";
|
||||
import { ImageType } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
|
||||
export const useItemImage = (itemId: string, imageType?: ImageType, width?: number, height?: number) => useQuery({
|
||||
queryKey: [QueryKeys.ItemImage, itemId, imageType, width, height],
|
||||
export const useItemImage = (itemId: string, imageType?: ImageType, width: number = 150, height: number = 150) => useQuery({
|
||||
queryKey: [
|
||||
QueryKeys.ItemImage,
|
||||
itemId,
|
||||
imageType,
|
||||
Math.ceil(width / 100) * 100, // Images are fetched at a higher, generic resolution
|
||||
Math.ceil(height / 100) * 100 // So these keys need to match
|
||||
],
|
||||
queryFn: () => fetchItemImage(itemId, imageType, width, height),
|
||||
staleTime: 1000 * 60, // One minute, these are stored on disk anyways
|
||||
gcTime: 1000 * 60 * 60 // One hour, could be less maybe?
|
||||
|
||||
Reference in New Issue
Block a user