Skip to content

Commit

Permalink
feat(article): query article version
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Feb 28, 2024
1 parent 99fe901 commit b7e34be
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 254 deletions.
3 changes: 3 additions & 0 deletions lang/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
"defaultMessage": "Followed",
"description": "src/components/Buttons/FollowUser/Unfollow.tsx"
},
"99OtWT": {
"defaultMessage": "Pending..."
},
"9Fpc9S": {
"defaultMessage": "Bug Report"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
"defaultMessage": "Followed",
"description": "src/components/Buttons/FollowUser/Unfollow.tsx"
},
"99OtWT": {
"defaultMessage": "Pending..."
},
"9Fpc9S": {
"defaultMessage": "Bug Report"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
"defaultMessage": "已追踪",
"description": "src/components/Buttons/FollowUser/Unfollow.tsx"
},
"99OtWT": {
"defaultMessage": "写入中…"
},
"9Fpc9S": {
"defaultMessage": "漏洞报告"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
"defaultMessage": "已追蹤",
"description": "src/components/Buttons/FollowUser/Unfollow.tsx"
},
"99OtWT": {
"defaultMessage": "寫入中…"
},
"9Fpc9S": {
"defaultMessage": "漏洞提報"
},
Expand Down
5 changes: 4 additions & 1 deletion src/common/utils/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ToPathArgs =
page: 'articleDetail'
article: ArticleArgs
collectionId?: string
versionId?: string
}
| {
page:
Expand Down Expand Up @@ -116,7 +117,9 @@ export const toPath = (
mediaHash ? '-' + mediaHash : ''
}`
}
if (!!args.collectionId) {
if (!!args.versionId) {
href = `${href}/revision?version=${args.versionId}`
} else if (!!args.collectionId) {
href = `${href}?collection=${args.collectionId}`
}
} catch (err) {
Expand Down
21 changes: 5 additions & 16 deletions src/views/ArticleDetail/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useContext, useEffect, useRef, useState } from 'react'
import { TEST_ID } from '~/common/enums'
import { captureClicks, initAudioPlayers, optimizeEmbed } from '~/common/utils'
import { useMutation, ViewerContext } from '~/components'
import { ContentArticleFragment, ReadArticleMutation } from '~/gql/graphql'
import { ReadArticleMutation } from '~/gql/graphql'

import styles from './styles.module.css'

Expand All @@ -19,11 +19,11 @@ const READ_ARTICLE = gql`
`

const Content = ({
article,
articleId,
content,
translating,
}: {
article: ContentArticleFragment
articleId: string
content: string
translating?: boolean
}) => {
Expand Down Expand Up @@ -88,12 +88,12 @@ const Content = ({

// if user is logged in, ReadArticle mutation will be invoked multiple times
if (viewer.isAuthed && isReading()) {
read({ variables: { id: article.id } })
read({ variables: { id: articleId } })
}

// if visitor, invoke ReadArticle mutation only once
if (!viewer.isAuthed && !visitorReadRef.current) {
read({ variables: { id: article.id } })
read({ variables: { id: articleId } })
visitorReadRef.current = true
}
return heartbeat
Expand Down Expand Up @@ -125,15 +125,4 @@ const Content = ({
)
}

Content.fragments = {
article: gql`
fragment ContentArticle on Article {
id
contents {
html
}
}
`,
}

export default Content
7 changes: 7 additions & 0 deletions src/views/ArticleDetail/MetaInfo/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export const fragments = {
access {
type
}
language
slug
mediaHash
author {
id
userName
}
...FingerprintArticle
}
${FingerprintButton.fragments.article}
Expand Down
4 changes: 2 additions & 2 deletions src/views/ArticleDetail/MetaInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
UserDigest,
ViewerContext,
} from '~/components'
import { ArticleDetailPublicQuery } from '~/gql/graphql'
import { MetaInfoArticleFragment } from '~/gql/graphql'

import FingerprintButton from './FingerprintButton'
import { fragments } from './gql'
import styles from './styles.module.css'
import TranslationButton from './TranslationButton'

type MetaInfoProps = {
article: NonNullable<ArticleDetailPublicQuery['article']>
article: MetaInfoArticleFragment
translated: boolean
canTranslate: boolean
toggleTranslate: () => any
Expand Down
16 changes: 12 additions & 4 deletions src/views/ArticleDetail/Revision/InfoHeader/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ import { UserDigest } from '~/components'

export const fragments = {
article: gql`
fragment InfoHeader on Article {
fragment InfoHeaderArticle on Article {
id
author {
id
...UserDigestMiniUser
}
mediaHash
dataHash
iscnId
createdAt
access {
type
secret
}
}
${UserDigest.Mini.fragments.user}
`,
articleVersion: gql`
fragment InfoHeaderArticleVersion on ArticleVersion {
id
dataHash
mediaHash
summary
createdAt
description
}
`,
}
Loading

0 comments on commit b7e34be

Please sign in to comment.