refactor: move more files to typescript
This commit is contained in:
20 files changed
+123
-177
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 })),
|
||||
@@ -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,
|
||||
);
|
||||
@@ -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,
|
||||
);
|
||||
@@ -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,
|
||||
);
|
||||
Reference in new issue
Block a user