Refactor(web): Replace final-form with Formik and cleanup (#46)

* refactor: begin to replace final-form

* refactor: replace final-form with formik n cleanup
This commit is contained in:
Ludvig Lundgren 2021-12-23 22:01:59 +01:00 committed by GitHub
parent c4d580eb03
commit 5e29564f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 1523 additions and 3409 deletions

59
web/src/utils/index.ts Normal file
View file

@ -0,0 +1,59 @@
// sleep for x ms
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// get baseUrl sent from server rendered index template
export function baseUrl() {
let baseUrl = ""
if (window.APP.baseUrl) {
if (window.APP.baseUrl === "/") {
baseUrl = "/"
} else if (window.APP.baseUrl === "{{.BaseUrl}}") {
baseUrl = "/"
} else if (window.APP.baseUrl === "/autobrr/") {
baseUrl = "/autobrr/"
} else {
baseUrl = window.APP.baseUrl
}
}
return baseUrl
}
// get sseBaseUrl for SSE
export function sseBaseUrl() {
let {origin} = window.location
let env = process.env.NODE_ENV
if (env === "development") {
return `http://localhost:8989/`
}
return `${origin}${baseUrl()}`
}
export function buildPath(...args: string[]): string {
const [first] = args;
const firstTrimmed = first.trim();
const result = args
.map((part) => part.trim())
.map((part, i) => {
if (i === 0) {
return part.replace(/[/]*$/g, '');
} else {
return part.replace(/(^[/]*|[/]*$)/g, '');
}
})
.filter((x) => x.length)
.join('/');
return firstTrimmed === '/' ? `/${result}` : result;
}
export function classNames(...classes: string[]) {
return classes.filter(Boolean).join(' ')
}
// column widths for inputs etc
export type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;