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 df6f23e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 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 { ArticleDetail } from '~/views/ArticleDetail'

export default ArticleDetail
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
11 changes: 7 additions & 4 deletions src/views/ArticleDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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

0 comments on commit df6f23e

Please sign in to comment.