diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..8a1a375 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/web/src/cascade/* diff --git a/.vscode/settings.json b/.vscode/settings.json index 76d6767..8f3288b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,7 +17,9 @@ "./web/src/Routes.js", ], "cSpell.words": [ + "Initialised", "Uploader", + "initialise", "redwoodjs" ] } diff --git a/web/src/Routes.js b/web/src/Routes.js index 547071b..8a6d6e6 100644 --- a/web/src/Routes.js +++ b/web/src/Routes.js @@ -13,7 +13,6 @@ const Routes = () => { return ( - {/* */} {/* Ownership enforced routes */} @@ -24,7 +23,7 @@ const Routes = () => { - {/* */} + {/* GENERATED ROUTES BELOW, probably going to clean these up and delete most of them, but the CRUD functionality is useful for now */} {/* All private by default for safety and because the routes that are left after clean up will probably be admin pages */} diff --git a/web/src/assets/harold.jpg b/web/src/assets/harold.jpg deleted file mode 100644 index e25486c..0000000 Binary files a/web/src/assets/harold.jpg and /dev/null differ diff --git a/web/src/cascade b/web/src/cascade index e634591..37cea9e 160000 --- a/web/src/cascade +++ b/web/src/cascade @@ -1 +1 @@ -Subproject commit e634591e27dd41fec1638b278be3c298c6ab4b5a +Subproject commit 37cea9eeb230f78fb34da95f2543b8c6850606c5 diff --git a/web/src/pages/HomePage/HomePage.js b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js similarity index 56% rename from web/src/pages/HomePage/HomePage.js rename to web/src/components/IdeCascadeStudio/IdeCascadeStudio.js index ff000c9..5360e2c 100644 --- a/web/src/pages/HomePage/HomePage.js +++ b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js @@ -1,41 +1,57 @@ -import MainLayout from 'src/layouts/MainLayout' -// import BlogPostsCell from 'src/components/BlogPostsCell' +import { useMutation, useFlash } from '@redwoodjs/web' +import { Link, routes, navigate } from '@redwoodjs/router' import { initialize } from 'src/cascade/js/MainPage/CascadeMain' +import CascadeController from 'src/helpers/cascadeController' import { useEffect, useState } from 'react' -const starterCode = `// Welcome to Cascade Studio! Here are some useful functions: -// Translate(), Rotate(), Scale(), Union(), Difference(), Intersection() -// Box(), Sphere(), Cylinder(), Cone(), Text3D(), Polygon() -// Offset(), Extrude(), RotatedExtrude(), Revolve(), Pipe(), Loft(), -// FilletEdges(), ChamferEdges(), -// Slider(), Button(), Checkbox() - -// Uncomment and hover over them to see their apis - -let holeRadius = Slider("Radius", 30 , 20 , 40); - -let sphere = Sphere(50); -let cylinderZ = Cylinder(holeRadius, 200, true); -let cylinderY = Rotate([0,1,0], 90, Cylinder(holeRadius, 200, true)); -let cylinderX = Rotate([1,0,0], 90, Cylinder(holeRadius, 200, true)); - -Translate([0, 0, 50], Difference(sphere, [cylinderX, cylinderY, cylinderZ])); - -Translate([-100, 0, 100], Text3D("cadhub.xyz")); - -// Don't forget to push imported or oc-defined shapes into sceneShapes to add them to the workspace! +const DELETE_PART_MUTATION = gql` + mutation DeletePartMutation($id: Int!) { + deletePart(id: $id) { + id + } + } ` +const domNode = document.createElement('div').setAttribute('id', 'sickId') -const HomePage1 = () => { - const [code, setCode] = useState(starterCode) +const IdeCascadeStudio = ({ part, saveCode, loading, error }) => { + const [code, setCode] = useState(part.code) useEffect(() => { - const sickCallback = (code) => setCode(code) - new initialize(sickCallback, starterCode) + const onCodeChange = (code) => setCode(code) + CascadeController.initialise(onCodeChange, part.code, domNode) + const element = document.getElementById('cascade-container') + element.setAttribute('style', 'height: auto; display: block; opacity: 100%') // eslint-disable-line + return () => { + element.setAttribute('style', 'height: auto; display: none;') // eslint-disable-line + } }, []) + const hasChanges = code !== part.code + const { addMessage } = useFlash() + const [deletePart] = useMutation(DELETE_PART_MUTATION, { + onCompleted: () => { + // navigate(routes.parts()) + addMessage('Part deleted.', { classes: 'rw-flash-success' }) + }, + }) + + const onDeleteClick = (id) => { + if (confirm('Are you sure you want to delete part ' + id + '?')) { + deletePart({ variables: { id } }) + } + } + return ( - -
current code {code}
- + <> + -
+ ) } -const HomePage = () => { - return hi -} - -export default HomePage +export default IdeCascadeStudio diff --git a/web/src/components/IdeCascadeStudio/IdeCascadeStudio.stories.js b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.stories.js new file mode 100644 index 0000000..6e94eef --- /dev/null +++ b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.stories.js @@ -0,0 +1,7 @@ +import IdeCascadeStudio from './IdeCascadeStudio' + +export const generated = () => { + return +} + +export default { title: 'Components/IdeCascadeStudio' } diff --git a/web/src/pages/HomePage/HomePage.test.js b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.test.js similarity index 51% rename from web/src/pages/HomePage/HomePage.test.js rename to web/src/components/IdeCascadeStudio/IdeCascadeStudio.test.js index 4880eea..7e80018 100644 --- a/web/src/pages/HomePage/HomePage.test.js +++ b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.test.js @@ -1,11 +1,11 @@ import { render } from '@redwoodjs/testing' -import HomePage from './HomePage' +import IdeCascadeStudio from './IdeCascadeStudio' -describe('HomePage', () => { +describe('IdeCascadeStudio', () => { it('renders successfully', () => { expect(() => { - render() + render() }).not.toThrow() }) }) diff --git a/web/src/components/IdePartCell/IdePartCell.js b/web/src/components/IdePartCell/IdePartCell.js index 703f70b..e9e6d21 100644 --- a/web/src/components/IdePartCell/IdePartCell.js +++ b/web/src/components/IdePartCell/IdePartCell.js @@ -1,10 +1,11 @@ import { useMutation, useFlash } from '@redwoodjs/web' import { navigate, routes } from '@redwoodjs/router' -// import Part from 'src/components/Part' +import IdeCascadeStudio from 'src/components/IdeCascadeStudio' +// import Part from 'src/components/Part'a export const QUERY = gql` - query FIND_PART_BY_ID($id: Int!) { - part: part(id: $id) { + query FIND_PART_BY_USENAME_TITLE($partTitle: String!, $userName: String!) { + part: partByUserAndTitle(partTitle: $partTitle, userName: $userName) { id title description @@ -16,7 +17,7 @@ export const QUERY = gql` ` const UPDATE_PART_MUTATION = gql` - mutation UpdatePartMutation($id: Int!, $input: UpdatePartInput!) { + mutation UpdatePartMutation($id: String!, $input: UpdatePartInput!) { updatePart(id: $id, input: $input) { id } @@ -27,7 +28,7 @@ export const Loading = () =>
Loading...
export const Empty = () =>
Part not found
-export const Success = ({ part }) => { +export const Success = ({ part, refetch }) => { const { addMessage } = useFlash() const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, { onCompleted: () => { @@ -40,7 +41,14 @@ export const Success = ({ part }) => { const saveCode = (input, id) => { console.log(id, input, 'wowow') updatePart({ variables: { id, input } }) + refetch() } - return
TODO part
- // return + return ( + + ) } diff --git a/web/src/components/PartProfile/PartProfile.js b/web/src/components/PartProfile/PartProfile.js index 00beef0..ad2dd3b 100644 --- a/web/src/components/PartProfile/PartProfile.js +++ b/web/src/components/PartProfile/PartProfile.js @@ -92,14 +92,21 @@ const PartProfile = ({ > Comments 11 - + + {canEdit && (