webapp/src/stores/ui.ts

40 lines
964 B
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import { persistentAtom } from '@nanostores/persistent'
2022-09-13 13:38:26 +00:00
import { atom } from 'nanostores'
2022-09-09 11:53:35 +00:00
import { useStore } from '@nanostores/solid'
export const locale = persistentAtom<string>('locale', 'ru')
export type ModalType = 'auth' | 'subscribe' | 'feedback' | 'share' | 'thank' | 'donate' | null
type WarnKind = 'error' | 'warn' | 'info'
export interface Warning {
body: string
kind: WarnKind
seen?: boolean
}
const modal = atom<ModalType>(null)
const warnings = atom<Warning[]>([])
export const showModal = (modalType: ModalType) => modal.set(modalType)
export const hideModal = () => modal.set(null)
export const clearWarns = () => warnings.set([])
export const warn = (warning: Warning) => warnings.set([...warnings.get(), warning])
export const useWarningsStore = () => {
const getWarnings = useStore(warnings)
return {
getWarnings
}
}
export const useModalStore = () => {
const getModal = useStore(modal)
return {
getModal
}
}