-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: début de suppression de useMutate, runMutation et useMutation
- Loading branch information
1 parent
3b02562
commit a005d20
Showing
5 changed files
with
127 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useSelector } from 'react-redux' | ||
import { useSWRConfig } from 'swr' | ||
import { executeQuery } from '../helpers/graphQL.js' | ||
import { | ||
addContributor as addContributorQuery, | ||
removeContributor as removeContributorQuery, | ||
} from '../components/ArticleContributors.graphql' | ||
import { getArticleContributors } from '../components/Article.graphql' | ||
import { useSWRKey } from './graphql.js' | ||
|
||
export function useArticleContributorActions({ articleId }) { | ||
const { mutate } = useSWRConfig() | ||
const key = useSWRKey()({ query: getArticleContributors }) | ||
const sessionToken = useSelector((state) => state.sessionToken) | ||
const addContributor = async (contributorId) => { | ||
const response = await executeQuery({ | ||
sessionToken, | ||
query: addContributorQuery, | ||
variables: { userId: contributorId, articleId }, | ||
}) | ||
await mutate(key, async (_) => ({ | ||
article: { | ||
contributors: response.article.addContributor.contributors, | ||
}, | ||
})) | ||
} | ||
|
||
const removeContributor = async (contributorId) => { | ||
const response = await executeQuery({ | ||
sessionToken, | ||
query: removeContributorQuery, | ||
variables: { userId: contributorId, articleId }, | ||
}) | ||
await mutate(key, async (_) => ({ | ||
article: { | ||
contributors: response.article.removeContributor.contributors, | ||
}, | ||
})) | ||
} | ||
|
||
return { | ||
addContributor, | ||
removeContributor, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters