2022-09-23 23:42:19 +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'
|
2022-09-23 23:42:19 +00:00
|
|
|
import { createSignal } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-23 23:42:19 +00:00
|
|
|
//export const locale = persistentAtom<string>('locale', 'ru')
|
|
|
|
export const [locale, setLocale] = createSignal('ru')
|
2022-09-09 11:53:35 +00:00
|
|
|
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)
|
2022-10-17 20:53:04 +00:00
|
|
|
export const toggleModal = (modalType) => modal.get() ? hideModal() : showModal(modalType)
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|