40 lines
972 B
TypeScript
40 lines
972 B
TypeScript
|
import { persistentAtom } from '@nanostores/persistent'
|
||
|
import { action, atom } from 'nanostores'
|
||
|
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
|
||
|
}
|
||
|
}
|