2023-06-14 17:19:30 +00:00
|
|
|
import type {
|
|
|
|
AuthModalSearchParams,
|
|
|
|
AuthModalSource,
|
2023-11-14 15:10:00 +00:00
|
|
|
ConfirmEmailSearchParams,
|
2023-06-14 17:19:30 +00:00
|
|
|
} from '../components/Nav/AuthModal/types'
|
2023-02-17 09:21:02 +00:00
|
|
|
import type { RootSearchParams } from '../pages/types'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-11-14 15:10:00 +00:00
|
|
|
import { createSignal } from 'solid-js'
|
|
|
|
|
|
|
|
import { useRouter } from './router'
|
|
|
|
|
2023-05-04 04:43:52 +00:00
|
|
|
export type ModalType =
|
|
|
|
| 'auth'
|
|
|
|
| 'subscribe'
|
|
|
|
| 'feedback'
|
|
|
|
| 'thank'
|
2023-07-31 21:24:41 +00:00
|
|
|
| 'confirm'
|
2023-05-04 04:43:52 +00:00
|
|
|
| 'donate'
|
|
|
|
| 'inviteToChat'
|
|
|
|
| 'uploadImage'
|
2023-08-28 11:48:54 +00:00
|
|
|
| 'simplifiedEditorUploadImage'
|
2023-05-11 11:43:14 +00:00
|
|
|
| 'uploadCoverImage'
|
2023-07-24 08:58:07 +00:00
|
|
|
| 'editorInsertLink'
|
2023-09-01 14:28:50 +00:00
|
|
|
| 'followers'
|
2023-09-16 06:26:19 +00:00
|
|
|
| 'following'
|
2023-11-02 19:21:51 +00:00
|
|
|
| 'search'
|
2023-12-20 16:06:42 +00:00
|
|
|
| 'inviteCoAuthors'
|
2024-01-05 19:31:28 +00:00
|
|
|
| 'share'
|
2023-05-11 11:43:14 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
export const MODALS: Record<ModalType, ModalType> = {
|
|
|
|
auth: 'auth',
|
|
|
|
subscribe: 'subscribe',
|
|
|
|
feedback: 'feedback',
|
|
|
|
thank: 'thank',
|
2023-07-31 21:24:41 +00:00
|
|
|
confirm: 'confirm',
|
2022-11-27 05:49:48 +00:00
|
|
|
donate: 'donate',
|
2023-05-04 04:43:52 +00:00
|
|
|
inviteToChat: 'inviteToChat',
|
2023-05-11 11:43:14 +00:00
|
|
|
uploadImage: 'uploadImage',
|
2023-08-28 11:48:54 +00:00
|
|
|
simplifiedEditorUploadImage: 'simplifiedEditorUploadImage',
|
2023-07-24 08:58:07 +00:00
|
|
|
uploadCoverImage: 'uploadCoverImage',
|
2023-08-28 11:48:54 +00:00
|
|
|
editorInsertLink: 'editorInsertLink',
|
2023-09-01 14:28:50 +00:00
|
|
|
followers: 'followers',
|
2023-11-02 19:21:51 +00:00
|
|
|
following: 'following',
|
2024-01-21 13:56:36 +00:00
|
|
|
search: 'search',
|
2023-12-20 16:06:42 +00:00
|
|
|
inviteCoAuthors: 'inviteCoAuthors',
|
2024-01-05 19:31:28 +00:00
|
|
|
share: 'share',
|
2022-10-25 16:25:42 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 17:16:07 +00:00
|
|
|
const [modal, setModal] = createSignal<ModalType>(null)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-12-20 08:07:57 +00:00
|
|
|
const { searchParams, changeSearchParams } = useRouter<
|
2023-06-14 17:19:30 +00:00
|
|
|
AuthModalSearchParams & ConfirmEmailSearchParams & RootSearchParams
|
|
|
|
>()
|
|
|
|
|
|
|
|
export const showModal = (modalType: ModalType, modalSource?: AuthModalSource) => {
|
|
|
|
if (modalSource) {
|
2023-12-20 08:07:57 +00:00
|
|
|
changeSearchParams({
|
2023-11-14 15:10:00 +00:00
|
|
|
source: modalSource,
|
2023-09-29 12:48:58 +00:00
|
|
|
})
|
2023-06-14 17:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setModal(modalType)
|
|
|
|
}
|
2022-11-13 19:35:57 +00:00
|
|
|
|
|
|
|
// TODO: find a better solution
|
2022-10-25 16:25:42 +00:00
|
|
|
export const hideModal = () => {
|
2023-09-29 12:48:58 +00:00
|
|
|
const newSearchParams: Partial<AuthModalSearchParams & ConfirmEmailSearchParams & RootSearchParams> = {
|
|
|
|
modal: null,
|
2023-11-14 15:10:00 +00:00
|
|
|
source: null,
|
2023-09-29 12:48:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
if (searchParams().modal === 'auth') {
|
|
|
|
if (searchParams().mode === 'confirm-email') {
|
2023-09-29 12:48:58 +00:00
|
|
|
newSearchParams.token = null
|
2022-11-13 19:35:57 +00:00
|
|
|
}
|
2023-09-29 12:48:58 +00:00
|
|
|
newSearchParams.mode = null
|
2022-11-13 19:35:57 +00:00
|
|
|
}
|
|
|
|
|
2023-12-20 08:07:57 +00:00
|
|
|
changeSearchParams(newSearchParams, true)
|
2022-11-13 19:35:57 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
setModal(null)
|
|
|
|
}
|
2022-10-17 20:53:04 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
export const useModalStore = () => {
|
|
|
|
return {
|
2023-11-14 15:10:00 +00:00
|
|
|
modal,
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
|
|
|
}
|