From d39872281e5d7a22ae5a3d4a368deb980694680f Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 5 Feb 2024 22:05:49 +0300 Subject: [PATCH] maintopic-limit-hotfix --- .lintstagedrc | 2 +- package-lock.json | 2 +- public/locales/en/translation.json | 1 + public/locales/ru/translation.json | 1 + src/components/Draft/Draft.tsx | 6 +++++- src/components/Editor/Panel/Panel.tsx | 6 ++++-- src/components/Nav/HeaderAuth.tsx | 6 ++++-- src/components/Views/PublishSettings/PublishSettings.tsx | 9 ++++++++- 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.lintstagedrc b/.lintstagedrc index e293187e..a3359680 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,5 +1,5 @@ { "*.{js,ts,cjs,mjs,d.mts,jsx,tsx,json,jsonc,scss,css}": [ - "npm run check" + "npx @biomejs/biome check ./src && tsc" ] } diff --git a/package-lock.json b/package-lock.json index dd85c875..bf14efef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ }, "devDependencies": { "@babel/core": "7.23.3", - "@biomejs/biome": "1.5.3", + "@biomejs/biome": "^1.5.3", "@graphql-codegen/cli": "5.0.0", "@graphql-codegen/typescript": "4.0.1", "@graphql-codegen/typescript-operations": "4.0.1", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index bdf6d55f..79653771 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -281,6 +281,7 @@ "Please enter password": "Please enter a password", "Please enter password again": "Please enter password again", "Please, confirm email": "Please confirm email", + "Please, set the main topic first": "Please, set the main topic first", "Podcasts": "Podcasts", "Poetry": "Poetry", "Popular": "Popular", diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index 541002ad..afb004de 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -295,6 +295,7 @@ "Please enter password": "Пожалуйста, введите пароль", "Please enter password again": "Пожалуйста, введите пароль ещё рез", "Please, confirm email": "Пожалуйста, подтвердите электронную почту", + "Please, set the main topic first": "Пожалуйста, сначала выберите главную тему", "Podcasts": "Подкасты", "Poetry": "Поэзия", "Popular": "Популярное", diff --git a/src/components/Draft/Draft.tsx b/src/components/Draft/Draft.tsx index 5c599fd1..cfbc9b0c 100644 --- a/src/components/Draft/Draft.tsx +++ b/src/components/Draft/Draft.tsx @@ -25,7 +25,11 @@ export const Draft = (props: Props) => { const handlePublishLinkClick = (e) => { e.preventDefault() - props.onPublish(props.shout) + if (props.shout.main_topic) { + props.onPublish(props.shout) + } else { + showSnackbar({ body: t('Please, set the main topic first') }) + } } const handleDeleteLinkClick = async (e) => { diff --git a/src/components/Editor/Panel/Panel.tsx b/src/components/Editor/Panel/Panel.tsx index 1fc98019..c6503473 100644 --- a/src/components/Editor/Panel/Panel.tsx +++ b/src/components/Editor/Panel/Panel.tsx @@ -14,6 +14,7 @@ import { Button } from '../../_shared/Button' import { DarkModeToggle } from '../../_shared/DarkModeToggle' import { Icon } from '../../_shared/Icon' +import { useSnackbar } from '../../../context/snackbar' import styles from './Panel.module.scss' const typograf = new Typograf({ locale: ['ru', 'en-US'] }) @@ -46,9 +47,10 @@ export const Panel = (props: Props) => { const handleSaveClick = () => { saveShout(form) } - + const { showSnackbar } = useSnackbar() const handlePublishClick = () => { - publishShout(form) + if (form.mainTopic) publishShout(form) + else showSnackbar({ body: t('Please, set the main topic first') }) } const html = useEditorHTML(() => editorRef.current()) diff --git a/src/components/Nav/HeaderAuth.tsx b/src/components/Nav/HeaderAuth.tsx index 286d4e6a..1d7851ab 100644 --- a/src/components/Nav/HeaderAuth.tsx +++ b/src/components/Nav/HeaderAuth.tsx @@ -16,6 +16,7 @@ import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient' import { ProfilePopup } from './ProfilePopup' +import { useSnackbar } from '../../context/snackbar' import styles from './Header/Header.module.scss' type Props = { @@ -62,9 +63,10 @@ export const HeaderAuth = (props: Props) => { const handleSaveButtonClick = () => { saveShout(form) } - + const { showSnackbar } = useSnackbar() const handlePublishButtonClick = () => { - publishShout(form) + if (form.mainTopic) publishShout(form) + else showSnackbar({ body: t('Please, set the main topic first') }) } const [width, setWidth] = createSignal(0) diff --git a/src/components/Views/PublishSettings/PublishSettings.tsx b/src/components/Views/PublishSettings/PublishSettings.tsx index da1ae8d7..7bc52d56 100644 --- a/src/components/Views/PublishSettings/PublishSettings.tsx +++ b/src/components/Views/PublishSettings/PublishSettings.tsx @@ -17,6 +17,7 @@ import { Button } from '../../_shared/Button' import { Icon } from '../../_shared/Icon' import { Image } from '../../_shared/Image' +import { useSnackbar } from '../../../context/snackbar' import stylesBeside from '../../Feed/Beside.module.scss' import styles from './PublishSettings.module.scss' @@ -53,6 +54,7 @@ export const PublishSettings = (props: Props) => { const { t } = useLocalize() const { author } = useSession() const { sortedTopics } = useTopicsStore() + const { showSnackbar } = useSnackbar() const [topics, setTopics] = createSignal(sortedTopics()) const composeDescription = () => { @@ -124,7 +126,12 @@ export const PublishSettings = (props: Props) => { handleBackClick() } const handlePublishSubmit = () => { - publishShout({ ...props.form, ...settingsForm }) + const shoutData = { ...props.form, ...settingsForm } + if (!shoutData?.mainTopic) { + showSnackbar({ body: t('Please, set the main topic first') }) + } else { + publishShout(shoutData) + } } const handleSaveDraft = () => { saveShout({ ...props.form, ...settingsForm })