Skip to content

Commit

Permalink
feat(new-article-path): Revise pathname of article detail page #4196
Browse files Browse the repository at this point in the history
for #4196
  • Loading branch information
tx0c authored and TomasC committed Mar 6, 2024
1 parent d1683e5 commit fdd28a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/pages/p/[shortHash].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ArticleDetailOuterByShortHash } from '~/views/ArticleDetail'

export default ArticleDetailOuterByShortHash
6 changes: 4 additions & 2 deletions src/views/ArticleDetail/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const articlePublicFragment = gql`
title
slug
mediaHash
shortHash
state
cover
summary
Expand Down Expand Up @@ -115,12 +116,13 @@ export const ARTICLE_AVAILABLE_TRANSLATIONS_BY_NODE_ID = gql`

export const ARTICLE_DETAIL_PUBLIC = gql`
query ArticleDetailPublic(
$mediaHash: String!
$mediaHash: String
$shortHash: String
$language: UserLanguage!
$includeTranslation: Boolean = false
$includeCanSuperLike: Boolean = true
) {
article(input: { mediaHash: $mediaHash }) {
article(input: { mediaHash: $mediaHash, shortHash: $shortHash }) {
...ArticlePublicArticle
}
}
Expand Down
37 changes: 34 additions & 3 deletions src/views/ArticleDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ const ArticleDetail = ({
}) => {
const { getQuery, router, routerLang } = useRoute()
const [needRefetchData, setNeedRefetchData] = useState(false)
const mediaHash = getQuery('mediaHash')

const shortHash = getQuery('shortHash')
const mediaHash = getQuery('mediaHash') // will delete by mediaHash & by articleId logic in later PR
const articleId =
(router.query.mediaHash as string)?.match(/^(\d+)/)?.[1] || ''
const viewer = useContext(ViewerContext)
Expand All @@ -524,8 +526,8 @@ const ArticleDetail = ({
*/
const isQueryByHash = !!(
mediaHash &&
isMediaHashPossiblyValid(mediaHash) &&
!articleId
isMediaHashPossiblyValid(mediaHash)
// && !articleId
)

// backward compatible with:
Expand All @@ -537,6 +539,7 @@ const ArticleDetail = ({
{
variables: {
mediaHash,
shortHash,
language: routerLang || UserLanguage.ZhHant,
includeTranslation,
},
Expand Down Expand Up @@ -807,4 +810,32 @@ const ArticleDetailOuter = () => {
return <ArticleDetail includeTranslation={includeTranslation} />
}

export const ArticleDetailOuterByShortHash = () => {
const { getQuery, router, routerLang } = useRoute()

Check failure on line 814 in src/views/ArticleDetail/index.tsx

View workflow job for this annotation

GitHub Actions / build

'router' is declared but its value is never read.
const shortHash = getQuery('shortHash')

Check failure on line 815 in src/views/ArticleDetail/index.tsx

View workflow job for this annotation

GitHub Actions / build

'shortHash' is declared but its value is never read.

const resultByHash = usePublicQuery<ArticleAvailableTranslationsQuery>(
ARTICLE_AVAILABLE_TRANSLATIONS,
{ variables: { mediaHash }, skip: !isQueryByHash }

Check failure on line 819 in src/views/ArticleDetail/index.tsx

View workflow job for this annotation

GitHub Actions / build

No value exists in scope for the shorthand property 'mediaHash'. Either declare one or provide an initializer.

Check failure on line 819 in src/views/ArticleDetail/index.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'isQueryByHash'.
)
const { data } = resultByHash // : resultByNodeId
const loading = resultByHash.loading // || resultByNodeId.loading
const includeTranslation =
!!routerLang &&
(data?.article?.availableTranslations || []).includes(routerLang)

/**
* Rendering
*/
if (loading) {
return (
<Layout.Main aside={<AuthorSidebar.Placeholder />}>
<Placeholder />
</Layout.Main>
)
}

return <ArticleDetail includeTranslation={includeTranslation} />
}

export default ArticleDetailOuter

0 comments on commit fdd28a2

Please sign in to comment.