1
0
Fork 0

fix(shared): Apply control limits to draft header. Fixes #5059

This commit is contained in:
joostdecock 2023-10-01 16:15:14 +02:00
parent 5f27133b5e
commit 9382585c07
3 changed files with 87 additions and 56 deletions

View file

@ -11,6 +11,7 @@ import {
MarginIcon,
ExpandIcon,
} from 'shared/components/icons.mjs'
import { freeSewingConfig as config } from 'shared/config/freesewing.config.mjs'
export const defaultSamm = (units, inMm = true) => {
const dflt = units === 'imperial' ? 0.5 : 1
@ -24,7 +25,7 @@ export const loadSettingsConfig = ({
parts = [],
}) => ({
sabool: {
control: 2, // Show when control > 1
control: config.coreSettingsControl.sa,
list: [0, 1],
choiceTitles: {
0: 'saNo',
@ -39,7 +40,7 @@ export const loadSettingsConfig = ({
},
samm: sabool
? {
control: 2, // Show when control > 1
control: config.coreSettingsControl.sa,
min: 0,
max: units === 'imperial' ? 2 : 2.5,
dflt: defaultSamm(units),
@ -47,7 +48,7 @@ export const loadSettingsConfig = ({
}
: false,
paperless: {
control: 2, // Show when control > 1
control: config.coreSettingsControl.paperless,
list: [0, 1],
choiceTitles: {
0: 'paperlessNo',
@ -61,7 +62,7 @@ export const loadSettingsConfig = ({
icon: PaperlessIcon,
},
locale: {
control: 3, // Show when control > 2
control: config.coreSettingsControl.locale,
list: ['de', 'en', 'es', 'fr', 'nl'],
dflt: language,
choiceTitles: {
@ -81,7 +82,7 @@ export const loadSettingsConfig = ({
icon: I18nIcon,
},
units: {
control: 1, // Show when control > 2
control: config.coreSettingsControl.units,
list: ['metric', 'imperial'],
dflt: 'metric',
choiceTitles: {
@ -95,7 +96,7 @@ export const loadSettingsConfig = ({
icon: UnitsIcon,
},
complete: {
control: 4, // Show when control > 3
control: config.coreSettingsControl.complete,
list: [1, 0],
dflt: 1,
choiceTitles: {
@ -109,7 +110,7 @@ export const loadSettingsConfig = ({
icon: DetailIcon,
},
expand: {
control: 4, // Show when control > 3
control: config.coreSettingsControl.expand,
list: [1, 0],
dflt: 1,
choiceTitles: {
@ -123,14 +124,14 @@ export const loadSettingsConfig = ({
icon: ExpandIcon,
},
only: {
control: 4, // Show when control > 3
control: config.coreSettingsControl.only,
dflt: false,
list: parts,
parts,
icon: IncludeIcon,
},
scale: {
control: 4, // Show when control > 3
control: config.coreSettingsControl.scale,
min: 0.1,
max: 5,
dflt: 1,
@ -138,7 +139,7 @@ export const loadSettingsConfig = ({
icon: ScaleIcon,
},
margin: {
control: 4, // Show when control > 3
control: config.coreSettingsControl.margin,
min: 0,
max: 2.5,
dflt: measurementAsMm(units === 'imperial' ? 0.125 : 0.2, units),

View file

@ -1,6 +1,7 @@
// __SDEFILE__ - This file is a dependency for the stand-alone environment
// Dependencies
import { capitalize, shortDate } from 'shared/utils.mjs'
import { controlLevels } from 'shared/config/freesewing.config.mjs'
// Hooks
import { useContext, useMemo } from 'react'
import { useMobileAction } from 'shared/context/mobile-menubar-context.mjs'
@ -145,52 +146,62 @@ export const DraftHeader = ({
{headerZoomButtons}
<Spacer />
<div className="flex flex-row items-center gap-4">
<IconButton
Icon={SaIcon}
dflt={settings.sabool ? false : true}
onClick={() => update.toggleSa()}
title={t('core-settings:sabool.t')}
/>
<IconButton
Icon={PaperlessIcon}
dflt={settings.paperless ? false : true}
onClick={() => update.settings(['paperless'], !settings.paperless)}
title={t('core-settings:paperless.t')}
/>
<IconButton
Icon={DetailIcon}
dflt={settings.complete}
onClick={() =>
update.settings(
['complete'],
typeof settings.complete === 'undefined' ? 0 : settings.complete ? 0 : 1
)
}
title={t('core-settings:complete.t')}
/>
<IconButton
Icon={ExpandIcon}
dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false}
onClick={() =>
update.settings(
['expand'],
typeof settings.expand === 'undefined' ? 1 : settings.expand ? 0 : 1
)
}
title={t('core-settings:expand.t')}
/>
<IconButton
Icon={
settings.units !== 'imperial'
? UnitsIcon
: ({ className }) => <UnitsIcon className={`${className} rotate-180 w-6 h-6`} />
}
dflt={settings.units !== 'imperial'}
onClick={() =>
update.settings(['units'], settings.units === 'imperial' ? 'metric' : 'imperial')
}
title={t('core-settings:units.t')}
/>
{control < controlLevels.core.sa ? null : (
<IconButton
Icon={SaIcon}
dflt={settings.sabool ? false : true}
onClick={() => update.toggleSa()}
title={t('core-settings:sabool.t')}
/>
)}
{control < controlLevels.core.paperless ? null : (
<IconButton
Icon={PaperlessIcon}
dflt={settings.paperless ? false : true}
onClick={() => update.settings(['paperless'], !settings.paperless)}
title={t('core-settings:paperless.t')}
/>
)}
{control < controlLevels.core.complete ? null : (
<IconButton
Icon={DetailIcon}
dflt={settings.complete}
onClick={() =>
update.settings(
['complete'],
typeof settings.complete === 'undefined' ? 0 : settings.complete ? 0 : 1
)
}
title={t('core-settings:complete.t')}
/>
)}
{control < controlLevels.core.expand ? null : (
<IconButton
Icon={ExpandIcon}
dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false}
onClick={() =>
update.settings(
['expand'],
typeof settings.expand === 'undefined' ? 1 : settings.expand ? 0 : 1
)
}
title={t('core-settings:expand.t')}
/>
)}
{control < controlLevels.core.units ? null : (
<IconButton
Icon={
settings.units !== 'imperial'
? UnitsIcon
: ({ className }) => <UnitsIcon className={`${className} rotate-180 w-6 h-6`} />
}
dflt={settings.units !== 'imperial'}
onClick={() =>
update.settings(['units'], settings.units === 'imperial' ? 'metric' : 'imperial')
}
title={t('core-settings:units.t')}
/>
)}
</div>
<Spacer />
<div

View file

@ -69,6 +69,23 @@ export const freeSewingConfig = {
id: 4,
},
},
control: {
core: {
sa: 2,
paperless: 2,
locale: 3,
units: 1,
complete: 4,
expand: 4,
only: 4,
scale: 4,
margin: 4,
},
ui: {
renderer: 4,
kiosk: 2,
},
},
social,
statuses: {
0: {
@ -98,4 +115,6 @@ export const controlLevels = {
...freeSewingConfig.account.fields.identities,
sets: freeSewingConfig.account.sets,
patterns: freeSewingConfig.account.patterns,
core: freeSewingConfig.control.core,
ui: freeSewingConfig.control.ui,
}