Skip to content

Commit

Permalink
fix(article): fix default version from route query
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Mar 4, 2024
1 parent 5223800 commit b3b9b5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions src/views/ArticleDetail/Revision/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -245,7 +245,7 @@ const ArticleDetailRevision = ({
{
variables: {
mediaHash,
version: currVersion || latestVersion,
version: currVersion,
},
skip: !isQueryByHash,
}
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit b3b9b5c

Please sign in to comment.