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