1
0
Fork 0

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:
joostdecock 2023-12-09 16:11:09 +01:00
parent 031be5820b
commit d442e23d69
3 changed files with 16 additions and 30 deletions

View file

@ -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 () => {