issues-95 get saving and forking to work

This commit is contained in:
Kurt Hutten
2020-11-14 19:44:40 +11:00
parent 7abdd87f03
commit 955f4c9e83
7 changed files with 82 additions and 24 deletions

View File

@@ -60,7 +60,18 @@ const IdeCascadeStudio = ({ part, saveCode, loading, error }) => {
<IdeToolbar
canEdit={canEdit}
isChanges={isChanges && !loading}
onSave={() => {}}
onSave={() => {
saveCode({
input: {
code,
title: part?.title,
userId: currentUser?.sub,
description: part?.description,
},
id: part.id,
isFork: !canEdit,
})
}}
onExport={(type) => threejsViewport[`saveShape${type}`]()}
/>
<div id="topnav" className="topnav hidden">

View File

@@ -26,6 +26,17 @@ const UPDATE_PART_MUTATION = gql`
}
}
`
const FORK_PART_MUTATION = gql`
mutation ForkPartMutation($input: CreatePartInput!) {
forkPart(input: $input) {
id
title
user {
userName
}
}
}
`
export const Loading = () => <div>Loading...</div>
@@ -39,10 +50,25 @@ export const Success = ({ part, refetch }) => {
addMessage('Part updated.', { classes: 'rw-flash-success' })
},
})
const [forkPart] = useMutation(FORK_PART_MUTATION, {
onCompleted: ({ forkPart }) => {
navigate(
routes.ide({
userName: forkPart?.user?.userName,
partTitle: forkPart?.title,
})
)
addMessage('Part Forked.', { classes: 'rw-flash-success' })
},
})
const saveCode = (input, id) => {
updatePart({ variables: { id, input } })
refetch()
const saveCode = ({ input, id, isFork }) => {
if (!isFork) {
updatePart({ variables: { id, input } })
refetch()
return
}
forkPart({ variables: { input } })
}
return (
<IdeCascadeStudio