2024-07-03 21:25:03 +00:00
|
|
|
import { useNavigate } from '@solidjs/router'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-07-15 22:57:44 +00:00
|
|
|
import { For } from 'solid-js'
|
2024-07-03 21:25:03 +00:00
|
|
|
import { AuthGuard } from '~/components/AuthGuard'
|
|
|
|
import { Button } from '~/components/_shared/Button'
|
|
|
|
import { Icon } from '~/components/_shared/Icon'
|
|
|
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
|
|
|
import { useGraphQL } from '~/context/graphql'
|
|
|
|
import { useLocalize } from '~/context/localize'
|
2024-07-18 09:22:28 +00:00
|
|
|
import { useSnackbar } from '~/context/ui'
|
2024-07-03 21:25:03 +00:00
|
|
|
import createShoutMutation from '~/graphql/mutation/core/article-create'
|
2024-07-03 21:39:29 +00:00
|
|
|
import styles from '~/styles/Create.module.scss'
|
2024-07-03 21:25:03 +00:00
|
|
|
import { LayoutType } from '~/types/common'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2024-07-03 21:25:03 +00:00
|
|
|
export default () => {
|
2024-07-09 09:13:13 +00:00
|
|
|
const { t } = useLocalize()
|
2024-07-03 21:25:03 +00:00
|
|
|
const client = useGraphQL()
|
2024-07-18 10:22:58 +00:00
|
|
|
const { showSnackbar } = useSnackbar()
|
2024-07-03 21:25:03 +00:00
|
|
|
const navigate = useNavigate()
|
|
|
|
const handleCreate = async (layout: LayoutType) => {
|
2024-07-18 09:22:28 +00:00
|
|
|
console.debug('[routes : edit/new] handling create click...')
|
2024-07-15 22:57:44 +00:00
|
|
|
const result = await client.mutation(createShoutMutation, { shout: { layout: layout } }).toPromise()
|
2024-07-03 21:25:03 +00:00
|
|
|
if (result) {
|
2024-07-18 09:22:28 +00:00
|
|
|
console.debug(result)
|
2024-07-18 10:22:58 +00:00
|
|
|
const { shout, error } = result.data.create_shout
|
|
|
|
if (error)
|
|
|
|
showSnackbar({
|
|
|
|
body: `${t('Error')}: ${t(error)}`,
|
|
|
|
type: 'error'
|
|
|
|
})
|
2024-07-03 21:25:03 +00:00
|
|
|
if (shout?.id) navigate(`/edit/${shout.id}`)
|
|
|
|
}
|
|
|
|
}
|
2023-02-17 09:21:02 +00:00
|
|
|
return (
|
2024-07-09 09:13:13 +00:00
|
|
|
<PageLayout
|
|
|
|
title={`${t('Discours')} :: ${t('Choose a post type')}`}
|
|
|
|
key="home"
|
|
|
|
desc="Participate in the Discours: share information, join the editorial team"
|
|
|
|
>
|
2023-09-21 11:38:22 +00:00
|
|
|
<AuthGuard>
|
|
|
|
<article class={clsx('wide-container', 'container--static-page', styles.Create)}>
|
|
|
|
<h1>{t('Choose a post type')}</h1>
|
|
|
|
<ul class={clsx('nodash', styles.list)}>
|
2024-07-15 22:57:44 +00:00
|
|
|
<For each={['Article', 'Literature', 'Image', 'Audio', 'Video']}>
|
|
|
|
{(layout: string) => (
|
2024-07-18 09:22:28 +00:00
|
|
|
<li onClick={() => handleCreate(layout.toLowerCase() as LayoutType)}>
|
|
|
|
<div class={styles.link}>
|
2024-07-15 22:57:44 +00:00
|
|
|
<Icon name={`create-${layout.toLowerCase()}`} class={styles.icon} />
|
|
|
|
<div>{t(layout)}</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
2023-09-21 11:38:22 +00:00
|
|
|
</ul>
|
2024-07-06 06:41:16 +00:00
|
|
|
<Button value={t('Back')} onClick={() => window?.history.back()} />
|
2023-09-21 11:38:22 +00:00
|
|
|
</article>
|
|
|
|
</AuthGuard>
|
2023-02-17 09:21:02 +00:00
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|