refactor: move more files to typescript

This commit is contained in:
Prayag Prajapati committed 2024-12-03 22:21:48 +05:30
1 parent 97526e29b4
commit cf8c5d4490
20 files changed
+123 -177

No files matched your search

-1
View File
@@ -8,7 +8,6 @@ import { version as appVer } from "../../../package.json";
// Initial custom axios client to use tauri's http module
import axios from "axios";
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
type ApiStore = {
api: Api | undefined;
+2 -7
View File
@@ -1,13 +1,8 @@
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
import { create } from "zustand";
import { setQueue } from "./queue";
import { start } from "repl";
import { max } from "lodash";
import type React from "react";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
import { secToTicks } from "../date/time";
import playbackProfile from "../playback-profiles";
type AudioPlaybackStore = {
@@ -90,11 +85,11 @@ export const generateAudioStreamUrl = (
enableRemoteMedia: false,
enableAudioVbrEncoding: true,
};
const urlParams = new URLSearchParams(urlOptions).toString();
const urlParams = new URLSearchParams(urlOptions as any).toString();
return `${basePath}/Audio/${itemId}/universal?${urlParams}`;
};
export const setAudioRef = (ref) => {
export const setAudioRef = (ref: React.RefObject<HTMLAudioElement>) => {
const state = useAudioPlayback.getState();
state.player.ref = ref;
useAudioPlayback.setState(state);
+10 -17
View File
@@ -1,28 +1,21 @@
import { createStore } from "zustand";
import { shallow } from "zustand/shallow";
import { useStoreWithEqualityFn } from "zustand/traditional";
import { createWithEqualityFn } from "zustand/traditional";
type BackdropStore = {
backdropUrl: string;
backdropId: string;
setBackdrop: (
url: string | undefined | null,
id: string | undefined | null,
) => void;
setBackdrop: (url: string | undefined, id: string | undefined) => void;
};
export const backdropStore = createStore((set) => ({
backdropUrl: "",
backdropId: "",
setBackdrop: (
url: string | undefined | null,
id: string | undefined | null,
) => set(() => ({ backdropUrl: url, backdropId: id })),
}));
export const useBackdropStore = createWithEqualityFn<BackdropStore>(
(set) => ({
backdropUrl: "",
backdropId: "",
setBackdrop: (url, id) => set(() => ({ backdropUrl: url, backdropId: id })),
}),
shallow,
);
export function useBackdropStore<T>(selector?: (state: BackdropStore) => T) {
return useStoreWithEqualityFn(backdropStore, selector!, shallow);
}
/**
* @deprecated Please use setBackdrop method from the store
*/
@@ -1,8 +1,11 @@
import { create } from "zustand";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
export const useCarouselStore = createWithEqualityFn(
type CarouselStore = {
direction: "left" | "right";
setDirection: (dir: "left" | "right") => void;
};
export const useCarouselStore = createWithEqualityFn<CarouselStore>(
(set) => ({
direction: "right",
setDirection: (dir) => set(() => ({ direction: dir })),
-10
View File
@@ -1,10 +0,0 @@
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
export const useDrawerStore = createWithEqualityFn(
(set) => ({
open: false,
setOpen: (sopen) => set((state) => ({ ...state, open: sopen })),
}),
shallow,
);
+17
View File
@@ -0,0 +1,17 @@
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
type DrawerStore = {
open: boolean;
setOpen: (sopen: boolean) => void;
};
export const useDrawerStore = createWithEqualityFn<DrawerStore>(
(set) => ({
open: false,
setOpen: (sopen) => {
set(() => ({ open: sopen }));
},
}),
shallow,
);
+9 -17
View File
@@ -1,10 +1,7 @@
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
import { create } from "zustand";
import { devtools } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
import { usePlaybackStore } from "./playback";
type PhotosPlaybackStore = {
photos: BaseItemDto[] | null;
@@ -12,21 +9,16 @@ type PhotosPlaybackStore = {
playPhotos: (photos: BaseItemDto[], index: number) => void;
};
type PhotosPlaybackStoreActions = {
playPhotos: (photos: BaseItemDto[]) => void;
};
export const usePhotosPlayback = createWithEqualityFn<PhotosPlaybackStore>()(
devtools(
immer((set) => ({
photos: null,
playPhotos: (photos, index) =>
set((state) => {
state.photos = photos;
state.index = index;
}),
index: 0,
})),
),
immer((set) => ({
photos: null,
playPhotos: (photos, index) =>
set((state) => {
state.photos = photos;
state.index = index;
}),
index: 0,
})),
shallow,
);