Added cadPackage to ProjectsOfUser, other cleanup/linting

This commit is contained in:
Frank Johnson
2021-09-19 11:06:45 -04:00
parent bb4659a2dd
commit 634304dfce
6 changed files with 83 additions and 70 deletions

View File

@@ -49,14 +49,15 @@ const CadPackage = ({
<button <button
onClick={onClick} onClick={onClick}
className={ className={
`grid grid-flow-col-dense items-center gap-2 text-gray-100 bg-opacity-30 hover:bg-opacity-80 ${cadPackageConfig.buttonClasses} ` + `grid grid-flow-col-dense items-center gap-2 text-gray-100 bg-opacity-30 ${
className onClick && ' hover:bg-opacity-80 '
} ${cadPackageConfig?.buttonClasses} ` + className
} }
> >
<div <div
className={`${cadPackageConfig.dotClasses} ${dotClass} rounded-full`} className={`${cadPackageConfig?.dotClasses} ${dotClass} rounded-full`}
/> />
{cadPackageConfig.label} {cadPackageConfig?.label}
</button> </button>
) )
} }

View File

@@ -8,6 +8,7 @@ export const QUERY = gql`
id id
title title
mainImage mainImage
cadPackage
createdAt createdAt
updatedAt updatedAt
user { user {

View File

@@ -1,7 +1,7 @@
// While the raw-loader Webpack plugin actually makes these imports work, this // While the raw-loader Webpack plugin actually makes these imports work, this
// eliminates noisy TypeScript errors by registering these file endings as types. // eliminates noisy TypeScript errors by registering these file endings as types.
// Learned this method of registering modules from https://stackoverflow.com/a/57444766 // Learned this method of registering modules from https://stackoverflow.com/a/57444766
declare module "*.md"; declare module '*.md'
declare module "*.scad"; declare module '*.scad'
declare module "*.py"; declare module '*.py'
declare module "*.jscad.js"; declare module '*.jscad.js'

View File

@@ -2,11 +2,33 @@ import { DefaultKernelExport } from './common'
import type { CadPackageType } from 'src/components/CadPackage/CadPackage' import type { CadPackageType } from 'src/components/CadPackage/CadPackage'
import openscad from './openScad/openScadController' import openscad from './openScad/openScadController'
import openScadGuide from 'src/helpers/cadPackages/openScad/userGuide.md'
import openScadInitialCode from 'src/helpers/cadPackages/openScad/initialCode.scad'
import cadquery from './cadQueryController' import cadquery from './cadQueryController'
import cadQueryGuide from 'src/helpers/cadPackages/cadQuery/userGuide.md'
import cadQueryInitialCode from 'src/helpers/cadPackages/cadQuery/initialCode.py'
import jscad from './jsCad/jsCadController' import jscad from './jsCad/jsCadController'
import jsCadGuide from 'src/helpers/cadPackages/jsCad/userGuide.md'
import jsCadInitialCode from 'src/helpers/cadPackages/jsCad/initialCode.jscad.js'
export const cadPackages: { [key in CadPackageType]: DefaultKernelExport } = { export const cadPackages: { [key in CadPackageType]: DefaultKernelExport } = {
openscad, openscad,
cadquery, cadquery,
jscad, jscad,
} }
export const initGuideMap: { [key in CadPackageType]: string } = {
openscad: openScadGuide,
cadquery: cadQueryGuide,
jscad: jsCadGuide,
INIT: '',
}
export const initCodeMap: { [key in CadPackageType]: string } = {
openscad: openScadInitialCode,
cadquery: cadQueryInitialCode,
jscad: jsCadInitialCode,
INIT: '',
}

View File

@@ -7,27 +7,37 @@ const { degToRad } = jscad.utils // because jscad uses radians for rotations
// https://openjscad.xyz/docs/module-modeling_booleans.html // https://openjscad.xyz/docs/module-modeling_booleans.html
const { subtract } = jscad.booleans const { subtract } = jscad.booleans
function main({//@jscad-params function main({
// Box example //@jscad-params
width=40, // Width // Box example
length=20, // Length width = 40, // Width
height=10, // Height length = 20, // Length
hole=3,// Hole for cables diameter (0=no hole) height = 10, // Height
wall=1, // wall {min:0.5, step:0.5} hole = 3, // Hole for cables diameter (0=no hole)
flip=0, // print orientation {type: 'choice', values: [0, 90, 180]} wall = 1, // wall {min:0.5, step:0.5}
}){ flip = 0, // print orientation {type: 'choice', values: [0, 90, 180]}
}) {
let wallOffset = wall * 2 let wallOffset = wall * 2
let model = subtract( let model = subtract(
cuboid({size:[width, length, height]}), cuboid({ size: [width, length, height] }),
translate([0,0,wall], cuboid({size:[width-wallOffset, length-wallOffset, height+wall]})), translate(
[0, 0, wall],
cuboid({ size: [width - wallOffset, length - wallOffset, height + wall] })
) )
if(hole){ )
model = subtract( model, if (hole) {
translate([width/2-wall/2], rotate([0, degToRad(90), 0 ], cylinder({radius:hole/2, height:wall}))) model = subtract(
model,
translate(
[width / 2 - wall / 2],
rotate(
[0, degToRad(90), 0],
cylinder({ radius: hole / 2, height: wall })
) )
} )
return rotate([degToRad(flip), 0, degToRad(90)], model) )
}
return rotate([degToRad(flip), 0, degToRad(90)], model)
} }
module.exports = {main} module.exports = { main }

View File

@@ -1,18 +1,12 @@
import { useReducer } from 'react' import { useReducer } from 'react'
import { cadPackages } from 'src/helpers/cadPackages' import { cadPackages, initCodeMap, initGuideMap } from 'src/helpers/cadPackages'
import type { RootState } from '@react-three/fiber' import type { RootState } from '@react-three/fiber'
import type { import type {
RawCustomizerParams, RawCustomizerParams,
ArtifactTypes, ArtifactTypes,
} from 'src/helpers/cadPackages/common' } from 'src/helpers/cadPackages/common'
import { CadhubParams } from 'src/components/Customizer/customizerConverter' import { CadhubParams } from 'src/components/Customizer/customizerConverter'
import openScadGuide from 'src/helpers/cadPackages/openScad/userGuide.md' import { CadPackageType } from 'src/components/CadPackage/CadPackage'
import openScadInitialCode from 'src/helpers/cadPackages/openScad/initialCode.scad'
import cadQueryGuide from 'src/helpers/cadPackages/cadQuery/userGuide.md'
import cadQueryInitialCode from 'src/helpers/cadPackages/cadQuery/initialCode.py'
import jsCadGuide from 'src/helpers/cadPackages/jsCad/userGuide.md'
import jsCadInitialCode from 'src/helpers/cadPackages/jsCad/initialCode.jscad.js'
function withThunk(dispatch, getState) { function withThunk(dispatch, getState) {
return (actionOrThunk) => return (actionOrThunk) =>
@@ -20,21 +14,6 @@ function withThunk(dispatch, getState) {
? actionOrThunk(dispatch, getState) ? actionOrThunk(dispatch, getState)
: dispatch(actionOrThunk) : dispatch(actionOrThunk)
} }
import { CadPackageType } from 'src/components/CadPackage/CadPackage'
const initGuideMap: { [key in CadPackageType]: string } = {
openscad: openScadGuide,
cadquery: cadQueryGuide,
jscad: jsCadGuide,
INIT: '',
}
const initCodeMap: { [key in CadPackageType]: string } = {
openscad: openScadInitialCode,
cadquery: cadQueryInitialCode,
jscad: jsCadInitialCode,
INIT: '',
}
const codeStorageKey = 'Last-editor-code' const codeStorageKey = 'Last-editor-code'
export const makeCodeStoreKey = (ideType) => `${codeStorageKey}-${ideType}` export const makeCodeStoreKey = (ideType) => `${codeStorageKey}-${ideType}`
@@ -251,25 +230,25 @@ const reducer = (state: State, { type, payload }): State => {
], ],
currentModel: payload === 0 ? 0 : payload - 1, currentModel: payload === 0 ? 0 : payload - 1,
} }
case 'updateEditorModel': { // case 'updateEditorModel': {
const newModels = [...state.models] // const newModels = [...state.models]
newModels[state.currentModel].content = payload // newModels[state.currentModel].content = payload
return { // return {
...state, // ...state,
models: newModels, // models: newModels,
} // }
} // }
case 'reorderEditorModels': { // case 'reorderEditorModels': {
const newModels = [ // const newModels = [
...state.models.slice(0, state.currentModel), // ...state.models.slice(0, state.currentModel),
...state.models.slice(state.currentModel + 1), // ...state.models.slice(state.currentModel + 1),
].splice(payload, 0, state.models[state.currentModel]) // ].splice(payload, 0, state.models[state.currentModel])
return { // return {
...state, // ...state,
models: newModels, // models: newModels,
currentModel: payload, // currentModel: payload,
} // }
} // }
default: default:
return state return state
} }