import { createMemo, createSignal, For, onCleanup, onMount, Show } from 'solid-js' import { useLocalize } from '../../context/localize' import { clsx } from 'clsx' import { Title } from '@solidjs/meta' import type { Shout, Topic } from '../../graphql/types.gen' import { apiClient } from '../../utils/apiClient' import { useRouter } from '../../stores/router' import { useEditorContext } from '../../context/editor' import { Editor, Panel, TopicSelect, UploadModalContent } from '../Editor' import { Icon } from '../_shared/Icon' import { Button } from '../_shared/Button' import styles from './Edit.module.scss' import { useSession } from '../../context/session' import { Modal } from '../Nav/Modal' import { hideModal, showModal } from '../../stores/ui' import { imageProxy } from '../../utils/imageProxy' import { GrowingTextarea } from '../_shared/GrowingTextarea' import { VideoUploader } from '../Editor/VideoUploader' import { VideoPlayer } from '../_shared/VideoPlayer' import { slugify } from '../../utils/slugify' type Props = { shout: Shout } const handleScrollTopButtonClick = (e) => { e.preventDefault() window.scrollTo({ top: 0, behavior: 'smooth' }) } const EMPTY_TOPIC: Topic = { id: -1, slug: '' } export const EditView = (props: Props) => { const { t } = useLocalize() const { user } = useSession() const [isScrolled, setIsScrolled] = createSignal(false) const [topics, setTopics] = createSignal(null) const [coverImage, setCoverImage] = createSignal(null) const [media, setMedia] = createSignal(props.shout.media) const { page } = useRouter() const { form, formErrors, actions: { setForm, setFormErrors } } = useEditorContext() const shoutTopics = props.shout.topics || [] setForm({ shoutId: props.shout.id, slug: props.shout.slug, title: props.shout.title, subtitle: props.shout.subtitle, selectedTopics: shoutTopics, mainTopic: shoutTopics.find((topic) => topic.slug === props.shout.mainTopic) || EMPTY_TOPIC, body: props.shout.body, coverImageUrl: props.shout.cover, media: media(), layout: props.shout.layout }) onMount(async () => { const allTopics = await apiClient.getAllTopics() setTopics(allTopics) }) onMount(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 0) } window.addEventListener('scroll', handleScroll, { passive: true }) onCleanup(() => { window.removeEventListener('scroll', handleScroll) }) }) const handleTitleInputChange = (value) => { setForm('title', value) setForm('slug', slugify(value)) if (value) { setFormErrors('title', '') } } const handleSlugInputChange = (e) => { const slug = e.currentTarget.value setForm('slug', slug) } const handleUploadModalContentCloseSetCover = (imgUrl: string) => { hideModal() setCoverImage(imageProxy(imgUrl)) setForm('coverImageUrl', imgUrl) } const handleDeleteCoverImage = () => { setForm('coverImageUrl', '') setCoverImage(null) } const handleTopicSelectChange = (newSelectedTopics) => { if (newSelectedTopics.length === 0) { setForm('mainTopic', EMPTY_TOPIC) } else if ( form.selectedTopics.length === 0 || newSelectedTopics.every((topic) => topic.id !== form.mainTopic.id) ) { setForm('mainTopic', newSelectedTopics[0]) } if (newSelectedTopics.length > 0) { setFormErrors('selectedTopics', '') } setForm('selectedTopics', newSelectedTopics) } const handleAddMedia = (data) => { setForm('media', JSON.stringify([data])) } return ( <>
{t('Write an article')}
handleTitleInputChange(value)} class={styles.titleInput} placeholder={t('Header')} initialValue={form.title} maxLength={100} />
{formErrors.title}
setForm('subtitle', value)} class={styles.subtitleInput} placeholder={t('Subheader')} initialValue={form.subtitle} maxLength={100} /> { handleAddMedia(data) }} /> } > {(mediaItem) => ( <> setMedia(null)} /> )} setForm('body', body)} />

{t('Publish Settings')}

Slug

{/*

Лид

*/} {/*
*/} {/* */} {/* */} {/*
*/} {/*

Выбор сообщества

*/} {/*

Сообщества можно перечислить через запятую

*/} {/*
*/} {/* */} {/*
*/}

Темы

{/*

*/} {/* Добавьте несколько тем, чтобы читатель знал, о чем ваш материал, и мог найти*/} {/* его на страницах интересных ему тем. Темы можно менять местами, первая тема*/} {/* становится заглавной*/} {/*

*/}
setForm('mainTopic', mainTopic)} mainTopic={form.mainTopic} />
{formErrors.selectedTopics}
{/*

Соавторы

*/} {/*

У каждого соавтора можно добавить роль

*/} {/*
*/} {/*
*/} {/* */} {/* */} {/*
*/} {/* */} {/*
*/} {/*
*/} {/*
Михаил Драбкин
*/} {/*
*/} {/* */} {/*
*/} {/*
*/}

{t('Material card')}

{t( 'Choose a title image for the article. You can immediately see how the publication card will look like.' )}

{form.title}
{form.title}
{form.subtitle}
{user().name}
handleUploadModalContentCloseSetCover(value)} /> ) } export default EditView