Skip to content

Commit

Permalink
Add refetch content action - fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcodes committed Jun 20, 2019
1 parent 4c95ada commit e9831ca
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/components/Post/Actions/Refetch.js
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
9 changes: 9 additions & 0 deletions src/components/Post/Actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ActionMarkRead from './MarkRead'
import ActionRemove from './Remove'
import ActionMute from './Mute'
import ActionBlock from './Block'
import ActionRefetch from './Refetch'
import style from './style'

const TogetherCardActions = ({
Expand Down Expand Up @@ -66,6 +67,14 @@ const TogetherCardActions = ({
{shownActions.includes('consoleLog') && (
<ActionConsoleLog post={post} menuItem />
)}
{shownActions.includes('refetch') && (
<ActionRefetch
_id={post._id}
url={post.url}
handleClose={() => setAnchorEl(null)}
menuItem
/>
)}
{post._id && shownActions.includes('remove') && (
<ActionRemove _id={post._id} channel={channelUid} menuItem />
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const TogetherCard = ({
shownActions = ['consoleLog', 'markRead', 'remove']
if (item.url) {
shownActions.push('view')
shownActions.push('refetch')
}
if (item.url && !item['likeOf'] && !item['repostOf']) {
shownActions.push('like', 'repost', 'reply')
Expand Down

0 comments on commit e9831ca

Please sign in to comment.