refactor: move more files to typescript
This commit is contained in:
20 files changed
+123
-177
No files matched your search
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* @format
|
||||
* @param {string} date - Date from server
|
||||
* @returns {string} Formated Date
|
||||
*/
|
||||
|
||||
export const formateDate = (date) => {
|
||||
let date = new Date(date);
|
||||
date = new Intl.DateTimeFormat().format(date);
|
||||
return date;
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @format
|
||||
* @param {string} date - Date from server
|
||||
* @returns {string} Formated Date
|
||||
*/
|
||||
|
||||
export const formateDate = (date: string | number | Date) => {
|
||||
const dateObj = new Date(date);
|
||||
const formatedDate = new Intl.DateTimeFormat().format(dateObj);
|
||||
return formatedDate;
|
||||
};
|
||||
@@ -3,7 +3,7 @@
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to Milliseconds
|
||||
*/
|
||||
export const ticksToMs = (ticks) => {
|
||||
export const ticksToMs = (ticks: number) => {
|
||||
return Math.round(ticks / 10000);
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ export const ticksToMs = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to Seconds
|
||||
*/
|
||||
export const ticksToSec = (ticks) => {
|
||||
export const ticksToSec = (ticks: number) => {
|
||||
return Math.round(ticksToMs(ticks) / 1000);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ export const ticksToSec = (ticks) => {
|
||||
* @param {number} sec - Sec of a particular item
|
||||
* @return {number} Converted Seconds to C# ticks
|
||||
*/
|
||||
export const secToTicks = (ticks) => {
|
||||
export const secToTicks = (ticks: number) => {
|
||||
return Math.round(ticks * 10000000);
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ export const secToTicks = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to Hhr Mmin formate
|
||||
*/
|
||||
export const getRuntime = (ticks) => {
|
||||
export const getRuntime = (ticks: number) => {
|
||||
const time = ticksToMs(ticks);
|
||||
let formatedTime = "";
|
||||
let timeSec = Math.floor(time / 1000);
|
||||
@@ -51,7 +51,7 @@ export const getRuntime = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to hh:mm:ss formate
|
||||
*/
|
||||
export const getRuntimeMusic = (ticks) => {
|
||||
export const getRuntimeMusic = (ticks: number) => {
|
||||
const time = ticksToMs(ticks);
|
||||
let formatedTime = "";
|
||||
let timeSec = Math.floor(time / 1000);
|
||||
@@ -82,7 +82,7 @@ export const getRuntimeMusic = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to H hour M minutes formate
|
||||
*/
|
||||
export const getRuntimeFull = (ticks) => {
|
||||
export const getRuntimeFull = (ticks: number) => {
|
||||
const time = ticksToMs(ticks);
|
||||
let formatedTime = "";
|
||||
let timeSec = Math.floor(time / 1000);
|
||||
@@ -103,7 +103,7 @@ export const getRuntimeFull = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} Converted ticks to Hh Mm formate
|
||||
*/
|
||||
export const getRuntimeCompact = (ticks) => {
|
||||
export const getRuntimeCompact = (ticks: number) => {
|
||||
const time = ticksToMs(ticks);
|
||||
let formatedTime = "";
|
||||
let timeSec = Math.floor(time / 1000);
|
||||
@@ -124,7 +124,7 @@ export const getRuntimeCompact = (ticks) => {
|
||||
* @param {number} ticks - C# ticks of a particular item
|
||||
* @return {number} End time of an item
|
||||
*/
|
||||
export const endsAt = (ticks) => {
|
||||
export const endsAt = (ticks: number) => {
|
||||
const current = new Date();
|
||||
const currentTime = current.getTime();
|
||||
const time = ticksToMs(ticks);
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
|
||||
// see https://github.com/tannerlinsley/react-query/issues/293
|
||||
// see https://usehooks.com/useDebounce/
|
||||
export default function useDebounce(value, delay) {
|
||||
export default function useDebounce(value: string, delay: number) {
|
||||
// State and setters for debounced value
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
const useIntersecting = (ref) => {
|
||||
const [isIntersecting, setIntersecting] = useState(false);
|
||||
|
||||
const observer = useMemo(
|
||||
() =>
|
||||
new IntersectionObserver(([entry]) =>
|
||||
setIntersecting(entry.isIntersecting),
|
||||
),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
observer.observe(ref.current);
|
||||
return () => observer.disconnect();
|
||||
});
|
||||
|
||||
return isIntersecting;
|
||||
};
|
||||
|
||||
export default useIntersecting;
|
||||
@@ -1,17 +1,21 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
function useInterval(callback: () => void, delay) {
|
||||
const savedCallback = useRef(null);
|
||||
function useInterval(callback: () => void, delay: number) {
|
||||
const savedCallback = useRef<null | (() => void)>(null);
|
||||
|
||||
// Remember the latest callback.
|
||||
useEffect(() => {
|
||||
savedCallback.current = callback;
|
||||
if (savedCallback.current) {
|
||||
savedCallback.current = callback;
|
||||
}
|
||||
}, [callback]);
|
||||
|
||||
// Set up the interval.
|
||||
useEffect(() => {
|
||||
function tick() {
|
||||
savedCallback.current();
|
||||
if (savedCallback.current) {
|
||||
savedCallback.current();
|
||||
}
|
||||
}
|
||||
if (delay !== null) {
|
||||
const id = setInterval(tick, delay);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const useKeyPress = (targetKey) => {
|
||||
const useKeyPress = (targetKey: string) => {
|
||||
// State for keeping track of whether key is pressed
|
||||
const [keyPressed, setKeyPressed] = useState(false);
|
||||
// If pressed key is our target key then set to true
|
||||
function downHandler({ key }) {
|
||||
function downHandler({ key }: KeyboardEvent) {
|
||||
if (key === targetKey) {
|
||||
setKeyPressed(true);
|
||||
}
|
||||
}
|
||||
// If released key is our target key then set to false
|
||||
const upHandler = ({ key }) => {
|
||||
const upHandler = ({ key }: KeyboardEvent) => {
|
||||
if (key === targetKey) {
|
||||
setKeyPressed(false);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MotionValue, useTransform } from "framer-motion";
|
||||
import { type MotionValue, useTransform } from "framer-motion";
|
||||
|
||||
export default function useParallax(
|
||||
value: MotionValue<number>,
|
||||
|
||||
@@ -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