fix update
This commit is contained in:
@@ -22,27 +22,33 @@ const Editor: FC = () => {
|
||||
}
|
||||
}, [])
|
||||
const [isLayersPanelOpen, setIsLayersPanelOpen] = useState(false)
|
||||
const [isInitialContentReady, setIsInitialContentReady] = useState(false)
|
||||
const { loadPages, pages, documentSettings } = useEditorStore()
|
||||
const { data } = useGetCatalogById(id!)
|
||||
const { data, isFetched } = useGetCatalogById(id!)
|
||||
const { scheduleUpdate, isSaving } = useUpdateCatalog()
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.data && data?.data?.content) {
|
||||
const json = JSON.parse(data?.data?.content)
|
||||
if (!json) return
|
||||
if (!isFetched) return
|
||||
|
||||
if (data?.data?.content) {
|
||||
try {
|
||||
const json = JSON.parse(data.data.content)
|
||||
if (Array.isArray(json)) {
|
||||
loadPages(json)
|
||||
} else if (json.pages) {
|
||||
} else if (json?.pages) {
|
||||
loadPages(json.pages, json.documentSettings)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Invalid catalog content JSON:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [data?.data])
|
||||
setIsInitialContentReady(true)
|
||||
}, [data?.data?.content, isFetched, loadPages])
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return
|
||||
if (!isInitialContentReady) return
|
||||
if (!pages || pages.length === 0) return
|
||||
|
||||
scheduleUpdate({
|
||||
@@ -51,7 +57,7 @@ const Editor: FC = () => {
|
||||
})
|
||||
// عمداً scheduleUpdate را در وابستگیها نیاوردیم تا از لوپ ذخیرهسازی جلوگیری شود
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id, pages, documentSettings])
|
||||
}, [id, isInitialContentReady, pages, documentSettings])
|
||||
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user