Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename useGraphQL to useGraphQLClient #1255

Merged
Merged
57 changes: 15 additions & 42 deletions front/src/components/ArticleContributors.jsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,32 @@
import React, { useCallback } from 'react'
import { useMutate, useMutation } from '../hooks/graphql.js'
import { useArticleContributorActions } from '../hooks/contributor.js'

import styles from './articleContributors.module.scss'
import ContactSearch from './ContactSearch.jsx'
import {
addContributor,
removeContributor,
} from './ArticleContributors.graphql'
import { getArticleContributors } from './Article.graphql'

import { useToasts } from '@geist-ui/core'
import { useTranslation } from 'react-i18next'

export default function ArticleContributors({ article, contributors }) {
const mutation = useMutation()
const { setToast } = useToasts()
const { t } = useTranslation()
const articleId = article._id
const { mutate } = useMutate({
query: getArticleContributors,
variables: { articleId },
const { addContributor, removeContributor } = useArticleContributorActions({
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 },
})
await addContributor(userId)
setToast({
text: `Contributeur ${
user.displayName || user.username
} ajouté à l'article.`,
text: t('article.contributors.added', {
name: user.displayName || user.username,
}),
type: 'default',
})
await mutate(
{
article: {
contributors: response.article.addContributor.contributors,
},
},
{ revalidate: false }
)
} catch (err) {
setToast({
text: String(err),
Expand All @@ -51,24 +35,13 @@ export default function ArticleContributors({ article, contributors }) {
}
} else if (action === 'unselect') {
try {
const response = await mutation({
query: removeContributor,
variables: { userId, articleId },
})
await removeContributor(userId)
setToast({
text: `Contributeur ${
user.displayName || user.username
} supprimé de l'article.`,
type: 'warning',
text: t('article.contributors.removed', {
name: user.displayName || user.username,
}),
type: 'default',
})
await mutate(
{
article: {
contributors: response.article.removeContributor.contributors,
},
},
{ revalidate: false }
)
} catch (err) {
setToast({
text: String(err),
Expand Down
10 changes: 5 additions & 5 deletions front/src/components/ArticleCreate.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useToasts } from '@geist-ui/core'
import React, { useState, useCallback, useEffect, useRef } from 'react'
import React, { useState, useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'

import { useGraphQL } from '../helpers/graphQL'
import { useGraphQLClient } from '../helpers/graphQL'
import { createArticle } from './Articles.graphql'
import Field from './Field.jsx'
import { getTags } from './Tag.graphql'
Expand All @@ -30,7 +30,7 @@ export default function ArticleCreate({ onSubmit, workspaceId = null }) {
const { setToast } = useToasts()

const [tags, setTags] = useState([])
const runQuery = useGraphQL()
const { query } = useGraphQLClient()
const workspaces = useSelector((state) => state.activeUser.workspaces)

useEffect(() => {
Expand All @@ -39,7 +39,7 @@ export default function ArticleCreate({ onSubmit, workspaceId = null }) {
try {
const {
user: { tags },
} = await runQuery({ query: getTags, variables: {} })
} = await query({ query: getTags, variables: {} })
setTags(tags)
} catch (err) {
setToast({
Expand All @@ -54,7 +54,7 @@ export default function ArticleCreate({ onSubmit, workspaceId = null }) {
try {
event.preventDefault()
const createArticleInput = fromFormData(event.target)
const { createArticle: createdArticle } = await runQuery({
const { createArticle: createdArticle } = await query({
query: createArticle,
variables: { createArticleInput },
})
Expand Down
98 changes: 0 additions & 98 deletions front/src/components/Chapter.jsx

This file was deleted.

152 changes: 0 additions & 152 deletions front/src/components/Corpus.jsx

This file was deleted.

Loading
Loading