From a60e923aef9331d1b6c32c8f6d6efc0316cb6cbd Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Wed, 11 Dec 2024 13:59:17 +0100 Subject: [PATCH] chore: npm run lint:fix --- front/src/components/404.jsx | 6 +- front/src/components/Article.graphql | 24 +- front/src/components/Article.jsx | 409 ++++++++++------ .../components/ArticleContributors.graphql | 48 +- front/src/components/ArticleContributors.jsx | 111 +++-- front/src/components/ArticleCreate.jsx | 119 +++-- front/src/components/ArticlePreview.jsx | 30 +- front/src/components/ArticleSendCopy.jsx | 55 ++- front/src/components/ArticleStats.jsx | 20 +- front/src/components/ArticleTags.jsx | 60 ++- front/src/components/ArticleVersionLinks.jsx | 74 +-- front/src/components/Articles.graphql | 8 +- front/src/components/Articles.jsx | 399 ++++++++++------ front/src/components/Book.jsx | 111 +++-- front/src/components/Button.jsx | 28 +- front/src/components/Button.test.jsx | 6 +- front/src/components/Chapter.jsx | 62 ++- front/src/components/ContactItem.jsx | 102 ++-- front/src/components/ContactSearch.jsx | 241 ++++++---- .../src/components/ContactSearch.module.scss | 2 +- front/src/components/Contacts.graphql | 65 ++- front/src/components/Credentials.jsx | 62 +-- front/src/components/Credentials.test.jsx | 69 ++- front/src/components/Error.jsx | 4 +- front/src/components/ErrorMessageCard.jsx | 25 +- front/src/components/Export.jsx | 163 +++++-- front/src/components/Field.jsx | 47 +- front/src/components/Footer.jsx | 92 ++-- front/src/components/Form.jsx | 351 ++++++++------ front/src/components/Form.test.jsx | 4 +- front/src/components/Header.jsx | 118 +++-- front/src/components/Loading.jsx | 20 +- front/src/components/Login.jsx | 105 +++-- front/src/components/Modal.jsx | 18 +- front/src/components/NavTab.jsx | 30 +- front/src/components/Privacy.jsx | 2 +- front/src/components/PrivateRoute.jsx | 9 +- front/src/components/ReferenceTypeIcon.jsx | 14 +- front/src/components/Register.jsx | 68 ++- front/src/components/Select.jsx | 17 +- front/src/components/SelectCombobox.js | 20 +- front/src/components/SelectCombobox.jsx | 67 ++- front/src/components/SelectCombobox.test.js | 31 +- front/src/components/SelectWidget.jsx | 113 ++--- front/src/components/Tag.graphql | 77 +-- front/src/components/Tag.jsx | 34 +- front/src/components/TagCreate.jsx | 58 ++- front/src/components/TagCreate.module.scss | 2 +- front/src/components/TimeAgo.jsx | 10 +- front/src/components/UserInfos.jsx | 120 +++-- .../components/Write/ArticleEditorMenu.jsx | 52 +- .../Write/ArticleEditorMetadata.jsx | 71 ++- front/src/components/Write/Biblio.jsx | 22 +- front/src/components/Write/CompareSelect.jsx | 5 +- front/src/components/Write/CreateVersion.jsx | 129 ++--- front/src/components/Write/PreviewHtml.jsx | 23 +- front/src/components/Write/PreviewPaged.jsx | 33 +- .../components/Write/PreviewPaged.module.scss | 6 +- front/src/components/Write/Reference.jsx | 33 +- front/src/components/Write/ReferenceList.jsx | 41 +- front/src/components/Write/Sommaire.jsx | 67 ++- front/src/components/Write/Versions.jsx | 443 ++++++++++++------ front/src/components/Write/WorkingVersion.jsx | 210 ++++++--- front/src/components/Write/Write.graphql | 8 +- front/src/components/Write/Write.jsx | 194 +++++--- .../Write/articleEditorMenu.module.scss | 1 - .../Write/articleEditorMetadata.module.scss | 2 +- .../Write/bibliographe/Bibliographe.jsx | 33 +- .../Write/bibliographe/CitationsPanel.jsx | 235 ++++++---- .../Write/bibliographe/RawBibtexPanel.jsx | 49 +- .../Write/bibliographe/ZoteroPanel.jsx | 216 +++++---- .../bibliographe/bibliographe.module.scss | 9 +- .../Write/createVersion.module.scss | 2 - .../Write/metadata/isidoreAuthor.jsx | 49 +- .../Write/metadata/isidoreKeyword.jsx | 17 +- .../Write/providers/monaco/BibtexEditor.jsx | 42 +- .../Write/providers/monaco/CompareSelect.jsx | 29 +- .../Write/providers/monaco/DiffEditor.jsx | 59 ++- .../Write/providers/monaco/Editor.jsx | 56 ++- .../Write/providers/monaco/TextEditor.jsx | 92 ++-- .../Write/providers/monaco/YamlEditor.jsx | 44 +- .../Write/providers/monaco/support.js | 44 +- .../components/Write/reference.module.scss | 5 +- .../src/components/Write/sommaire.module.scss | 3 +- .../src/components/Write/versions.module.scss | 8 +- .../Write/workingVersion.module.scss | 24 +- front/src/components/Write/write.module.scss | 8 +- .../yamleditor/ArticleEditorMetadataForm.jsx | 25 +- front/src/components/article.module.scss | 11 +- .../src/components/articleCreate.module.scss | 4 +- front/src/components/articleStats.module.scss | 2 +- front/src/components/button.module.scss | 16 +- .../collaborative/CollaborativeEditor.jsx | 32 +- .../CollaborativeEditorArticleHeader.jsx | 144 ++++-- .../CollaborativeEditorStatus.jsx | 110 +++-- .../CollaborativeEditorWebSocketStatus.jsx | 23 +- .../CollaborativeEditorWriters.jsx | 33 +- .../CollaborativeSession.graphql | 24 +- .../CollaborativeSessionAction.jsx | 68 ++- .../CollaborativeSessionError.jsx | 23 +- .../collaborative/CollaborativeTextEditor.jsx | 171 ++++--- .../components/collaborative/collaborating.js | 31 +- front/src/components/corpus/Corpus.graphql | 119 ++--- front/src/components/corpus/Corpus.jsx | 123 +++-- .../components/corpus/CorpusArticleCard.jsx | 28 +- .../components/corpus/CorpusArticleItems.jsx | 68 ++- .../src/components/corpus/CorpusArticles.jsx | 64 ++- front/src/components/corpus/CorpusCreate.jsx | 72 +-- front/src/components/corpus/CorpusItem.jsx | 162 +++++-- .../components/corpus/CorpusMetadataModal.jsx | 68 ++- .../components/corpus/CorpusSelectItem.jsx | 37 +- .../corpus/CorpusSelectItem.module.scss | 2 +- .../components/corpus/CorpusSelectItems.jsx | 60 ++- front/src/components/corpus/CorpusUpdate.jsx | 69 +-- .../corpus/corpusArticleCard.module.scss | 2 +- .../components/corpus/corpusItem.module.scss | 4 +- front/src/components/credentials.module.scss | 8 +- front/src/components/export.module.scss | 4 +- front/src/components/feedback/InlineAlert.jsx | 12 +- front/src/components/field.module.scss | 57 ++- front/src/components/form.module.scss | 10 +- front/src/components/header.module.scss | 13 +- front/src/components/header/LanguagesIcon.jsx | 40 +- front/src/components/header/LanguagesMenu.jsx | 44 +- front/src/components/header/UserMenu.jsx | 93 ++-- front/src/components/header/UserMenuLink.jsx | 26 +- front/src/components/login.module.scss | 21 +- .../src/components/metadata/MetadataForm.jsx | 18 +- .../src/components/metadata/MetadataValues.js | 11 +- front/src/components/modal.module.scss | 2 +- front/src/components/solo/SoloSession.graphql | 34 +- .../src/components/solo/SoloSessionAction.jsx | 69 ++- front/src/components/tag.module.scss | 6 +- front/src/components/tag/TagsList.jsx | 98 ++-- front/src/components/tag/tagsList.module.scss | 1 - front/src/components/userInfos.module.scss | 3 +- .../components/workspace/CreateWorkspace.jsx | 15 +- .../components/workspace/WorkspaceItem.jsx | 244 ++++++---- .../components/workspace/WorkspaceLabel.jsx | 6 +- .../workspace/WorkspaceManageMembers.jsx | 148 +++--- .../workspace/WorkspaceMenuItem.jsx | 20 +- .../workspace/WorkspaceSelectItem.jsx | 48 +- .../workspace/WorkspaceSelectItem.module.scss | 6 +- .../workspace/WorkspaceSelectionItems.jsx | 52 +- front/src/components/workspace/Workspaces.jsx | 82 ++-- .../workspace/workspaceItem.module.scss | 2 +- front/src/contexts/CurrentUser.js | 2 +- front/src/contexts/CurrentWorkspace.js | 2 +- front/src/createReduxStore.js | 305 +++++++----- front/src/helpers/acquintances.js | 21 +- front/src/helpers/acquintances.test.js | 7 +- front/src/helpers/bibtex.js | 24 +- front/src/helpers/bibtex.test.js | 30 +- front/src/helpers/colors.js | 10 +- front/src/helpers/graphQL.js | 43 +- front/src/helpers/isidore.js | 8 +- front/src/helpers/preview.js | 9 +- front/src/helpers/preview.test.js | 4 +- front/src/helpers/userProfile.js | 19 +- front/src/helpers/validationEmail.js | 3 +- front/src/helpers/zotero.js | 40 +- front/src/helpers/zotero.test.js | 21 +- front/src/hooks/componentVisible.js | 2 +- front/src/hooks/graphql.js | 94 ++-- front/src/hooks/pandoc.js | 4 +- front/src/hooks/stylo-export.js | 70 ++- front/src/hooks/user.js | 2 +- front/src/hooks/workspace.js | 6 +- front/src/i18n.js | 10 +- front/src/index.jsx | 102 ++-- front/src/layouts/App.jsx | 18 +- front/src/schemas/README.md | 2 +- .../src/schemas/article-metadata.schema.json | 24 +- front/src/schemas/article-ui-schema.json | 71 +-- .../src/schemas/corpus-journal-ui-schema.json | 4 +- front/src/services/ArticleService.graphql | 20 +- front/src/services/ArticleService.js | 80 ++-- front/src/services/WorkspaceService.graphql | 1 - front/src/services/WorkspaceService.js | 34 +- front/src/stories/Button.story.jsx | 30 +- front/src/stories/Form.story.jsx | 10 +- front/src/stories/Story.jsx | 56 ++- front/src/stories/form-story-ui-schema.json | 11 +- front/src/stories/story.module.scss | 2 +- front/src/styles/defaults.scss | 20 +- front/src/styles/general.scss | 35 +- front/src/wdyr.js | 5 +- 187 files changed, 6366 insertions(+), 3777 deletions(-) diff --git a/front/src/components/404.jsx b/front/src/components/404.jsx index 2a54cf438..584109e57 100644 --- a/front/src/components/404.jsx +++ b/front/src/components/404.jsx @@ -4,7 +4,7 @@ import App from '../layouts/App' import styles from '../components/Write/write.module.scss' -export default function PageNotFound () { +export default function PageNotFound() { const location = useLocation() return ( @@ -12,7 +12,9 @@ export default function PageNotFound () {

Error 404

-

Page not found at {location.pathname}.

+

+ Page not found at {location.pathname}. +

diff --git a/front/src/components/Article.graphql b/front/src/components/Article.graphql index 64c774424..f9aa99005 100644 --- a/front/src/components/Article.graphql +++ b/front/src/components/Article.graphql @@ -46,9 +46,9 @@ query getArticleContributors($articleId: ID!) { } } -query deleteArticle ($article: ID!) { - article (article: $article) { - delete (dryRun: false) +query deleteArticle($article: ID!) { + article(article: $article) { + delete(dryRun: false) } } @@ -61,9 +61,9 @@ mutation duplicateArticle($user: ID, $article: ID!, $to: ID!) { } } -query addTags ($article: ID!, $tags: [ID]!) { - article (article: $article) { - addTags (tags: $tags) { +query addTags($article: ID!, $tags: [ID]!) { + article(article: $article) { + addTags(tags: $tags) { _id name color @@ -71,9 +71,9 @@ query addTags ($article: ID!, $tags: [ID]!) { } } -query removeTags ($article: ID!, $tags: [ID]!) { - article (article: $article) { - removeTags (tags: $tags) { +query removeTags($article: ID!, $tags: [ID]!) { + article(article: $article) { + removeTags(tags: $tags) { _id name color @@ -82,7 +82,7 @@ query removeTags ($article: ID!, $tags: [ID]!) { } query getArticleInfo($articleId: ID!) { - article (article: $articleId) { + article(article: $articleId) { title workingVersion { @@ -92,7 +92,7 @@ query getArticleInfo($articleId: ID!) { } query getArticleTags($articleId: ID!) { - article (article: $articleId) { + article(article: $articleId) { tags { _id name @@ -102,7 +102,7 @@ query getArticleTags($articleId: ID!) { } mutation startCollaborativeSession($articleId: ID!) { - article (articleId: $articleId) { + article(articleId: $articleId) { startCollaborativeSession { id } diff --git a/front/src/components/Article.jsx b/front/src/components/Article.jsx index c83577215..65641a240 100644 --- a/front/src/components/Article.jsx +++ b/front/src/components/Article.jsx @@ -1,9 +1,15 @@ import React, { useState, useCallback, useEffect, useMemo } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' -import { Link} from 'react-router-dom' +import { Link } from 'react-router-dom' import clsx from 'clsx' -import { Modal as GeistModal, Note, Spacer, useModal, useToasts } from '@geist-ui/core' +import { + Modal as GeistModal, + Note, + Spacer, + useModal, + useToasts, +} from '@geist-ui/core' import { useActiveWorkspace } from '../hooks/workspace.js' import styles from './article.module.scss' @@ -29,7 +35,7 @@ import { Printer, Send, Trash, - UserPlus + UserPlus, } from 'react-feather' import { @@ -50,45 +56,61 @@ import { useSelector } from 'react-redux' import ArticleContributors from './ArticleContributors.jsx' import ArticleSendCopy from './ArticleSendCopy.jsx' -export default function Article ({ article, onArticleUpdated, onArticleDeleted, onArticleCreated }) { - const activeUser = useSelector(state => state.activeUser) +export default function Article({ + article, + onArticleUpdated, + onArticleDeleted, + onArticleCreated, +}) { + const activeUser = useSelector((state) => state.activeUser) const articleId = useMemo(() => article._id, [article]) const activeWorkspace = useActiveWorkspace() - const activeWorkspaceId = useMemo(() => activeWorkspace?._id, [activeWorkspace]) + const activeWorkspaceId = useMemo( + () => activeWorkspace?._id, + [activeWorkspace] + ) - const { - data: contributorsQueryData, - error: contributorsError, - } = useGraphQL({ query: getArticleContributors, variables: { articleId } }, { - fallbackData: { - article - }, - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false - }) - const contributors = (contributorsQueryData?.article?.contributors || []).filter(c => c.user._id !== article.owner._id) - const { data: userTagsQueryData } = useGraphQL({ query: getTags, variables: {} }, { - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false - }) - const userTags = (userTagsQueryData?.user?.tags || []) - const { data: articleTagsQueryData } = useGraphQL({ query: getArticleTags, variables: { articleId } }, { - fallbackData: { - article - }, - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false - }) - const tags = (articleTagsQueryData?.article?.tags || []) + const { data: contributorsQueryData, error: contributorsError } = useGraphQL( + { query: getArticleContributors, variables: { articleId } }, + { + fallbackData: { + article, + }, + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + } + ) + const contributors = ( + contributorsQueryData?.article?.contributors || [] + ).filter((c) => c.user._id !== article.owner._id) + const { data: userTagsQueryData } = useGraphQL( + { query: getTags, variables: {} }, + { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + } + ) + const userTags = userTagsQueryData?.user?.tags || [] + const { data: articleTagsQueryData } = useGraphQL( + { query: getArticleTags, variables: { articleId } }, + { + fallbackData: { + article, + }, + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + } + ) + const tags = articleTagsQueryData?.article?.tags || [] const { t } = useTranslation() const { setToast } = useToasts() const { visible: deleteArticleVisible, setVisible: setDeleteArticleVisible, - bindings: deleteArticleModalBinding + bindings: deleteArticleModalBinding, } = useModal() const mutation = useMutation() @@ -107,52 +129,65 @@ export default function Article ({ article, onArticleUpdated, onArticleDeleted, if (contributorsError) { setToast({ type: 'error', - text: `Unable to load contributors: ${contributorsError.toString()}` + text: `Unable to load contributors: ${contributorsError.toString()}`, }) } }, [contributorsError]) - const toggleExpansion = useCallback((event) => { - if (!event.key || [' ', 'Enter'].includes(event.key)) { - setExpanded(!expanded) - } - }, [setExpanded, expanded]) + const toggleExpansion = useCallback( + (event) => { + if (!event.key || [' ', 'Enter'].includes(event.key)) { + setExpanded(!expanded) + } + }, + [setExpanded, expanded] + ) const duplicate = async () => { const duplicatedArticleQuery = await mutation({ query: duplicateArticle, - variables: { user: activeUser._id, to: activeUser._id, article: articleId } + variables: { + user: activeUser._id, + to: activeUser._id, + article: articleId, + }, }) onArticleCreated({ ...article, ...duplicatedArticleQuery.duplicateArticle, contributors: [], - versions: [] + versions: [], }) } const rename = async (e) => { e.preventDefault() - await mutation({ query: renameArticle, variables: { user: activeUser._id, article: articleId, title: newTitle } }) + await mutation({ + query: renameArticle, + variables: { user: activeUser._id, article: articleId, title: newTitle }, + }) onArticleUpdated({ ...article, - title: newTitle + title: newTitle, }) setRenaming(false) } const handleDeleteArticle = async () => { try { - await mutation({ query: deleteArticle, variables: { article: articleId } }) + await mutation({ + query: deleteArticle, + variables: { article: articleId }, + }) onArticleDeleted(article) setToast({ type: 'default', - text: t('article.delete.toastSuccess') + text: t('article.delete.toastSuccess'), }) } catch (err) { setToast({ type: 'error', - text: t('article.delete.toastError', {errMessage: err.message}) + text: t('article.delete.toastError', { errMessage: err.message }), }) } } @@ -165,172 +200,268 @@ export default function Article ({ article, onArticleUpdated, onArticleDeleted, setSharing(false) }, [setSharing]) - const handleArticleTagsUpdated = useCallback((event) => { - onArticleUpdated({ - ...article, - tags: event.updatedTags - }) - }, [article]) + const handleArticleTagsUpdated = useCallback( + (event) => { + onArticleUpdated({ + ...article, + tags: event.updatedTags, + }) + }, + [article] + ) return (
{exporting && ( setExporting(false)}> - + )}

{t('article.shareModal.title')}

- {t('article.shareModal.description')} + + {t('article.shareModal.description')} + - + - {t('modal.close.text')} + + {t('modal.close.text')} +

{t('article.shareModal.title')}

- {t('article.shareModal.description')} + + {t('article.shareModal.description')} + - + - {t('modal.close.text')} + + {t('modal.close.text')} +

{t('article.sendCopyModal.title')}

- {t('article.sendCopyModal.description')}{' '} - + + {t('article.sendCopyModal.description')}{' '} + + + + - + - {t('modal.close.text')} + + {t('modal.close.text')} +
{!renaming && (

- {expanded ? : } + {expanded ? : } {article.title} - +

)} {renaming && ( -
rename(e)}> - setNewTitle(e.target.value)} placeholder="Article Title"/> - - )}

{tags.map((t) => ( - + ))} - {t('article.by.text')} {article.owner.displayName} - {contributors?.length > 0 && (, {contributors.map(c => c.user.displayName || c.user.username).join(', ')})} - + {t('article.by.text')}{' '} + {article.owner.displayName} + {contributors?.length > 0 && ( + + + ,{' '} + {contributors + .map((c) => c.user.displayName || c.user.username) + .join(', ')} + + + )} +

{expanded && (
- - - {userTags.length > 0 && <> -

{t('article.tags.title')}

-
- -
- - } + + + {userTags.length > 0 && ( + <> +

{t('article.tags.title')}

+
+ +
+ + )}

{t('article.workspaces.title')}

    - +

{t('article.corpus.title')}

    - +
)} @@ -343,11 +474,11 @@ Article.propTypes = { article: PropTypes.shape({ title: PropTypes.string, owner: PropTypes.shape({ - displayName: PropTypes.string + displayName: PropTypes.string, }), collaborativeSession: PropTypes.object, soloSession: PropTypes.object, updatedAt: PropTypes.string, - _id: PropTypes.string - }) + _id: PropTypes.string, + }), } diff --git a/front/src/components/ArticleContributors.graphql b/front/src/components/ArticleContributors.graphql index 4e6ac9b7f..66566b888 100644 --- a/front/src/components/ArticleContributors.graphql +++ b/front/src/components/ArticleContributors.graphql @@ -1,33 +1,33 @@ query addContributor($userId: ID!, $articleId: ID!) { - article(article: $articleId) { - addContributor(userId: $userId) { - _id - contributors { - roles - user { - _id - displayName - username - email - } - } + article(article: $articleId) { + addContributor(userId: $userId) { + _id + contributors { + roles + user { + _id + displayName + username + email } + } } + } } query removeContributor($userId: ID!, $articleId: ID!) { - article(article: $articleId) { - removeContributor(userId: $userId) { - _id - contributors { - roles - user { - _id - displayName - username - email - } - } + article(article: $articleId) { + removeContributor(userId: $userId) { + _id + contributors { + roles + user { + _id + displayName + username + email } + } } + } } diff --git a/front/src/components/ArticleContributors.jsx b/front/src/components/ArticleContributors.jsx index 6fcf1a850..ec49b55e5 100644 --- a/front/src/components/ArticleContributors.jsx +++ b/front/src/components/ArticleContributors.jsx @@ -3,57 +3,82 @@ import { useMutate, useMutation } from '../hooks/graphql.js' import styles from './articleContributors.module.scss' import ContactSearch from './ContactSearch.jsx' -import { addContributor, removeContributor } from './ArticleContributors.graphql' +import { + addContributor, + removeContributor, +} from './ArticleContributors.graphql' import { getArticleContributors } from './Article.graphql' import { useToasts } from '@geist-ui/core' -export default function ArticleContributors ({ article, contributors }) { +export default function ArticleContributors({ article, contributors }) { const mutation = useMutation() const { setToast } = useToasts() const articleId = article._id - const { mutate } = useMutate({ query: getArticleContributors, variables: { articleId } }) + const { mutate } = useMutate({ + query: getArticleContributors, + variables: { articleId }, + }) - const handleUserUpdated = useCallback(async ({ user, action }) => { - const { _id: userId } = user - if (action === 'select') { - // add contributor - try { - const response = await mutation({ query: addContributor, variables: { userId, articleId } }) - setToast({ - text: `Contributeur ${user.displayName || user.username} ajouté à l'article.`, - type: 'default', - }) - await mutate({ - article: { - contributors: response.article.addContributor.contributors - } - }, { revalidate: false }) - } catch (err) { - setToast({ - text: String(err), - type: 'error' - }) + const handleUserUpdated = useCallback( + async ({ user, action }) => { + const { _id: userId } = user + if (action === 'select') { + // add contributor + try { + const response = await mutation({ + query: addContributor, + variables: { userId, articleId }, + }) + setToast({ + text: `Contributeur ${ + user.displayName || user.username + } ajouté à l'article.`, + type: 'default', + }) + await mutate( + { + article: { + contributors: response.article.addContributor.contributors, + }, + }, + { revalidate: false } + ) + } catch (err) { + setToast({ + text: String(err), + type: 'error', + }) + } + } else if (action === 'unselect') { + try { + const response = await mutation({ + query: removeContributor, + variables: { userId, articleId }, + }) + setToast({ + text: `Contributeur ${ + user.displayName || user.username + } supprimé de l'article.`, + type: 'warning', + }) + await mutate( + { + article: { + contributors: response.article.removeContributor.contributors, + }, + }, + { revalidate: false } + ) + } catch (err) { + setToast({ + text: String(err), + type: 'error', + }) + } } - } else if (action === 'unselect') { - try { - const response = await mutation({ query: removeContributor, variables: { userId, articleId } }) - setToast({ - text: `Contributeur ${user.displayName || user.username} supprimé de l'article.`, - type: 'warning', - }) - await mutate({ - article: { - contributors: response.article.removeContributor.contributors - } - }, { revalidate: false }) - } catch (err) { - setToast({ - text: String(err), - type: 'error' - }) - } - } - }, [articleId]) + }, + [articleId] + ) return (
diff --git a/front/src/components/ArticleCreate.jsx b/front/src/components/ArticleCreate.jsx index eba807a9a..0163905e0 100644 --- a/front/src/components/ArticleCreate.jsx +++ b/front/src/components/ArticleCreate.jsx @@ -12,8 +12,7 @@ import styles from './articleCreate.module.scss' import ArticleTag from './Tag' import { useCurrentUser } from '../contexts/CurrentUser' - -export default function ArticleCreate ({ onSubmit }) { +export default function ArticleCreate({ onSubmit }) { const { t } = useTranslation() const { setToast } = useToasts() const { state: title, bindings: titleBindings } = useInput('') @@ -31,47 +30,58 @@ export default function ArticleCreate ({ onSubmit }) { useEffect(() => { // Self invoking async function - (async () => { + ;(async () => { try { - const { user: { tags } } = await runQuery({ query: getTags, variables: {} }) + const { + user: { tags }, + } = await runQuery({ query: getTags, variables: {} }) setTags(tags) } catch (err) { setToast({ - text: t('article.getTags.error', {errMessage: err }), - type: 'error' + text: t('article.getTags.error', { errMessage: err }), + type: 'error', }) } })() }, []) - const handleSubmit = useCallback(async (event) => { - try { - event.preventDefault() - const result = await runQuery({ query: createArticle, variables: { user: activeUser._id, title, tags: selectedTagIds } }) - const createdArticle = { - ...result.createArticle, - tags: result.createArticle.addTags + const handleSubmit = useCallback( + async (event) => { + try { + event.preventDefault() + const result = await runQuery({ + query: createArticle, + variables: { user: activeUser._id, title, tags: selectedTagIds }, + }) + const createdArticle = { + ...result.createArticle, + tags: result.createArticle.addTags, + } + delete createdArticle.addTags + onSubmit(createdArticle) + setToast({ + text: t('article.create.successNotification'), + type: 'default', + }) + } catch (err) { + setToast({ + text: t('article.create.errorNotification', { errMessage: err }), + type: 'error', + }) } - delete createdArticle.addTags - onSubmit(createdArticle) - setToast({ - text: t('article.create.successNotification'), - type: 'default' - }) - } catch (err) { - setToast({ - text: t('article.create.errorNotification', {errMessage: err}), - type: 'error' - }) - } - }, [title, selectedTagIds]) + }, + [title, selectedTagIds] + ) - const toggleCheckedTags = useCallback(event => { - const _id = etv(event) - selectedTagIds.includes(_id) - ? setSelectedtagIds(selectedTagIds.filter(tagId => tagId !== _id)) - : setSelectedtagIds([...selectedTagIds, _id]) - }, [selectedTagIds]) + const toggleCheckedTags = useCallback( + (event) => { + const _id = etv(event) + selectedTagIds.includes(_id) + ? setSelectedtagIds(selectedTagIds.filter((tagId) => tagId !== _id)) + : setSelectedtagIds([...selectedTagIds, _id]) + }, + [selectedTagIds] + ) return (
@@ -83,28 +93,33 @@ export default function ArticleCreate ({ onSubmit }) { type="text" className={styles.titleField} /> - {tags.length > 0 &&
- -
    - {tags.map((t) => ( -
  • - -
  • - ))} -
-
} + {tags.length > 0 && ( +
+ +
    + {tags.map((t) => ( +
  • + +
  • + ))} +
+
+ )}
  • -
diff --git a/front/src/components/ArticlePreview.jsx b/front/src/components/ArticlePreview.jsx index d5d367b52..1f5bce5c3 100644 --- a/front/src/components/ArticlePreview.jsx +++ b/front/src/components/ArticlePreview.jsx @@ -7,26 +7,30 @@ import Loading from './Loading' export default function ArticlePreview() { const { id, version, bookId } = useParams() - const { exportEndpoint } = useSelector(state => state.applicationConfig) + const { exportEndpoint } = useSelector((state) => state.applicationConfig) const [isLoaded, setLoaded] = useState(false) const previewFrame = useRef() const url = bookId - ? (`${exportEndpoint}/api/v1/htmlBook/${bookId}?preview=true`) - : (version - ? `${exportEndpoint}/api/v1/htmlVersion/${version}?preview=true` - : `${exportEndpoint}/api/v1/htmlArticle/${id}?preview=true`) + ? `${exportEndpoint}/api/v1/htmlBook/${bookId}?preview=true` + : version + ? `${exportEndpoint}/api/v1/htmlVersion/${version}?preview=true` + : `${exportEndpoint}/api/v1/htmlArticle/${id}?preview=true` useEffect(() => { previewFrame.current.addEventListener('load', () => setLoaded(true)) }, []) - return <> - {!isLoaded && } - -