diff --git a/src/views/ArticleDetail/Revision/Versions/VersionsDropdown/index.tsx b/src/views/ArticleDetail/Revision/Versions/VersionsDropdown/index.tsx index 573a822d7f..c6dae977a5 100644 --- a/src/views/ArticleDetail/Revision/Versions/VersionsDropdown/index.tsx +++ b/src/views/ArticleDetail/Revision/Versions/VersionsDropdown/index.tsx @@ -56,9 +56,9 @@ const VersionsDropdown = ({ article: VersionsArticleFragment }) => { const { getQuery } = useRoute() - const currVersion = getQuery('version') const versions = article.versions.edges.map((edge) => edge?.node!) + const currVersion = getQuery('version') || versions[0]?.id const version = versions.find((v) => v.id === currVersion) if (versions.length < 1 || !version) { diff --git a/src/views/ArticleDetail/Revision/Versions/VersionsSidebar/index.tsx b/src/views/ArticleDetail/Revision/Versions/VersionsSidebar/index.tsx index e21d6ffabf..9953811ac0 100644 --- a/src/views/ArticleDetail/Revision/Versions/VersionsSidebar/index.tsx +++ b/src/views/ArticleDetail/Revision/Versions/VersionsSidebar/index.tsx @@ -11,9 +11,9 @@ import styles from './styles.module.css' const VersionsSidebar = ({ article }: { article: VersionsArticleFragment }) => { const { getQuery } = useRoute() - const currVersion = getQuery('version') const versions = article.versions.edges.map((edge) => edge?.node!) + const currVersion = getQuery('version') || versions[0]?.id if (versions.length < 1) { return null diff --git a/src/views/ArticleDetail/Revision/index.tsx b/src/views/ArticleDetail/Revision/index.tsx index f7158c4bf0..fc12941553 100644 --- a/src/views/ArticleDetail/Revision/index.tsx +++ b/src/views/ArticleDetail/Revision/index.tsx @@ -222,7 +222,7 @@ const ArticleDetailRevision = ({ }) => { const { getQuery, router } = useRoute() const mediaHash = getQuery('mediaHash') - const currVersion = getQuery('version') + const currVersion = getQuery('version') || latestVersion const articleId = (router.query.mediaHash as string)?.match(/^(\d+)/)?.[1] || '' const viewer = useContext(ViewerContext) @@ -245,7 +245,7 @@ const ArticleDetailRevision = ({ { variables: { mediaHash, - version: currVersion || latestVersion, + version: currVersion, }, skip: !isQueryByHash, } @@ -255,17 +255,13 @@ const ArticleDetailRevision = ({ { variables: { id: toGlobalId({ type: 'Article', id: articleId }), - version: currVersion || latestVersion, + version: currVersion, }, skip: isQueryByHash, } ) - const { - data, - client, - refetch: refetchPublic, - } = resultByHash.data ? resultByHash : resultByNodeId + const { data, client } = resultByHash.data ? resultByHash : resultByNodeId const loading = resultByHash.loading || resultByNodeId.loading const error = resultByHash.error || resultByNodeId.error @@ -289,12 +285,10 @@ const ArticleDetailRevision = ({ } useEffect(() => { - // refetch data when URL query is changed ;(async () => { - await refetchPublic() await loadPrivate() })() - }, [mediaHash, currVersion]) + }, [article?.id, currVersion]) /** * Render:Loading