-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add refetch content action - fixes #3
- Loading branch information
1 parent
4c95ada
commit e9831ca
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react' | ||
import { useMutation } from 'react-apollo-hooks' | ||
import { useSnackbar } from 'notistack' | ||
import { CircularProgress } from '@material-ui/core' | ||
import RefetchIcon from '@material-ui/icons/Refresh' | ||
import BaseAction from './Base' | ||
import { REFETCH_POST } from '../../../queries' | ||
|
||
const ActionRefetch = ({ url, _id, menuItem, handleClose }) => { | ||
const [loading, setLoading] = useState(false) | ||
const { enqueueSnackbar } = useSnackbar() | ||
const refetchPost = useMutation(REFETCH_POST, { | ||
variables: { post: _id, url }, | ||
}) | ||
|
||
const onClick = async e => { | ||
setLoading(true) | ||
const { | ||
data: { refetchPost: update }, | ||
error, | ||
} = await refetchPost() | ||
setLoading(false) | ||
if (error) { | ||
enqueueSnackbar('Error loading post content', { variant: 'error' }) | ||
} else if (!update || !update.content) { | ||
enqueueSnackbar('Could not parse post content', { variant: 'warning' }) | ||
} | ||
handleClose() | ||
} | ||
|
||
return ( | ||
<BaseAction | ||
title={'Refetch Full Post' + (loading ? ' (loading...)' : '')} | ||
onClick={onClick} | ||
icon={<RefetchIcon />} | ||
menuItem={menuItem} | ||
/> | ||
) | ||
} | ||
|
||
export default ActionRefetch |
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