1
0
Fork 0

chore: Fixing linter warnings

This commit is contained in:
joostdecock 2023-05-19 16:31:28 +02:00
parent e0ce1a8bcf
commit c49a47a0de
33 changed files with 76 additions and 547 deletions

View file

@ -1,5 +1,5 @@
// Hooks
import { useState, useEffect, useContext } from 'react'
import { useState, useContext } from 'react'
import { useTranslation } from 'next-i18next'
// Context
import { ModalContext } from 'shared/context/modal-context.mjs'
@ -15,9 +15,7 @@ import {
MenuIcon,
OptionsIcon,
PrintIcon,
SettingsIcon,
UploadIcon,
WrenchIcon,
} from 'shared/components/icons.mjs'
import { Ribbon } from 'shared/components/ribbon.mjs'
import Link from 'next/link'
@ -71,7 +69,6 @@ export const colors = [
'violet',
'purple',
]
const views = ['menu', 'draft', 'test', 'print', 'cut', 'save', 'export', 'edit', 'clear', 'help']
const NavIcons = ({ setModal, setView, view }) => {
const { t } = useTranslation(['header'])

View file

@ -3,25 +3,10 @@ import { useEffect, useState } from 'react'
import { useTranslation } from 'next-i18next'
import { useView } from 'shared/hooks/use-view.mjs'
import { useAccount } from 'shared/hooks/use-account.mjs'
import { useBackend } from 'shared/hooks/use-backend.mjs'
// Dependencies
import { pluginTheme } from '@freesewing/plugin-theme'
import { pluginI18n } from '@freesewing/plugin-i18n'
import { objUpdate } from 'shared/utils.mjs'
//import { preloaders } from 'shared/components/workbench/preloaders.mjs'
// Components
//import { DraftError } from 'shared/components/workbench/pattern/error.mjs'
import { Modal } from 'shared/components/modal/modal.mjs'
import { ErrorBoundary } from 'shared/components/error/error-boundary.mjs'
// Views
//import { LabSample } from 'shared/components/workbench/sample.mjs'
//import { ExportDraft } from 'shared/components/workbench/exporting/index.mjs'
//import { GistAsJson, GistAsYaml } from 'shared/components/workbench/gist.mjs'
//import { DraftLogs } from 'shared/components/workbench/logs.mjs'
//import { CutLayout } from 'shared/components/workbench/layout/cut/index.mjs'
//import { PrintLayout } from 'shared/components/workbench/layout/print/index.mjs'
//import { EditYaml } from 'shared/components/workbench/edit/index.mjs'
// Components
import { WorkbenchHeader } from './header.mjs'
import { ErrorView } from 'shared/components/error/view.mjs'
@ -47,7 +32,6 @@ export const Workbench = ({ design, Design, set = false, DynamicDocs = false })
const { t, i18n } = useTranslation(ns)
const { language } = i18n
const { account, token } = useAccount()
const { backend } = useBackend(token)
const defaultSettings = loadDefaultSettings({
units: account.imperial ? 'imperial' : 'metric',
@ -128,171 +112,3 @@ export const Workbench = ({ design, Design, set = false, DynamicDocs = false })
</>
)
}
/*
const views = {
measurements: WorkbenchMeasurements,
//draft: LabDraft,
test: LabSample,
printingLayout: PrintLayout,
cuttingLayout: CutLayout,
export: ExportDraft,
logs: DraftLogs,
yaml: GistAsYaml,
json: GistAsJson,
edit: EditYaml,
welcome: () => <p>TODO</p>,
}
const hasRequiredMeasurementsMethod = (design, gist) => {
if (design.patternConfig?.measurements?.length > 0 && !gist.measurements) return false
for (const m of design.patternConfig?.measurements || []) {
if (!gist.measurements[m]) return false
}
return true
}
const doPreload = async (preload, from, design, gist, setGist, setPreloaded) => {
const g = await preloaders[from](preload, design)
setPreloaded(preload)
setGist({ ...gist, ...g.settings })
}
/*
* This component wraps the workbench and is in charge of
* keeping the gist state, which will trickle down
* to all workbench subcomponents
export const WorkbenchWrapper = ({
app,
design,
preload = false,
from = false,
layout = false,
}) => {
// State for gist
const { gist, setGist, unsetGist, updateGist, gistReady, undoGist, resetGist } = useGist(
design.designConfig?.data?.name,
app.locale
)
const [messages, setMessages] = useState([])
const [popup, setPopup] = useState(false)
const [preloaded, setPreloaded] = useState(false)
// we'll only use this if the renderer is svg, but we can't call hooks conditionally
const { t } = useTranslation(['plugin'])
// We'll use this in more than one location
const hasRequiredMeasurements = hasRequiredMeasurementsMethod(design, gist)
// If we don't have the required measurements,
// force view to measurements
useEffect(() => {
if (!gistReady) return
if (!['measurements', 'edit'].includes(gist._state?.view) && !hasRequiredMeasurements)
updateGist(['_state', 'view'], 'measurements')
}, [gistReady, gist._state?.view, hasRequiredMeasurements, updateGist])
// If we need to preload the gist, do so
useEffect(() => {
if (preload && preload !== preloaded && from && preloaders[from]) {
doPreload(preload, from, design, gist, setGist, setPreloaded)
}
}, [preload, preloaded, from, design, gist, setGist])
// Helper methods to manage the gist state
const updateWBGist = useMemo(
() =>
(path, value, closeNav = false, addToHistory = true) => {
updateGist(path, value, addToHistory)
// Force close of menu on mobile if it is open
if (closeNav && app.primaryMenu) app.setPrimaryMenu(false)
},
[app, updateGist]
)
// Helper methods to handle messages
const feedback = {
add: (msg) => {
const newMsgs = [...messages]
if (Array.isArray(msg)) newMsgs.push(...msg)
else newMsgs.push(msg)
setMessages(newMsgs)
},
set: setMessages,
clear: () => setMessages([]),
}
// don't do anything until the gist is ready
if (!gistReady) {
return null
}
// Generate the draft here so we can pass it down to both the view and the options menu
let draft = false
if (['draft', 'logs', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) {
gist.embed = true
// get the appropriate layout for the view
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
// hand it separately to the design
draft = new design({ ...gist, layout })
//draft.__init()
// add theme to svg renderer
if (gist.renderer === 'svg') {
draft.use(pluginI18n, { t })
draft.use(pluginTheme, { skipGrid: ['pages'] })
}
// draft it for draft and event views. Other views may add plugins, etc and we don't want to draft twice
try {
if (['draft', 'logs'].indexOf(gist._state.view) > -1) draft.draft()
} catch (error) {
return <DraftError error={error} app={app} draft={draft} at={'draft'} />
}
}
// Props to pass down
const componentProps = {
app,
design,
gist,
updateGist: updateWBGist,
unsetGist,
setGist,
feedback,
gistReady,
showInfo: setPopup,
hasRequiredMeasurements,
draft,
}
// Required props for layout
const layoutProps = {
app: app,
noSearch: true,
workbench: true,
AltMenu: <WorkbenchMenu {...componentProps} />,
showInfo: setPopup,
}
const errorProps = {
undoGist,
resetGist,
gist,
}
// Layout to use
const LayoutComponent = layout
const Component = views[gist._state?.view] ? views[gist._state.view] : views.welcome
return (
<LayoutComponent {...layoutProps}>
{messages}
<ErrorBoundary {...errorProps}>
<Component {...componentProps} draft={draft} />
{popup && <Modal cancel={() => setPopup(false)}>{popup}</Modal>}
</ErrorBoundary>
</LayoutComponent>
)
}
*/

View file

@ -9,18 +9,6 @@ import { loadSettingsConfig } from './config.mjs'
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
import { SettingsIcon, ClearIcon, HelpIcon } from 'shared/components/icons.mjs'
import Link from 'next/link'
import {
Li,
Ul,
SumButton,
SumDiv,
Summary,
Deg,
SecText,
Details,
TopSummary,
TopSumTitle,
} from '../index.mjs'
import { Collapse } from 'shared/components/collapse.mjs'
import {
CompleteSettingInput,

View file

@ -1,6 +1,4 @@
import { useState } from 'react'
import { useTranslation } from 'next-i18next'
import { SecText, SumButton, Li, SumDiv, Deg } from 'shared/components/workbench/menus/index.mjs'
import { formatMm } from 'shared/utils.mjs'
import { ClearIcon } from 'shared/components/icons.mjs'
import { ChoiceButton } from 'shared/components/choice-button.mjs'
@ -202,10 +200,6 @@ export const SaMmSettingInput = ({ name, config, current, update, t, units }) =>
[['sa'], newCurrent],
])
}
const reset = () => {
update.settings([[['samm']], [['sa'], config.dflt]])
setValue(config.dflt)
}
return (
<>
@ -238,7 +232,6 @@ export const SaBoolSettingInput = ({ config, current, update, t, samm, changed }
if (typeof current === 'undefined') current = config.dflt
const handleChange = (newCurrent) => {
const newSa = newCurrent ? samm : 0
if (newCurrent === config.dflt) reset()
else {
update.settings([[['sabool'], newCurrent], [['sa']]])

View file

@ -1,5 +1,4 @@
import { formatMm } from 'shared/utils.mjs'
import { SecText, AccentText, PrimaryText } from 'shared/components/workbench/menus/index.mjs'
const ListValue = ({ current, t, config, changed }) =>
changed

View file

@ -8,17 +8,6 @@ import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
import { Collapse } from 'shared/components/collapse.mjs'
import { OptionsIcon, ClearIcon, HelpIcon, EditIcon, CloseIcon } from 'shared/components/icons.mjs'
import { Chevron } from 'shared/components/navigation/primary.mjs'
import {
Li,
Ul,
Details,
Summary,
SumDiv,
SumButton,
Deg,
TopSummary,
TopSumTitle,
} from 'shared/components/workbench/menus/index.mjs'
import { optionsMenuStructure } from 'shared/utils.mjs'
import { optionType } from 'shared/utils.mjs'
import {

View file

@ -1,152 +0,0 @@
import { DesignOptions } from './design-options/index.mjs'
import { CoreSettings, ns as coreSettingsNs } from './core-settings/index.mjs'
import { XrayMenu } from './xray/index.mjs'
import { TestDesignOptions } from './test-design-options/index.mjs'
import { BulletIcon } from 'shared/components/icons.mjs'
export const linkClasses = `
text-base text-base-content sm:text-base-content
hover:text-secondary
sm:hover:text-secondary
`
export const ns = coreSettingsNs
export const Ul = (props) => <ul className="pl-5 list-inside">{props.children}</ul>
export const Li = (props) => (
<li className="flex flex-row border-r-2 border-r-transparent hover:border-r-secondary">
{props.children}
</li>
)
export const Details = (props) => (
<details className="grow" open={props.open || false}>
{props.children}
</details>
)
export const Deg = ({ changed }) => (
<BulletIcon
className={`w-2.5 h-2.5 inline-block p-0 mr-1 ${changed ? 'text-accent' : ''}`}
stroke={6}
/>
)
export const NoSumDiv = (props) => (
<div
className={`
grow px-2 ml-2 border-l-2
${linkClasses}
hover:cursor-pointer
hover:border-secondary
sm:hover:border-secondary-focus
text-base-content sm:text-base-content
`}
>
{props.children}
</div>
)
export const SumDiv = (props) => (
<div
className={`
grow pl-2 border-l-2
${linkClasses}
hover:cursor-pointer
hover:border-secondary
sm:hover:border-secondary-focus
text-base-content sm:text-base-content
py-2
`}
>
{props.children}
</div>
)
export const Summary = (props) => (
<summary
className={`
flex flex-row
px-2
text-base-content
sm:text-base-content
hover:cursor-pointer
items-start
`}
>
{props.children}
</summary>
)
export const TopSummary = (props) => (
<summary
className={`
flex flex-row gap-4 text-lg
hover:cursor-pointer
p-2
text-base-content
sm:text-base-content
items-center
`}
>
<span className="text-secondary-focus mr-4">{props.icon || null}</span>
{props.children}
</summary>
)
export const SumButton = (props) => (
<button
className={`
flex flex-row
px-2
w-full justify-between
text-left
text-base-content
sm:text-base-content
hover:cursor-pointer
items-start
mr-4
`}
onClick={props.onClick}
>
{props.children}
</button>
)
export const TopSumTitle = (props) => (
<span className={`grow ${linkClasses} hover:cursor-pointer font-bold uppercase`}>
{props.children}
</span>
)
export const SecText = (props) =>
props.raw ? (
<span className="text-secondary-focus" dangerouslySetInnerHTML={{ __html: props.raw }} />
) : (
<span className="text-secondary-focus">{props.children}</span>
)
export const AccentText = (props) =>
props.raw ? (
<span className="text-accent-focus" dangerouslySetInnerHTML={{ __html: props.raw }} />
) : (
<span className="text-accent-focus">{props.children}</span>
)
export const PrimaryText = (props) =>
props.raw ? (
<span className="text-primary-focus" dangerouslySetInnerHTML={{ __html: props.raw }} />
) : (
<span className="text-primary-focus">{props.children}</span>
)
export const DraftMenu = (props) => {
const { design, patternConfig, settings, ui, update, Option = false } = props
return (
<nav className="grow mb-12">
<DesignOptions {...{ design, update, settings, patternConfig }} />
<CoreSettings {...{ design, update, settings, patternConfig }} />
{ui.renderer === 'react' ? <XrayMenu {...props} /> : null}
</nav>
)
}
export const TestMenu = (props) => {
return (
<nav className="grow mb-12">
<TestDesignOptions {...props} />
</nav>
)
}

View file

@ -1,15 +1,9 @@
import { Chevron } from 'shared/components/navigation/primary'
import {
Ul,
Li,
Details,
Summary,
SumDiv,
NoSumDiv,
Deg,
} from 'shared/components/workbench/menus/index.mjs'
export const XrayAttributes = ({ attr = false, t }) => {
return null
// FIXME
/*
if (!attr || !attr.list || Object.keys(attr.list).length < 1) return null
return (
@ -50,4 +44,5 @@ export const XrayAttributes = ({ attr = false, t }) => {
</Details>
</Li>
)
*/
}

View file

@ -3,7 +3,6 @@ import { linkClasses, Chevron } from 'shared/components/navigation/primary.mjs'
import { ConsoleLog } from './log.mjs'
import { XrayReset } from './reset.mjs'
import { XrayList } from './list.mjs'
import { Ul, Details, TopSummary } from 'shared/components/workbench/menus/index.mjs'
import { useTranslation } from 'next-i18next'
import { Collapse } from 'shared/components/collapse.mjs'
import { ChoiceButton } from 'shared/components/choice-button.mjs'

View file

@ -1,6 +1,5 @@
import { Chevron } from 'shared/components/navigation/primary.mjs'
import { ClearIcon, FilterIcon, SearchIcon } from 'shared/components/icons.mjs'
import { Ul, Li, Details, Summary, SumDiv, Deg } from 'shared/components/workbench/menus/index.mjs'
import { XrayPath } from './path.mjs'
import { XrayPoint } from './point.mjs'
import { useTranslation } from 'next-i18next'
@ -12,6 +11,9 @@ const types = {
export const XrayList = (props) => {
const { t } = useTranslation(['app', 'parts'])
return null
// FIXME
/*
const title = t(`parts:${props.partName}`) + ` (${props.partName})`
@ -159,4 +161,5 @@ export const XrayList = (props) => {
</Details>
</Li>
)
*/
}

View file

@ -1,15 +1,9 @@
import { Chevron } from 'shared/components/navigation/primary.mjs'
import {
Ul,
Li,
Details,
Summary,
SumButton,
SumDiv,
Deg,
} from 'shared/components/workbench/menus/index.mjs'
export const ConsoleLog = (props) => (
export const ConsoleLog = (props) => null
// FIXME
/*
(
<Li>
<Details>
<Summary>
@ -41,3 +35,4 @@ export const ConsoleLog = (props) => (
</Details>
</Li>
)
*/

View file

@ -1,17 +1,9 @@
import { Chevron } from 'shared/components/navigation/primary'
import {
Ul,
Li,
Details,
Summary,
SumDiv,
NoSumDiv,
Deg,
} from 'shared/components/workbench/menus/index.mjs'
import { XrayPoint } from './point'
const MoveLine = ({ op }) => <XrayPoint point={op.to} />
const Curve = ({ op }) =>
const Curve = ({ op }) => null
/*
['cp1', 'cp2', 'to'].map((pnt) => (
<Li key={pnt}>
<Details>
@ -26,8 +18,10 @@ const Curve = ({ op }) =>
</Details>
</Li>
))
const XrayPathOp = ({ op }) => (
*/
const XrayPathOp = ({ op }) => null
/*
* (
<Li>
{op.type === 'close' ? (
<NoSumDiv>
@ -49,8 +43,10 @@ const XrayPathOp = ({ op }) => (
)}
</Li>
)
export const XrayPathOps = ({ ops = false }) => {
*/
export const XrayPathOps = ({ ops = false }) => null
/*
* {
if (!ops || ops.length < 1) return null
return (
@ -72,3 +68,4 @@ export const XrayPathOps = ({ ops = false }) => {
</Li>
)
}
*/

View file

@ -1,9 +1,9 @@
import { Ul, Li, NoSumDiv, Deg } from 'shared/components/workbench/menus/index.mjs'
import { formatMm } from 'shared/utils.mjs'
import { XrayAttributes } from './attributes.mjs'
import { XrayPathOps } from './path-ops.mjs'
export const XrayPath = ({ pathName, partName, draft, units }) => {
export const XrayPath = ({ pathName, partName, draft, units }) => null
/*{
const path = draft?.parts?.[partName]?.paths?.[pathName]
if (!path) return null
@ -32,3 +32,4 @@ export const XrayPath = ({ pathName, partName, draft, units }) => {
</Ul>
)
}
*/

View file

@ -1,8 +1,8 @@
import { Ul, Li, NoSumDiv, Deg } from 'shared/components/workbench/menus/index.mjs'
import { round } from 'shared/utils'
import { XrayAttributes } from './attributes'
export const XrayPoint = ({ pointName, partName, draft, t }) => {
export const XrayPoint = ({ pointName, partName, draft, t }) => null
/*{
const point = draft?.parts?.[partName]?.points?.[pointName]
return point ? (
@ -20,3 +20,4 @@ export const XrayPoint = ({ pointName, partName, draft, t }) => {
</Ul>
) : null
}
*/

View file

@ -1,7 +1,7 @@
import { Li, SumButton, SumDiv, Deg } from 'shared/components/workbench/menus/index.mjs'
import { useTranslation } from 'next-i18next'
export const XrayReset = (props) => {
export const XrayReset = (props) => null
/*{
const { t } = useTranslation(['app'])
return (
@ -15,3 +15,4 @@ export const XrayReset = (props) => {
</Li>
)
}
*/