blob: 2b09c12f405d9cbc1a8e8d35f35fa70ae5af7424 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import { useCallback, useMemo, useState } from "react";
import { useHistory } from "react-router";
import { useDidUpdate, useMediaMatch } from "rooks";
import { getBaseUrl } from ".";
export function useBaseUrl(slash: boolean = false) {
return useMemo(() => getBaseUrl(slash), [slash]);
}
export function useGotoHomepage() {
const history = useHistory();
return useCallback(() => history.push("/"), [history]);
}
export function useCanUpdateInject() {
if (process.env.NODE_ENV !== "production") {
return process.env["REACT_APP_CAN_UPDATE"] === "true";
} else {
return window.Bazarr.canUpdate;
}
}
export function useHasUpdateInject() {
if (process.env.NODE_ENV !== "production") {
return process.env["REACT_APP_HAS_UPDATE"] === "true";
} else {
return window.Bazarr.hasUpdate;
}
}
export function useIsMobile() {
return useMediaMatch("(max-width: 576px)");
}
export function useIsArrayExtended(arr: any[]) {
const [size, setSize] = useState(arr.length);
const [isExtended, setExtended] = useState(arr.length !== 0);
useDidUpdate(() => {
setExtended(arr.length > size);
setSize(arr.length);
}, [arr.length]);
return isExtended;
}
|