diff --git a/web/src/components/Part2Cell/Part2Cell.js b/web/src/components/Part2Cell/Part2Cell.js index 3fd5a18..4dcff89 100644 --- a/web/src/components/Part2Cell/Part2Cell.js +++ b/web/src/components/Part2Cell/Part2Cell.js @@ -6,11 +6,11 @@ import PartProfile from 'src/components/PartProfile' export const QUERY = gql` query FIND_PART_BY_USERNAME_TITLE($userName: String!, $partTitle: String!) { userPart: userName(userName: $userName) { + id name userName bio image - id Part(partTitle: $partTitle) { id title @@ -25,6 +25,19 @@ export const QUERY = gql` } ` +const UPDATE_PART_MUTATION = gql` + mutation UpdatePartMutation($id: String!, $input: UpdatePartInput!) { + updatePart:updatePart(id: $id, input: $input) { + id + title + user { + id + userName + } + } + } +` + export const Loading = () =>
Loading...
export const Empty = () =>
Empty
@@ -32,5 +45,23 @@ export const Empty = () =>
Empty
export const Failure = ({ error }) =>
Error: {error.message}
export const Success = ({ userPart, variables: {isEditable} }) => { - return + const { addMessage } = useFlash() + const [updateUser, { loading, error }] = useMutation(UPDATE_PART_MUTATION, { + onCompleted: ({updatePart}) => { + navigate(routes.part2({userName: updatePart.user.userName, partTitle: updatePart.title})) + addMessage('Part updated.', { classes: 'rw-flash-success' }) + }, + }) + + const onSave = (id, input) => { + updateUser({ variables: { id, input } }) + } + + return } diff --git a/web/src/components/PartProfile/PartProfile.js b/web/src/components/PartProfile/PartProfile.js index e713235..8806ba5 100644 --- a/web/src/components/PartProfile/PartProfile.js +++ b/web/src/components/PartProfile/PartProfile.js @@ -1,22 +1,36 @@ -import {useState} from 'react' +import {useState, useEffect} from 'react' import Editor from "rich-markdown-editor"; +import { navigate, routes } from '@redwoodjs/router' import ImageUploader from 'src/components/ImageUploader' import Breadcrumb from 'src/components/Breadcrumb' import EmojiReaction from 'src/components/EmojiReaction' import Button from 'src/components/Button' -const PartProfile = ({userPart, isEditable}) => { +const PartProfile = ({userPart, isEditable, onSave, loading, error}) => { const part = userPart?.Part const [input, setInput] = useState({ title: part.title, mainImage: part.mainImage, description: part.description, }) - const hi = () => {} + const setProperty = (property, value) => setInput({ + ...input, + [property]: value, + }) + const onTitleChange = ({target}) => setProperty('title', target.value) + const onDescriptionChange = (description) => setProperty('description', description()) + const onImageUpload = ({cloudinaryPublicId}) => setProperty('mainImage', cloudinaryPublicId) + const onEditSaveClick = () => { + if (isEditable) { + onSave(part.id, input) + return + } + navigate(routes.editPart2({userName: userPart.userName, partTitle: part.title})) + } return ( <> -
+
{/* Side column */}