import { redirectPage } from '@nanostores/router' import { clsx } from 'clsx' import { createSignal, lazy, onMount, Show } from 'solid-js' import { createStore } from 'solid-js/store' import { ShoutForm, useEditorContext } from '../../../context/editor' import { useLocalize } from '../../../context/localize' import { useSession } from '../../../context/session' import { apiClient } from '../../../graphql/client/core' import { Topic } from '../../../graphql/schema/core.gen' import { UploadedFile } from '../../../pages/types' import { router } from '../../../stores/router' import { hideModal, showModal } from '../../../stores/ui' import { Button } from '../../_shared/Button' import { Icon } from '../../_shared/Icon' import { Image } from '../../_shared/Image' import { TopicSelect, UploadModalContent } from '../../Editor' import { Modal } from '../../Nav/Modal' import { EMPTY_TOPIC } from '../Edit' import styles from './PublishSettings.module.scss' import stylesBeside from '../../Feed/Beside.module.scss' const SimplifiedEditor = lazy(() => import('../../Editor/SimplifiedEditor')) const GrowingTextarea = lazy(() => import('../../_shared/GrowingTextarea/GrowingTextarea')) const DESCRIPTION_MAX_LENGTH = 400 type Props = { shoutId: number form: ShoutForm } const shorten = (str: string, maxLen: number) => { if (str.length <= maxLen) return str const result = str.slice(0, Math.max(0, str.lastIndexOf(' ', maxLen))).trim() return `${result}...` } export const PublishSettings = async (props: Props) => { const { t } = useLocalize() const { author } = useSession() const composeDescription = () => { if (!props.form.description) { const cleanFootnotes = props.form.body.replaceAll(/.*?<\/footnote>/g, '') const leadText = cleanFootnotes.replaceAll(/<\/?[^>]+(>|$)/gi, ' ') return shorten(leadText, DESCRIPTION_MAX_LENGTH).trim() } return props.form.description } const initialData: Partial = { coverImageUrl: props.form.coverImageUrl, mainTopic: props.form.mainTopic || EMPTY_TOPIC, slug: props.form.slug, title: props.form.title, subtitle: props.form.subtitle, description: composeDescription(), } const { formErrors, actions: { setForm, setFormErrors, saveShout, publishShout }, } = useEditorContext() const [settingsForm, setSettingsForm] = createStore(initialData) const [topics, setTopics] = createSignal(null) const handleUploadModalContentCloseSetCover = (image: UploadedFile) => { hideModal() setSettingsForm('coverImageUrl', image.url) } const handleDeleteCoverImage = () => { setSettingsForm('coverImageUrl', '') } const handleTopicSelectChange = (newSelectedTopics) => { if ( props.form.selectedTopics.length === 0 || newSelectedTopics.every((topic) => topic.id !== props.form.mainTopic.id) ) { setSettingsForm((prev) => { return { ...prev, mainTopic: newSelectedTopics[0], } }) } if (newSelectedTopics.length > 0) { setFormErrors('selectedTopics', '') } setForm('selectedTopics', newSelectedTopics) } onMount(async () => { const allTopics = await apiClient.getAllTopics() setTopics(allTopics) }) const handleBackClick = () => { redirectPage(router, 'edit', { shoutId: props.shoutId.toString(), }) } const handleCancelClick = () => { setSettingsForm(initialData) handleBackClick() } const handlePublishSubmit = () => { publishShout({ ...props.form, ...settingsForm }) } const handleSaveDraft = () => { saveShout({ ...props.form, ...settingsForm }) } return (

{t('Publish Settings')}

{t('Material card')}

{initialData.title}
{settingsForm.mainTopic.title}
{settingsForm.title}
{settingsForm.subtitle}
{author()?.name}

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

setSettingsForm('title', value)} allowEnterKey={false} maxLength={100} /> setSettingsForm('subtitle', value)} allowEnterKey={false} maxLength={100} /> setForm('description', value)} maxLength={DESCRIPTION_MAX_LENGTH} />

{t('Slug')}

{t('Topics')}

{t( 'Add a few topics so that the reader knows what your content is about and can find it on pages of topics that interest them. Topics can be swapped, the first topic becomes the title', )}

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

Соавторы

*/} {/*

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

*/} {/*
*/} {/*
*/} {/* */} {/* */} {/*
*/} {/* */} {/*
*/} {/*
*/} {/*
Михаил Драбкин
*/} {/*
*/} {/* */} {/*
*/} {/*
*/}
handleUploadModalContentCloseSetCover(value)} />
) }