From df6f23e69366cf8468f13ac45f295f25a9e53921 Mon Sep 17 00:00:00 2001 From: TomasC <49659410+tx0c@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:31:03 +0000 Subject: [PATCH] feat(new-article-path): Revise pathname of article detail page #4196 for #4196 --- src/pages/p/[shortHash].tsx | 3 +++ src/views/ArticleDetail/gql.ts | 6 ++++-- src/views/ArticleDetail/index.tsx | 11 +++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 src/pages/p/[shortHash].tsx diff --git a/src/pages/p/[shortHash].tsx b/src/pages/p/[shortHash].tsx new file mode 100644 index 0000000000..c392a789b3 --- /dev/null +++ b/src/pages/p/[shortHash].tsx @@ -0,0 +1,3 @@ +import { ArticleDetail } from '~/views/ArticleDetail' + +export default ArticleDetail diff --git a/src/views/ArticleDetail/gql.ts b/src/views/ArticleDetail/gql.ts index 0a92901fda..a2d6cf1d88 100644 --- a/src/views/ArticleDetail/gql.ts +++ b/src/views/ArticleDetail/gql.ts @@ -19,6 +19,7 @@ const articlePublicFragment = gql` title slug mediaHash + shortHash state cover summary @@ -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 } } diff --git a/src/views/ArticleDetail/index.tsx b/src/views/ArticleDetail/index.tsx index 2c6f27a5f9..dc28f330ae 100644 --- a/src/views/ArticleDetail/index.tsx +++ b/src/views/ArticleDetail/index.tsx @@ -507,14 +507,16 @@ const BaseArticleDetail = ({ ) } -const ArticleDetail = ({ +export const ArticleDetail = ({ includeTranslation, }: { includeTranslation: boolean }) => { 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) @@ -524,8 +526,8 @@ const ArticleDetail = ({ */ const isQueryByHash = !!( mediaHash && - isMediaHashPossiblyValid(mediaHash) && - !articleId + isMediaHashPossiblyValid(mediaHash) + // && !articleId ) // backward compatible with: @@ -537,6 +539,7 @@ const ArticleDetail = ({ { variables: { mediaHash, + shortHash, language: routerLang || UserLanguage.ZhHant, includeTranslation, },