1
0
Fork 0

wip(fs.lab): Work on workbench components

This commit is contained in:
Joost De Cock 2022-01-25 08:31:06 +01:00
parent 8703983f2f
commit 22b25c0c5d
5 changed files with 242 additions and 63 deletions

View file

@ -1,4 +1,4 @@
import React, { useState } from 'react' import React, { useState, useEffect } from 'react'
/* /*
* This is a single input for a measurements * This is a single input for a measurements
@ -11,7 +11,6 @@ import React, { useState } from 'react'
const MeasurementInput = ({ m, gist, app, updateMeasurements }) => { const MeasurementInput = ({ m, gist, app, updateMeasurements }) => {
const prefix = (app.site === 'org') ? '' : 'https://freesewing.org' const prefix = (app.site === 'org') ? '' : 'https://freesewing.org'
const title = app.t(`measurements.${m}`) const title = app.t(`measurements.${m}`)
console.log('render', m)
const isValid = input => { const isValid = input => {
if (input === null || input === '') return null if (input === null || input === '') return null
return !isNaN(input) return !isNaN(input)
@ -23,7 +22,7 @@ const MeasurementInput = ({ m, gist, app, updateMeasurements }) => {
console.log({ok}) console.log({ok})
if (ok) { if (ok) {
setValid(true) setValid(true)
updateMeasurements(evt.target.value, m) updateMeasurements(evt.target.value*10, m)
} else setValid(false) } else setValid(false)
} }
@ -33,6 +32,11 @@ const MeasurementInput = ({ m, gist, app, updateMeasurements }) => {
isValid(gist.measurements[m]) isValid(gist.measurements[m])
) )
useEffect(() => {
console.log(gist.measurements)
if (gist?.measurements?.[m]) setVal(gist.measurements[m]/10)
}, [gist])
if (!m) return null if (!m) return null
return ( return (

View file

@ -1,4 +1,27 @@
import MeasurementInput from './input-measurement.js' import MeasurementInput from './input-measurement.js'
import { withBreasts, withoutBreasts } from 'pkgs/models/src/index.js'
import nonHuman from './non-human-measurements.js'
import WithBreastsIcon from 'shared/components/icons/with-breasts.js'
import WithoutBreastsIcon from 'shared/components/icons/without-breasts.js'
const groups = {
people: {
with: withBreasts,
without: withoutBreasts,
},
dolls: {
with: nonHuman.withBreasts.dolls,
without: nonHuman.withoutBreasts.dolls,
},
giants: {
with: nonHuman.withBreasts.giants,
without: nonHuman.withoutBreasts.giants,
}
}
const icons = {
with: <WithBreastsIcon />,
without: <WithoutBreastsIcon />,
}
const WorkbenchMeasurements = ({ app, pattern, gist, updateGist }) => { const WorkbenchMeasurements = ({ app, pattern, gist, updateGist }) => {
@ -6,10 +29,11 @@ const WorkbenchMeasurements = ({ app, pattern, gist, updateGist }) => {
const updateMeasurements = (value, m=false) => { const updateMeasurements = (value, m=false) => {
if (m === false) { if (m === false) {
// Set all measurements // Set all measurements
updateGist('measurements', value)
} else { } else {
// Set one measurement // Set one measurement
const newValues = {...gist.measurements} const newValues = {...gist.measurements}
newValues[m] = value.trim() newValues[m] = value
updateGist('measurements', newValues) updateGist('measurements', newValues)
} }
} }
@ -24,22 +48,63 @@ const WorkbenchMeasurements = ({ app, pattern, gist, updateGist }) => {
</span> </span>
{app.t('measurements')} {app.t('measurements')}
</h1> </h1>
{pattern.config.measurements && ( <details open>
<> <summary><h2 className="inline-block">{app.t('cfp.preloadMeasurements')}</h2></summary>
<h2>{app.t('requiredMeasurements')}</h2> <div className="ml-2 pl-4 border-l-2">
{pattern.config.measurements.map(m => ( {Object.keys(groups).map(group => (
<MeasurementInput key={m} m={m} {...inputProps} /> <details>
<summary><h3 className="inline-block">{app.t(`app.${group}`)}</h3></summary>
<div className="ml-2 pl-4 border-l-2">
{Object.keys(icons).map(type => (
<>
<h4>{app.t(`app.${type}Breasts`)}</h4>
<ul className="flex flex-row flex-wrap gap-2">
{Object.keys(groups[group][type]).map((m) => (
<li key={`${m}-${type}-${group}`} className="">
<button
className="flex flex-row btn btn-outline"
onClick={() => updateMeasurements(groups[group][type][m], false)}
>
{icons[type]}
{app.t('cfp.size')}&nbsp;
{ group === 'people'
? m.slice(-2)
: m
}
</button>
</li>
))}
</ul>
</>
))}
</div>
</details>
))} ))}
</> </div>
)} </details>
{pattern.config.optionalMeasurements && (
<> <details>
<h2>{app.t('optionalMeasurements')}</h2> <summary><h2 className="inline-block">{app.t('cfp.enterMeasurements')}</h2></summary>
{pattern.config.optionalMeasurements.map(m => ( <div className="ml-2 pl-4 border-l-2">
<MeasurementInput key={m} m={m} {...inputProps} /> {pattern.config.measurements && (
))} <>
</> <h3>{app.t('requiredMeasurements')}</h3>
)} {pattern.config.measurements.map(m => (
<MeasurementInput key={m} m={m} {...inputProps} />
))}
</>
)}
{pattern.config.optionalMeasurements && (
<>
<h3>{app.t('optionalMeasurements')}</h3>
{pattern.config.optionalMeasurements.map(m => (
<MeasurementInput key={m} m={m} {...inputProps} />
))}
</>
)}
</div>
</details>
</div> </div>
) )
} }

View file

@ -3,51 +3,111 @@ import Link from 'next/link'
import orderBy from 'lodash.orderby' import orderBy from 'lodash.orderby'
import OptionsIcon from 'shared/components/icons/options.js' import OptionsIcon from 'shared/components/icons/options.js'
import SettingsIcon from 'shared/components/icons/settings.js' import SettingsIcon from 'shared/components/icons/settings.js'
import MenuIcon from 'shared/components/icons/menu.js'
import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' import { linkClasses, Chevron } from 'shared/components/navigation/primary.js'
const structure = (pattern, app) => ({ // Component that renders a sublevel of navigation
modes: [ const ModeButtons = props => props.children.length === 0
{ title: `Draft ${pattern.config.name}`, action: '' }, ? null
], : (
options: [ <ul className="pl-5 list-inside">
{ title: `Draft ${pattern.config.name}`, action: '' }, {props.children.map(mode => (
], <li key={mode.title} className="flex flex-row">
settings: [ <button title={mode.title} className={`
{ title: `Draft ${pattern.config.name}`, action: '' }, grow pl-2 border-l-2
], ${linkClasses}
hover:border-secondary
sm:hover:border-secondary-focus
text-left
${mode.name === props.mode
? 'text-secondary border-secondary sm:text-secondary-focus sm:border-secondary-focus'
: 'text-base-content sm:text-neutral-content'
}
`}>
<span className={`
text-3xl mr-2 inline-block p-0 leading-3
${mode.name === props.mode
? 'text-secondary sm:text-secondary-focus translate-y-1'
: 'translate-y-3'
}
`}>
{mode.name === props.mode ? <>&bull;</> : <>&deg;</>}
</span>
<span className={mode.name === props.mode ? 'font-bold' : ''}>
{ mode.title }
</span>
</button>
</li>
))}
</ul>
)
const groupMaker = (t, setMode, pattern) => ({
modes: {
icon: <MenuIcon />,
title: t('app.modes'),
children: [
{
name: 'measurements',
title: t('app.measurements'),
onClick: () => setMode('measurements')
},
{
name: 'draft',
title: t('app.draftThing', { thing: pattern }),
onClick: () => setMode('draft')
},
{
name: 'test',
title: t('app.testThing', { thing: pattern }),
onClick: () => setMode('test')
},
{
name: 'export',
title: t('app.export'),
onClick: () => setMode('export')
},
]
},
toggles: {
icon: <OptionsIcon />,
title: `${t('cfp.turnOn')} / ${t('cfp.turnOff')}`,
},
options: {
icon: <OptionsIcon />,
title: t('app.designOptions'),
},
settings: {
icon: <SettingsIcon />,
title: t('app.settings')
},
}) })
const TopLevel = ({ icon, title }) => ( const WorkbenchMenu = props => {
<details className='py-1'> const groups = groupMaker(props.app.t, props.setMode, props.pattern)
<summary className={` return (
flex flex-row uppercase gap-4 font-bold text-lg <nav className="smmax-w-96 grow mb-12">
hover:cursor-row-resize {Object.keys(groups).map(group => (
p-2 <details className='py-1'>
text-base-content <summary className={`
sm:text-neutral-content flex flex-row uppercase gap-4 font-bold text-lg
items-center hover:cursor-row-resize
`}> p-2
<span className="text-secondary-focus mr-4">{icon}</span> text-base-content
<span className={`grow ${linkClasses}`}> sm:text-neutral-content
{title} items-center
</span> `} open={'modes' === group}>
<Chevron /> <span className="text-secondary-focus mr-4">{groups[group].icon}</span>
</summary> <span className={`grow ${linkClasses}`}>
fixme {groups[group].title}
</details> </span>
) <Chevron />
</summary>
const Menu = ({ app, pattern }) => ([ {group === 'modes' && <ModeButtons {...props} {...groups[group]} />}
<TopLevel key='a' title='Toggles' icon={<OptionsIcon />} pattern={pattern} />, </details>
<TopLevel key='b' title='Modes' icon={<OptionsIcon />} pattern={pattern} />, ))}
<TopLevel key='c' title='Design Options' icon={<OptionsIcon />} pattern={pattern} />, </nav>
<TopLevel key='d' title='Pattern Settings' icon={<SettingsIcon />} pattern={pattern} />, )
]) }
const WorkbenchMenu = ({ app, pattern }) => (
<nav className="smmax-w-96 grow mb-12">
<Menu app={app} pattern={pattern} />
</nav>
)
export default WorkbenchMenu export default WorkbenchMenu

View file

@ -0,0 +1,51 @@
import { withBreasts, withoutBreasts } from '@freesewing/models'
const nonHuman = {
withoutBreasts: {
dolls: {},
giants: {}
},
withBreasts: {
dolls: {},
giants: {}
}
}
const round = val => Math.round(val*10)/10
for (let i=0.1;i<0.7;i+=0.1) {
const name = `${Math.round(i*10)}/10`
nonHuman.withBreasts.dolls[name] = {}
// withBreasts: Based on Anneke (size 34)
for (const [m, val] of Object.entries(withBreasts.size34)) {
nonHuman.withBreasts.dolls[name][m] = (m === 'shoulderSlope')
? val
: round(val * i)
}
// withoutBreasts: Based on Ronan (size 42)
nonHuman.withoutBreasts.dolls[name] = {}
for (const [m, val] of Object.entries(withoutBreasts.size42)) {
nonHuman.withoutBreasts.dolls[name][m] = (m === 'shoulderSlope')
? val
: round(val * i)
}
}
for (let i=1.5;i<=3;i+=0.5) {
const name = `${i}/1`
nonHuman.withBreasts.giants[name] = {}
// withBreasts: Based on Anneke (size 34)
for (const [m, val] of Object.entries(withBreasts.size34)) {
nonHuman.withBreasts.giants[name][m] = (m === 'shoulderSlope')
? val
: round(val * i)
}
nonHuman.withoutBreasts.giants[name] = {}
// withoutBreasts: Based on Ronan (size 42)
for (const [m, val] of Object.entries(withoutBreasts.size42)) {
nonHuman.withoutBreasts.giants[name][m] = (m === 'shoulderSlope')
? val
: round(val * i)
}
}
export default nonHuman

View file

@ -62,7 +62,7 @@ const WorkbenchWrapper = ({ app, pattern }) => {
app: app, app: app,
noSearch: true, noSearch: true,
workbench: true, workbench: true,
AltMenu: Menu AltMenu: <Menu app={app} pattern={pattern} mode={mode} setMode={setMode} gist={gist} updateGist={updateGist} />
} }
return ( return (
@ -75,7 +75,6 @@ const WorkbenchWrapper = ({ app, pattern }) => {
updateGist={updateGist} updateGist={updateGist}
/> />
)} )}
<pre>{JSON.stringify(gist, null, 2)}</pre>
</Layout> </Layout>
) )
} }