v0.35.0
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useMutation, useFlash } from '@redwoodjs/web'
|
||||
import { useMutation } from '@redwoodjs/web'
|
||||
import { toast } from '@redwoodjs/web/toast'
|
||||
import { navigate, routes } from '@redwoodjs/router'
|
||||
import PostForm from 'src/components/PostForm'
|
||||
import PostForm from 'src/components/Post/PostForm'
|
||||
|
||||
export const QUERY = gql`
|
||||
query FIND_POST_BY_ID($id: Int!) {
|
||||
query FindPostById($id: Int!) {
|
||||
post: post(id: $id) {
|
||||
id
|
||||
title
|
||||
@@ -26,11 +27,10 @@ const UPDATE_POST_MUTATION = gql`
|
||||
export const Loading = () => <div>Loading...</div>
|
||||
|
||||
export const Success = ({ post }) => {
|
||||
const { addMessage } = useFlash()
|
||||
const [updatePost, { loading, error }] = useMutation(UPDATE_POST_MUTATION, {
|
||||
onCompleted: () => {
|
||||
toast.success('Post updated')
|
||||
navigate(routes.posts())
|
||||
addMessage('Post updated.', { classes: 'rw-flash-success' })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation, useFlash } from '@redwoodjs/web'
|
||||
import { useMutation } from '@redwoodjs/web'
|
||||
import { toast } from '@redwoodjs/web/toast'
|
||||
import { navigate, routes } from '@redwoodjs/router'
|
||||
import PostForm from 'src/components/PostForm'
|
||||
import PostForm from 'src/components/Post/PostForm'
|
||||
|
||||
const CREATE_POST_MUTATION = gql`
|
||||
mutation CreatePostMutation($input: CreatePostInput!) {
|
||||
@@ -11,11 +12,10 @@ const CREATE_POST_MUTATION = gql`
|
||||
`
|
||||
|
||||
const NewPost = () => {
|
||||
const { addMessage } = useFlash()
|
||||
const [createPost, { loading, error }] = useMutation(CREATE_POST_MUTATION, {
|
||||
onCompleted: () => {
|
||||
toast.success('Post created')
|
||||
navigate(routes.posts())
|
||||
addMessage('Post created.', { classes: 'rw-flash-success' })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMutation, useFlash } from '@redwoodjs/web'
|
||||
import { useMutation } from '@redwoodjs/web'
|
||||
import { toast } from '@redwoodjs/web/toast'
|
||||
import { Link, routes, navigate } from '@redwoodjs/router'
|
||||
|
||||
const DELETE_POST_MUTATION = gql`
|
||||
@@ -30,11 +31,10 @@ const checkboxInputTag = (checked) => {
|
||||
}
|
||||
|
||||
const Post = ({ post }) => {
|
||||
const { addMessage } = useFlash()
|
||||
const [deletePost] = useMutation(DELETE_POST_MUTATION, {
|
||||
onCompleted: () => {
|
||||
toast.success('Post deleted')
|
||||
navigate(routes.posts())
|
||||
addMessage('Post deleted.', { classes: 'rw-flash-success' })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Post from 'src/components/Post'
|
||||
import Post from 'src/components/Post/Post'
|
||||
|
||||
export const QUERY = gql`
|
||||
query FIND_POST_BY_ID($id: Int!) {
|
||||
query FindPostById($id: Int!) {
|
||||
post: post(id: $id) {
|
||||
id
|
||||
title
|
||||
@@ -7,6 +7,12 @@ import {
|
||||
Submit,
|
||||
} from '@redwoodjs/forms'
|
||||
|
||||
const formatDatetime = (value) => {
|
||||
if (value) {
|
||||
return value.replace(/:\d{2}\.\d{3}\w/, '')
|
||||
}
|
||||
}
|
||||
|
||||
const PostForm = (props) => {
|
||||
const onSubmit = (data) => {
|
||||
props.onSave(data, props?.post?.id)
|
||||
@@ -1,6 +1,9 @@
|
||||
import { useMutation, useFlash } from '@redwoodjs/web'
|
||||
import { useMutation } from '@redwoodjs/web'
|
||||
import { toast } from '@redwoodjs/web/toast'
|
||||
import { Link, routes } from '@redwoodjs/router'
|
||||
|
||||
import { QUERY } from 'src/components/Post/PostsCell'
|
||||
|
||||
const DELETE_POST_MUTATION = gql`
|
||||
mutation DeletePostMutation($id: Int!) {
|
||||
deletePost(id: $id) {
|
||||
@@ -36,16 +39,20 @@ const checkboxInputTag = (checked) => {
|
||||
}
|
||||
|
||||
const PostsList = ({ posts }) => {
|
||||
const { addMessage } = useFlash()
|
||||
const [deletePost] = useMutation(DELETE_POST_MUTATION, {
|
||||
onCompleted: () => {
|
||||
addMessage('Post deleted.', { classes: 'rw-flash-success' })
|
||||
toast.success('Post deleted')
|
||||
},
|
||||
// This refetches the query on the list page. Read more about other ways to
|
||||
// update the cache over here:
|
||||
// https://www.apollographql.com/docs/react/data/mutations/#making-all-other-cache-updates
|
||||
refetchQueries: [{ query: QUERY }],
|
||||
awaitRefetchQueries: true,
|
||||
})
|
||||
|
||||
const onDeleteClick = (id) => {
|
||||
if (confirm('Are you sure you want to delete post ' + id + '?')) {
|
||||
deletePost({ variables: { id }, refetchQueries: ['POSTS'] })
|
||||
deletePost({ variables: { id } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Link, routes } from '@redwoodjs/router'
|
||||
|
||||
import Posts from 'src/components/Posts'
|
||||
import Posts from 'src/components/Post/Posts'
|
||||
|
||||
export const QUERY = gql`
|
||||
query POSTS {
|
||||
Reference in New Issue
Block a user