webapp/src/stores/ui.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-09-23 23:42:19 +00:00
import { createSignal } from 'solid-js'
2022-10-25 16:25:42 +00:00
import { useRouter } from './router'
2022-09-09 11:53:35 +00:00
2022-09-23 23:42:19 +00:00
export const [locale, setLocale] = createSignal('ru')
2022-10-25 16:25:42 +00:00
export type ModalType = 'auth' | 'subscribe' | 'feedback' | 'thank' | 'donate'
2022-09-09 11:53:35 +00:00
type WarnKind = 'error' | 'warn' | 'info'
export interface Warning {
body: string
kind: WarnKind
seen?: boolean
}
2022-10-25 16:25:42 +00:00
export const MODALS: Record<ModalType, ModalType> = {
auth: 'auth',
subscribe: 'subscribe',
feedback: 'feedback',
thank: 'thank',
donate: 'donate'
}
const [modal, setModal] = createSignal<ModalType | null>(null)
2022-09-09 11:53:35 +00:00
2022-10-25 16:25:42 +00:00
const [warnings, setWarnings] = createSignal<Warning[]>([])
2022-09-09 11:53:35 +00:00
2022-10-25 16:25:42 +00:00
export const showModal = (modalType: ModalType) => setModal(modalType)
export const hideModal = () => {
const { changeSearchParam } = useRouter()
changeSearchParam('modal', null, true)
changeSearchParam('mode', null, true)
setModal(null)
}
2022-10-17 20:53:04 +00:00
2022-10-25 16:25:42 +00:00
export const clearWarns = () => setWarnings([])
export const warn = (warning: Warning) => setWarnings([...warnings(), warning])
2022-09-09 11:53:35 +00:00
export const useWarningsStore = () => {
return {
2022-10-25 16:25:42 +00:00
warnings
2022-09-09 11:53:35 +00:00
}
}
export const useModalStore = () => {
return {
2022-10-25 16:25:42 +00:00
modal
2022-09-09 11:53:35 +00:00
}
}