webapp/src/components/Views/Create.tsx

176 lines
7.2 KiB
TypeScript
Raw Normal View History

2023-03-23 17:15:50 +00:00
import { createSignal, lazy, onMount, Show, Suspense } from 'solid-js'
2023-02-17 09:21:02 +00:00
import { Loading } from '../_shared/Loading'
import { useLocalize } from '../../context/localize'
import { clsx } from 'clsx'
import styles from './Create.module.scss'
2023-03-13 12:26:25 +00:00
import { Title } from '@solidjs/meta'
2023-03-23 17:15:50 +00:00
import { createStore } from 'solid-js/store'
import type { ShoutInput, Topic } from '../../graphql/types.gen'
import { apiClient } from '../../utils/apiClient'
import { TopicSelect } from '../Editor/TopicSelect/TopicSelect'
2023-02-11 09:32:52 +00:00
2023-03-08 16:35:13 +00:00
const Editor = lazy(() => import('../Editor/Editor'))
2023-02-11 09:32:52 +00:00
2023-03-23 17:15:50 +00:00
type ShoutForm = {
slug: string
title: string
subtitle: string
topicSlugs: string[]
body: string
coverImageUrl: string
}
2022-11-01 19:27:43 +00:00
export const CreateView = () => {
2023-02-17 09:21:02 +00:00
const { t } = useLocalize()
2023-03-23 17:15:50 +00:00
const [topics, setTopics] = createSignal<Topic[]>(null)
const [form, setForm] = createStore<ShoutForm>({
slug: '',
title: '',
subtitle: '',
topicSlugs: [],
body: '',
coverImageUrl: ''
})
onMount(async () => {
const allTopics = await apiClient.getAllTopics()
setTopics(allTopics)
})
const handleFormSubmit = (e) => {
e.preventDefault()
}
2022-09-09 11:53:35 +00:00
return (
2023-03-13 12:26:25 +00:00
<>
<Title>{t('Write an article')}</Title>
<Suspense fallback={<Loading />}>
2023-03-23 17:15:50 +00:00
<form onSubmit={handleFormSubmit}>
2023-03-13 12:26:25 +00:00
<div class="wide-container">
<div class="shift-content">
<div class="row">
<div class="col-md-10 col-lg-9 col-xl-8">
2023-03-23 17:15:50 +00:00
<h4>Slug</h4>
<div class="pretty-form__item">
<input
type="text"
name="slug"
id="slug"
value={form.slug}
onChange={(e) => setForm('slug', e.currentTarget.value)}
/>
<label for="slug">Slug</label>
</div>
2023-03-13 12:26:25 +00:00
<h4>Заголовок</h4>
<div class="pretty-form__item">
<input
type="text"
2023-03-23 17:15:50 +00:00
name="title"
id="title"
2023-03-13 12:26:25 +00:00
placeholder="Придумайте заголовок вашей истории"
2023-03-23 17:15:50 +00:00
value={form.title}
onChange={(e) => setForm('title', e.currentTarget.value)}
2023-03-13 12:26:25 +00:00
/>
2023-03-23 17:15:50 +00:00
<label for="title">Придумайте заголовок вашей истории</label>
2023-03-13 12:26:25 +00:00
</div>
2023-03-13 12:26:25 +00:00
<h4>Подзаголовок</h4>
<div class="pretty-form__item">
2023-03-23 17:15:50 +00:00
<input
type="text"
name="subtitle"
id="subtitle"
placeholder="Подзаголовок"
value={form.subtitle}
onChange={(e) => setForm('subtitle', e.currentTarget.value)}
/>
<label for="subtitle">Подзаголовок</label>
2023-03-13 12:26:25 +00:00
</div>
2023-03-23 17:15:50 +00:00
<Editor onChange={(body) => setForm('body', body)} />
2023-03-13 12:26:25 +00:00
<h1>Настройки публикации</h1>
{/*<h4>Лид</h4>*/}
{/*<div class="pretty-form__item">*/}
{/* <textarea name="lead" id="lead" placeholder="Лид"></textarea>*/}
{/* <label for="lead">Лид</label>*/}
{/*</div>*/}
2023-03-13 12:26:25 +00:00
{/*<h4>Выбор сообщества</h4>*/}
{/*<p class="description">Сообщества можно перечислить через запятую</p>*/}
{/*<div class="pretty-form__item">*/}
{/* <input*/}
{/* type="text"*/}
{/* name="community"*/}
{/* id="community"*/}
{/* placeholder="Сообщества"*/}
{/* class="nolabel"*/}
{/* />*/}
{/*</div>*/}
2023-03-13 12:26:25 +00:00
<h4>Темы</h4>
2023-03-23 17:15:50 +00:00
{/*<p class="description">*/}
{/* Добавьте несколько тем, чтобы читатель знал, о&nbsp;чем ваш материал, и&nbsp;мог найти*/}
{/* его на&nbsp;страницах интересных ему тем. Темы можно менять местами, первая тема*/}
{/* становится заглавной*/}
{/*</p>*/}
<div class="pretty-form__item">
2023-03-23 17:15:50 +00:00
<Show when={topics()}>
<TopicSelect
topics={topics()}
onChange={(selectedTopicSlugs) => setForm('topicSlugs', selectedTopics)}
selectedTopicSlugs={form.topicSlugs}
/>
</Show>
{/*<input type="text" name="topics" id="topics" placeholder="Темы" class="nolabel" />*/}
</div>
2023-03-23 17:15:50 +00:00
{/*<h4>Соавторы</h4>*/}
{/*<p class="description">У каждого соавтора можно добавить роль</p>*/}
{/*<div class="pretty-form__item--with-button">*/}
{/* <div class="pretty-form__item">*/}
{/* <input type="text" name="authors" id="authors" placeholder="Введите имя или e-mail" />*/}
{/* <label for="authors">Введите имя или e-mail</label>*/}
{/* </div>*/}
{/* <button class="button button--submit">Добавить</button>*/}
{/*</div>*/}
2023-03-23 17:15:50 +00:00
{/*<div class="row">*/}
{/* <div class="col-md-6">Михаил Драбкин</div>*/}
{/* <div class="col-md-6">*/}
{/* <input type="text" name="coauthor" id="coauthor1" class="nolabel" />*/}
{/* </div>*/}
{/*</div>*/}
2023-03-13 12:26:25 +00:00
<h4>Карточка материала на&nbsp;главной</h4>
<p class="description">
Выберите заглавное изображение для статьи, тут сразу можно увидеть как карточка будет
выглядеть на&nbsp;главной странице
</p>
2023-03-13 12:26:25 +00:00
<div class={styles.articlePreview}></div>
<div class={styles.saveBlock}>
<p>
Проверьте ещё раз введённые данные, если всё верно, вы&nbsp;можете сохранить или
опубликовать ваш текст
</p>
2023-03-23 17:15:50 +00:00
{/*<button class={clsx('button button--outline', styles.button)}>Сохранить</button>*/}
<button type="submit" class={clsx('button button--submit', styles.button)}>
Опубликовать
</button>
2023-03-13 12:26:25 +00:00
</div>
</div>
</div>
</div>
</div>
2023-03-13 12:26:25 +00:00
</form>
</Suspense>
</>
2022-09-09 11:53:35 +00:00
)
}
2022-11-01 19:27:43 +00:00
export default CreateView