fix(shared): Saving pattern in edit mode
This reverts the temporary fix for #5534
(commit 99b6e75956
)
and implements a proper fix.
This also closes #5570 as that was a side-effect of the initial
half-assed fix.
This commit is contained in:
parent
031be5820b
commit
d442e23d69
3 changed files with 16 additions and 30 deletions
|
@ -21,7 +21,7 @@ import { Loading } from 'shared/components/spinner.mjs'
|
|||
const ns = nsMerge('$$design$$', wbNs, pageNs)
|
||||
|
||||
const EditDesignComponent = ({ id, design, Design, settings }) => (
|
||||
<Workbench preload={{ settings }} saveAs={{ pattern: id, edit: 0 }} {...{ design, Design }} />
|
||||
<Workbench preload={{ settings }} saveAs={{ pattern: id }} {...{ design, Design }} />
|
||||
)
|
||||
|
||||
const Edit$$Design$$Page = ({ page }) => {
|
||||
|
|
|
@ -105,10 +105,9 @@ export const Workbench = ({ design, Design, saveAs = false, preload = false }) =
|
|||
// Handle preload
|
||||
useEffect(() => {
|
||||
if (preload) {
|
||||
// This will run a few times while variouos things bootstrap
|
||||
// This will run a few times while things bootstrap
|
||||
// but should not run after that.
|
||||
if (preload.settings && preloaded < 3) {
|
||||
console.log('preloading settings', { mounted, preloaded })
|
||||
if (preload.settings && preloaded < 2) {
|
||||
setSettings(preload.settings)
|
||||
setView('draft')
|
||||
setPreloaded(preloaded + 1)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import { capitalize, shortDate } from 'shared/utils.mjs'
|
||||
import { controlLevels } from 'shared/config/freesewing.config.mjs'
|
||||
// Hooks
|
||||
import { useEffect, useContext, useMemo } from 'react'
|
||||
import { useContext, useMemo } from 'react'
|
||||
import { useMobileAction } from 'shared/context/mobile-menubar-context.mjs'
|
||||
import { useTranslation } from 'next-i18next'
|
||||
import { useBackend } from 'shared/hooks/use-backend.mjs'
|
||||
|
@ -99,32 +99,19 @@ export const DraftHeader = ({
|
|||
// add the zoom buttons as an action on the mobile menubar
|
||||
useMobileAction('zoom', { order: 0, actionContent: headerZoomButtons })
|
||||
|
||||
/*
|
||||
* This saves the pattern on intial load which side-steps #5534 until
|
||||
* we figure out what's causing it exactly
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (saveAs && saveAs.edit === 0) {
|
||||
savePattern(true)
|
||||
saveAs.edit++
|
||||
}
|
||||
}, [saveAs])
|
||||
|
||||
const savePattern = async (silent = false) => {
|
||||
if (!silent) setLoadingStatus([true, 'savingPattern'])
|
||||
const savePattern = async () => {
|
||||
setLoadingStatus([true, 'savingPattern'])
|
||||
const result = await backend.updatePattern(saveAs.pattern, { settings })
|
||||
if (!silent) {
|
||||
if (result.success)
|
||||
setLoadingStatus([
|
||||
true,
|
||||
<>
|
||||
{t('status:patternSaved')} <small>[#{saveAs.pattern}]</small>
|
||||
</>,
|
||||
true,
|
||||
true,
|
||||
])
|
||||
else setLoadingStatus([true, 'backendError', true, false])
|
||||
}
|
||||
if (result.success)
|
||||
setLoadingStatus([
|
||||
true,
|
||||
<>
|
||||
{t('status:patternSaved')} <small>[#{saveAs.pattern}]</small>
|
||||
</>,
|
||||
true,
|
||||
true,
|
||||
])
|
||||
else setLoadingStatus([true, 'backendError', true, false])
|
||||
}
|
||||
|
||||
const bookmarkPattern = async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue