From 97526e29b410302c6e97e831b99e3a2d35b77fb8 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Tue, 3 Dec 2024 19:01:17 +0530 Subject: [PATCH] refactor: move more components to ts --- package.json | 2 +- src/components/outroCard/index.tsx | 38 +++-- src/components/outroCard/outroCard.scss | 2 +- src/components/queueTrack/index.tsx | 80 +--------- src/components/showMoreText/index.tsx | 12 +- src/components/skeleton/cards.jsx | 26 --- src/components/skeleton/cards.tsx | 34 ++++ .../skeleton/{carousel.jsx => carousel.tsx} | 27 ++-- src/components/skeleton/episode.tsx | 150 +++++++++++------- src/components/skeleton/episodeCards.jsx | 59 ------- ...{seasonSelector.jsx => seasonSelector.tsx} | 9 +- src/routes/_api/player/audio.tsx | 8 +- 12 files changed, 180 insertions(+), 267 deletions(-) delete mode 100644 src/components/skeleton/cards.jsx create mode 100644 src/components/skeleton/cards.tsx rename src/components/skeleton/{carousel.jsx => carousel.tsx} (68%) delete mode 100644 src/components/skeleton/episodeCards.jsx rename src/components/skeleton/{seasonSelector.jsx => seasonSelector.tsx} (89%) diff --git a/package.json b/package.json index e3b0314..4fd8022 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "blink", "private": true, - "version": "0.0.6-dev", + "version": "0.0.7-dev", "type": "module", "scripts": { "dev": "vite --force && tsr watch", diff --git a/src/components/outroCard/index.tsx b/src/components/outroCard/index.tsx index af043df..d0b1921 100644 --- a/src/components/outroCard/index.tsx +++ b/src/components/outroCard/index.tsx @@ -1,5 +1,5 @@ import { useApiInContext } from "@/utils/store/api"; -import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback"; +import { playItemFromQueue } from "@/utils/store/playback"; import useQueue from "@/utils/store/queue"; import { Button, Typography } from "@mui/material"; import React from "react"; @@ -7,8 +7,8 @@ import { getTypeIcon } from "../utils/iconsCollection"; import "./outroCard.scss"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useCentralStore } from "@/utils/store/central"; +import { useMutation } from "@tanstack/react-query"; const OutroCard = (props: { handleShowCredits: () => void }) => { const api = useApiInContext((s) => s.api); @@ -16,19 +16,14 @@ const OutroCard = (props: { handleShowCredits: () => void }) => { s.currentItemIndex, s.tracks, ]); - const item = queueItems[nextItemIndex + 1]; - const user = useQuery({ - queryKey: ["user"], - queryFn: async () => { - const result = await getUserApi(api).getCurrentUser(); - return result.data; - }, - }); + const item = queueItems?.[nextItemIndex + 1]; + const user = useCentralStore((s) => s.currentUser); const handlePlayNext = useMutation({ mutationKey: ["playNextButton"], - mutationFn: () => playItemFromQueue("next", user.data?.Id, api), + mutationFn: () => playItemFromQueue("next", user?.Id, api), onError: (error) => [console.error(error)], }); + if (!item || !item.Type) return null; return (
Up Next @@ -37,14 +32,21 @@ const OutroCard = (props: { handleShowCredits: () => void }) => { {item.Name ) : (
- {getTypeIcon(item?.Type)} + {getTypeIcon(item.Type)}
)} @@ -56,6 +58,7 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
- {currentDraggingIndex && currentDraggingIndex >= 0 && ( + {(currentDraggingIndex ?? -1) >= 0 && (
drag_handle
- {queue[currentDraggingIndex].Name} + {queue[currentDraggingIndex ?? 0].Name} - {queue[currentDraggingIndex].Artists?.join(", ")} + {queue[currentDraggingIndex ?? 0].Artists?.join(", ")}
{getRuntimeMusic( - queue[currentDraggingIndex].RunTimeTicks ?? 0, + queue[currentDraggingIndex ?? 0].RunTimeTicks ?? 0, )}