From 9d59c18886925c199114025e6e914b86f4cb6454 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Mon, 19 Oct 2020 07:17:39 +1100 Subject: [PATCH 1/2] route to ide from part edit --- web/src/components/EditPartCell/EditPartCell.js | 5 +---- web/src/components/PartForm/PartForm.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/web/src/components/EditPartCell/EditPartCell.js b/web/src/components/EditPartCell/EditPartCell.js index 3ba7344..70c8a68 100644 --- a/web/src/components/EditPartCell/EditPartCell.js +++ b/web/src/components/EditPartCell/EditPartCell.js @@ -29,14 +29,11 @@ export const Success = ({ part }) => { const { addMessage } = useFlash() const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, { onCompleted: () => { - navigate(routes.parts()) addMessage('Part updated.', { classes: 'rw-flash-success' }) }, }) - const onSave = (input, id) => { - updatePart({ variables: { id, input } }) - } + const onSave = (input, id) => updatePart({ variables: { id, input } }) return ( diff --git a/web/src/components/PartForm/PartForm.js b/web/src/components/PartForm/PartForm.js index 64d8fbb..17126e3 100644 --- a/web/src/components/PartForm/PartForm.js +++ b/web/src/components/PartForm/PartForm.js @@ -8,16 +8,24 @@ import { Submit, } from '@redwoodjs/forms' import { useState } from 'react'; +import { navigate, routes } from '@redwoodjs/router' import Editor from "rich-markdown-editor"; const PartForm = (props) => { const [description, setDescription] = useState(props?.part?.description) - const onSubmit = (data) => { - props.onSave({ + const onSubmit = async (data, e) => { + + await props.onSave({ ...data, description, }, props?.part?.id) + const shouldOpenIde = e?.nativeEvent?.submitter?.dataset?.openIde + if(shouldOpenIde) { + navigate(routes.partIde({id: props?.part?.id})) + } else { + navigate(routes.part({id: props?.part?.id})) + } } return ( @@ -80,6 +88,9 @@ const PartForm = (props) => { Save + + Save and open IDE + From 4db2195b1d2e4ad11c0e2f43963ad245b8e7320a Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Mon, 19 Oct 2020 07:21:54 +1100 Subject: [PATCH 2/2] Fix flash after new routing --- web/src/components/EditPartCell/EditPartCell.js | 10 ++-------- web/src/components/PartForm/PartForm.js | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/web/src/components/EditPartCell/EditPartCell.js b/web/src/components/EditPartCell/EditPartCell.js index 70c8a68..b434a62 100644 --- a/web/src/components/EditPartCell/EditPartCell.js +++ b/web/src/components/EditPartCell/EditPartCell.js @@ -1,5 +1,4 @@ -import { useMutation, useFlash } from '@redwoodjs/web' -import { navigate, routes } from '@redwoodjs/router' +import { useMutation } from '@redwoodjs/web' import PartForm from 'src/components/PartForm' export const QUERY = gql` @@ -26,12 +25,7 @@ const UPDATE_PART_MUTATION = gql` export const Loading = () =>
Loading...
export const Success = ({ part }) => { - const { addMessage } = useFlash() - const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, { - onCompleted: () => { - addMessage('Part updated.', { classes: 'rw-flash-success' }) - }, - }) + const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION) const onSave = (input, id) => updatePart({ variables: { id, input } }) diff --git a/web/src/components/PartForm/PartForm.js b/web/src/components/PartForm/PartForm.js index 17126e3..c300d8c 100644 --- a/web/src/components/PartForm/PartForm.js +++ b/web/src/components/PartForm/PartForm.js @@ -9,10 +9,12 @@ import { } from '@redwoodjs/forms' import { useState } from 'react'; import { navigate, routes } from '@redwoodjs/router' +import { useFlash } from '@redwoodjs/web' import Editor from "rich-markdown-editor"; const PartForm = (props) => { + const { addMessage } = useFlash() const [description, setDescription] = useState(props?.part?.description) const onSubmit = async (data, e) => { @@ -26,6 +28,7 @@ const PartForm = (props) => { } else { navigate(routes.part({id: props?.part?.id})) } + addMessage('Part updated.', { classes: 'rw-flash-success' }) } return (