mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
enhancement(web): improve functionality of utility components (#1094)
added missing Buffer definition for Stacktracey, made date functions more robust against undefined values enhancement: made simplifyDate and IsEmptyDate prone against undefined values fix: added a global Buffer definition (apparently required by Stacktracey)
This commit is contained in:
parent
087471a1f7
commit
64f81a4614
4 changed files with 29 additions and 6 deletions
|
@ -46,6 +46,7 @@
|
|||
"@typescript-eslint/parser": "^6.5.0",
|
||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||
"autoprefixer": "^10.4.15",
|
||||
"buffer": "^6.0.3",
|
||||
"date-fns": "^2.30.0",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
|
|
18
web/pnpm-lock.yaml
generated
18
web/pnpm-lock.yaml
generated
|
@ -59,6 +59,9 @@ dependencies:
|
|||
autoprefixer:
|
||||
specifier: ^10.4.15
|
||||
version: 10.4.15(postcss@8.4.29)
|
||||
buffer:
|
||||
specifier: ^6.0.3
|
||||
version: 6.0.3
|
||||
date-fns:
|
||||
specifier: ^2.30.0
|
||||
version: 2.30.0
|
||||
|
@ -2766,6 +2769,10 @@ packages:
|
|||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
dev: false
|
||||
|
||||
/base64-js@1.5.1:
|
||||
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||
dev: false
|
||||
|
||||
/binary-extensions@2.2.0:
|
||||
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
||||
engines: {node: '>=8'}
|
||||
|
@ -2806,6 +2813,13 @@ packages:
|
|||
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
|
||||
dev: false
|
||||
|
||||
/buffer@6.0.3:
|
||||
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
||||
dependencies:
|
||||
base64-js: 1.5.1
|
||||
ieee754: 1.2.1
|
||||
dev: false
|
||||
|
||||
/builtin-modules@3.3.0:
|
||||
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
|
||||
engines: {node: '>=6'}
|
||||
|
@ -3839,6 +3853,10 @@ packages:
|
|||
resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==}
|
||||
dev: false
|
||||
|
||||
/ieee754@1.2.1:
|
||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||
dev: false
|
||||
|
||||
/ignore@5.2.4:
|
||||
resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
|
||||
engines: {node: '>= 4'}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { Buffer } from "buffer";
|
||||
|
||||
import "@fontsource-variable/inter";
|
||||
import "./index.css";
|
||||
|
@ -18,6 +19,9 @@ declare global {
|
|||
}
|
||||
|
||||
window.APP = window.APP || {};
|
||||
// Apparently Stacktracey requires this for some weird reason
|
||||
// (at least in local dev env)
|
||||
window.Buffer = Buffer;
|
||||
|
||||
// Initializes auth and theme contexts
|
||||
InitializeGlobalContext();
|
||||
|
@ -28,4 +32,4 @@ root.render(
|
|||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
||||
);
|
||||
|
|
|
@ -39,16 +39,16 @@ export function classNames(...classes: string[]) {
|
|||
export type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
||||
|
||||
// simplify date
|
||||
export function simplifyDate(date: string) {
|
||||
if (date !== "0001-01-01T00:00:00Z") {
|
||||
export function simplifyDate(date?: string) {
|
||||
if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") {
|
||||
return formatISO9075(new Date(date));
|
||||
}
|
||||
return "n/a";
|
||||
}
|
||||
|
||||
// if empty date show as n/a
|
||||
export function IsEmptyDate(date: string) {
|
||||
if (date !== "0001-01-01T00:00:00Z") {
|
||||
export function IsEmptyDate(date?: string) {
|
||||
if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") {
|
||||
return formatDistanceToNowStrict(
|
||||
new Date(date),
|
||||
{ addSuffix: true }
|
||||
|
@ -82,4 +82,4 @@ export const get = <T> (obj: T, path: string|Array<any>, defValue?: string) => {
|
|||
);
|
||||
// If found value is undefined return default value; otherwise return the value
|
||||
return result === undefined ? defValue : result;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue