mirror of
https://github.com/idanoo/autobrr
synced 2025-07-24 01:09:13 +00:00
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:
parent
c4d580eb03
commit
5e29564f03
66 changed files with 1523 additions and 3409 deletions
59
web/src/utils/index.ts
Normal file
59
web/src/utils/index.ts
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue