1
0
Fork 0

[react] fix: Improve handling default values of the pattern settings. (#234)

Fixes #229

unsure if expand is intended to be enabled or disabled by default, I opted for saving paper by default, but this can be easily changed.

Reviewed-on: https://codeberg.org/freesewing/freesewing/pulls/234
Reviewed-by: Joost De Cock <joostdecock@noreply.codeberg.org>
Co-authored-by: Jonathan Haas <haasjona@gmail.com>
Co-committed-by: Jonathan Haas <haasjona@gmail.com>
This commit is contained in:
Jonathan Haas 2025-04-12 08:01:16 +00:00 committed by Joost De Cock
parent aa9267b3c9
commit 658555efb6

View file

@ -14,6 +14,11 @@ import { LoadingStatus } from './components/LoadingStatus.mjs'
import { ModalContextProvider } from '@freesewing/react/context/Modal' import { ModalContextProvider } from '@freesewing/react/context/Modal'
import { LoadingStatusContextProvider } from '@freesewing/react/context/LoadingStatus' import { LoadingStatusContextProvider } from '@freesewing/react/context/LoadingStatus'
/**
* Default setting values for the editor
*/
const defaultSettings = { sa: false, paperless: false, expand: false, complete: true }
/** /**
* FreeSewing's pattern editor * FreeSewing's pattern editor
* *
@ -109,18 +114,17 @@ export const Editor = ({
* We also ensure that settings is always set to an empty object in case there * We also ensure that settings is always set to an empty object in case there
* are no settings yet, as this avoids having to null-check them everywhere. * are no settings yet, as this avoids having to null-check them everywhere.
*/ */
const passDownState = const passDownState = {
state.ui?.ux === undefined
? {
settings: {}, // Ensure settings is always set
...state, ...state,
ui: { ...(state.ui || {}), ux: editorConfig.defaultUx }, // Preset the default value of the pattern settings if not given.
// Otherwise, we would later need to be very careful
// when handling undefined/unset settings (including in the pattern code).
settings: { ...defaultSettings, ...state.settings },
_: { ...ephemeralState, missingMeasurements }, _: { ...ephemeralState, missingMeasurements },
} }
: {
settings: {}, // Ensure settings is always set if (state.ui?.ux === undefined) {
...state, passDownState.ui = { ...(state.ui || {}), ux: editorConfig.defaultUx }
_: { ...ephemeralState, missingMeasurements },
} }
return ( return (