[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.6 KiB

import getConfig from 'src/config'
import {
NotificationType,
Form,
FormValue,
Config,
} from 'src/types'
export function notificationTypeToClassName(type: NotificationType): string {
switch (type) {
case NotificationType.Info: return 'is-info'
case NotificationType.Success: return 'is-success'
case NotificationType.Error: return 'is-danger'
case NotificationType.Welcome: return 'is-success'
}
}
export const objectToQuerystring = (obj: object) => Object.entries(obj).filter(([_, value]) => value !== undefined).map(([name, value]) => `${name}=${value}`).join('&')
export function setTitle(title: string, decorate: boolean = true) {
if (decorate) {
document.title = `${title} / Flexor`
} else {
document.title = title
}
}
export function valueFromForm<T extends FormValue>(form: Form, name: string): T | undefined
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue: T): T
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined {
const field = form[name]
if (!field) return defaultValue
if (field.value === undefined) return defaultValue
return field.value as T
}
export const urlForBlob = (config: Config, name: string) => `${config.blobUrl}${name}`
export async function urlForBlobAsync(name: string) {
const config = await getConfig()
return urlForBlob(config, name)
}