Skip to content

Commit

Permalink
feat(ui): go back to the listing after article status update
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed May 8, 2019
1 parent cccd240 commit a1f3509
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ui/src/articles/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Props {

type AllProps = Props & RouteComponentProps<{ id: string }>

export default ({ category, match }: AllProps) => {
export default ({ category, match, history }: AllProps) => {
const { id } = match.params

let title = 'Articles to read'
Expand Down Expand Up @@ -56,7 +56,7 @@ export default ({ category, match }: AllProps) => {
<ArticleMenu article={article} />
</ArticleHeader>
<ArticleContent article={article} />
<MarkAsButton article={article} floating />
<MarkAsButton article={article} floating onSuccess={() => history.push(redirect)} />
</>
) : (
<ErrorPanel title="Not found">Article #{id} not found.</ErrorPanel>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/articles/components/MarkAsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { UpdateArticleStatus } from '../queries'
interface Props {
article: Article
floating?: boolean
onSuccess?: (article: Article) => void
}

type AllProps = Props & IMessageDispatchProps

export const MarkAsButton = (props: AllProps) => {
const { article, floating = false, showMessage } = props
const { article, floating = false, showMessage, onSuccess } = props

const [loading, setLoading] = useState(false)
const updateArticleStatusMutation = useMutation<UpdateArticleStatusRequest>(UpdateArticleStatus)
Expand All @@ -29,6 +30,7 @@ export const MarkAsButton = (props: AllProps) => {
// update: updateCacheAfterUpdateStatus
})
if (floating) setLoading(false)
if (onSuccess) onSuccess(article)
} catch (err) {
setLoading(false)
showMessage(getGQLError(err), true)
Expand Down

0 comments on commit a1f3509

Please sign in to comment.