diff --git a/src/components/Editor/SetCover/Uploader.tsx b/src/components/Editor/SetCover/Uploader.tsx index bc93bd0f8e..0015e10686 100644 --- a/src/components/Editor/SetCover/Uploader.tsx +++ b/src/components/Editor/SetCover/Uploader.tsx @@ -10,7 +10,7 @@ import { ASSET_TYPE, ENTITY_TYPE, } from '~/common/enums' -import { sleep, validateImage } from '~/common/utils' +import { validateImage } from '~/common/utils' import { DraftDetailStateContext, Icon, @@ -55,13 +55,14 @@ const Uploader: React.FC = ({ const [upload, { loading }] = useMutation( DIRECT_IMAGE_UPLOAD, + undefined, + { showToast: false } + ) + const [directImageUploadDone] = useMutation( + DIRECT_IMAGE_UPLOAD_DONE, { update: async (cache, { data }) => { if (data?.directImageUpload) { - // FIXME: newly uploaded images will return 404 in a short time - // https://community.cloudflare.com/t/new-uploaded-images-need-about-10-min-to-display-in-my-website/121568 - await sleep(300) - updateDraftAssets({ cache, id: entityId, @@ -72,11 +73,6 @@ const Uploader: React.FC = ({ }, { showToast: false } ) - const [directImageUploadDone] = useMutation( - DIRECT_IMAGE_UPLOAD_DONE, - undefined, - { showToast: false } - ) const { upload: uploadImage, uploading } = useDirectImageUpload() const { isInPath } = useRoute() diff --git a/src/views/ArticleDetail/Edit/index.tsx b/src/views/ArticleDetail/Edit/index.tsx index 08f42efdbc..1b88e284ab 100644 --- a/src/views/ArticleDetail/Edit/index.tsx +++ b/src/views/ArticleDetail/Edit/index.tsx @@ -1,7 +1,7 @@ import { useQuery } from '@apollo/react-hooks' import _omit from 'lodash/omit' import dynamic from 'next/dynamic' -import { useContext, useState } from 'react' +import { useContext, useEffect, useState } from 'react' import { ASSET_TYPE, @@ -86,6 +86,10 @@ const BaseEdit = ({ article }: { article: Article }) => { // cover const [assets, setAssets] = useState(article.assets || []) + + useEffect(() => { + setAssets(article.assets || []) + }, [article.assets]) const [cover, setCover] = useState( assets.find((asset) => asset.path === article.cover) )