Get parts on profile to update when user saves a new part

This commit is contained in:
Kurt Hutten
2020-12-30 12:45:47 +11:00
parent fff0956746
commit 62b26b969e
7 changed files with 55 additions and 33 deletions

View File

@@ -26,9 +26,9 @@ const UPDATE_USER_MUTATION = gql`
}
`
export const Loading = () => <div>Loading...</div>
export const Loading = () => <div className="h-screen">Loading...</div>
export const Empty = () => <div>Empty</div>
export const Empty = () => <div className="h-full">Empty</div>
export const Failure = ({ error }) => <div>Error: {error.message}</div>

View File

@@ -1,6 +1,8 @@
import { useMutation, useFlash } from '@redwoodjs/web'
import { navigate, routes } from '@redwoodjs/router'
import IdeCascadeStudio from 'src/components/IdeCascadeStudio'
import { QUERY as UsersPartsQuery } from 'src/components/PartsOfUserCell'
import useUser from 'src/helpers/hooks/useUser'
export const QUERY = gql`
query FIND_PART_BY_USENAME_TITLE($partTitle: String!, $userName: String!) {
@@ -45,12 +47,19 @@ export const Empty = () => <div>Part not found</div>
export const Success = ({ part, refetch }) => {
const { addMessage } = useFlash()
const { user } = useUser()
const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
onCompleted: () => {
addMessage('Part updated.', { classes: 'rw-flash-success' })
},
})
const [forkPart] = useMutation(FORK_PART_MUTATION, {
refetchQueries: [
{
query: UsersPartsQuery,
variables: { userName: user?.userName },
},
],
onCompleted: ({ forkPart }) => {
navigate(
routes.ide({

View File

@@ -11,6 +11,8 @@ import ImageUploader from 'src/components/ImageUploader'
import Svg from '../Svg/Svg'
import LoginModal from 'src/components/LoginModal'
import { FORK_PART_MUTATION } from 'src/components/IdePartCell'
import { QUERY as UsersPartsQuery } from 'src/components/PartsOfUserCell'
import useUser from 'src/helpers/hooks/useUser'
const IdeToolbar = ({
canEdit,
@@ -27,9 +29,17 @@ const IdeToolbar = ({
const { isAuthenticated, currentUser } = useAuth()
const showForkButton = !(canEdit || isDraft)
const [title, setTitle] = useState('untitled-part')
const { user } = useUser()
const { addMessage } = useFlash()
const [forkPart] = useMutation(FORK_PART_MUTATION)
const [forkPart] = useMutation(FORK_PART_MUTATION, {
refetchQueries: [
{
query: UsersPartsQuery,
variables: { userName: userNamePart?.userName || user?.userName },
},
],
})
const handleClick = ({ event, whichPopup }) => {
setAnchorEl(event.currentTarget)
@@ -145,7 +155,7 @@ const IdeToolbar = ({
</span>
)}
</Button>
{isDraft && (
{isDraft && isAuthenticated && (
<div className="flex items-center">
<Button
iconName={'save'}

View File

@@ -97,9 +97,9 @@ const DELETE_PART_MUTATION = gql`
}
`
export const Loading = () => <div>Loading...</div>
export const Loading = () => <div className="h-screen">Loading...</div>
export const Empty = () => <div>Empty</div>
export const Empty = () => <div className="h-full">Empty</div>
export const Failure = ({ error }) => <div>Error: {error.message}</div>

View File

@@ -24,14 +24,7 @@ export const QUERY = gql`
export const Loading = () => <div>Loading...</div>
export const Empty = () => {
return (
<div className="rw-text-center">
{'No parts yet. '}
<Link to={routes.draftPart()} className="rw-link">
{'Create one?'}
</Link>
</div>
)
return <div className="rw-text-center">No parts yet.</div>
}
export const Success = ({