Skip to content

Commit

Permalink
feat(article): remove unused queries
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed May 2, 2024
1 parent 9ea690a commit 9066e25
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/components/Forms/PaymentForm/PayTo/Confirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const Confirm: React.FC<FormProps> = ({
update: (cache, result) => {
updateDonation({
cache,
id: article.id,
shortHash: article.shortHash,
viewer,
txId: result.data?.payTo.transaction.id,
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const SetAmount: React.FC<FormProps> = ({
update: (cache) => {
updateDonation({
cache,
id: article.id,
shortHash: article.shortHash,
viewer,
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/PaymentForm/Processing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const USDTProcessingForm: React.FC<Props> = ({
update: (cache, result) => {
updateDonation({
cache,
id: article.id,
shortHash: article.shortHash,
viewer: isConnectedAddress ? viewer : undefined,
txId: result.data?.payTo.transaction.id,
})
Expand Down
24 changes: 11 additions & 13 deletions src/components/GQL/updates/appreciation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@ import { DataProxy } from 'apollo-cache'
import _cloneDeep from 'lodash/cloneDeep'
import _some from 'lodash/some'

import { ArticleDetailPublicByNodeIdQuery } from '~/gql/graphql'
import { ArticleDetailPublicQuery } from '~/gql/graphql'

export const updateAppreciation = ({
cache,
left,
id,
shortHash,
total,
viewer,
canSuperLike,
}: {
cache: DataProxy
left: number
id: string
shortHash: string
total: number
viewer: any
canSuperLike?: boolean
}) => {
const {
ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
} = require('~/views/ArticleDetail/gql')
const { ARTICLE_DETAIL_PUBLIC } = require('~/views/ArticleDetail/gql')

try {
if (!id) {
if (!shortHash) {
return
}

// read from local cache
const cacheData = _cloneDeep(
cache.readQuery<ArticleDetailPublicByNodeIdQuery>({
query: ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
variables: { id },
cache.readQuery<ArticleDetailPublicQuery>({
query: ARTICLE_DETAIL_PUBLIC,
variables: { shortHash },
})
)

Expand All @@ -42,7 +40,7 @@ export const updateAppreciation = ({

// update counts
const article = cacheData.article as NonNullable<
ArticleDetailPublicByNodeIdQuery['article']
ArticleDetailPublicQuery['article']
> & { __typename: 'Article' }
article.appreciateLeft = left
article.likesReceivedTotal = total
Expand All @@ -55,9 +53,9 @@ export const updateAppreciation = ({

// write to local cache
cache.writeQuery({
query: ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
query: ARTICLE_DETAIL_PUBLIC,
data: cacheData,
variables: { id },
variables: { shortHash },
})
} catch (e) {
console.error(e)
Expand Down
16 changes: 7 additions & 9 deletions src/components/GQL/updates/donation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ import { ArticleDetailPublicQuery } from '~/gql/graphql'

export const updateDonation = ({
cache,
id,
shortHash,
viewer,
txId,
}: {
cache: DataProxy
id: string
shortHash: string
viewer?: Viewer
txId?: string
}) => {
const {
ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
} = require('~/views/ArticleDetail/gql')
const { ARTICLE_DETAIL_PUBLIC } = require('~/views/ArticleDetail/gql')

try {
if (!id || !txId) {
if (!shortHash || !txId) {
return
}

// read from local cache
const variables = { id }
const variables = { shortHash }
const cacheData = _cloneDeep(
cache.readQuery<ArticleDetailPublicQuery>({
query: ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
query: ARTICLE_DETAIL_PUBLIC,
variables,
})
)
Expand Down Expand Up @@ -86,7 +84,7 @@ export const updateDonation = ({

// write to local cache
cache.writeQuery({
query: ARTICLE_DETAIL_PUBLIC_BY_NODE_ID,
query: ARTICLE_DETAIL_PUBLIC,
data: cacheData,
variables,
})
Expand Down
1 change: 1 addition & 0 deletions src/views/ArticleDetail/AppreciationButton/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const fragments = {
public: gql`
fragment AppreciationButtonArticlePublic on Article {
id
shortHash
author {
id
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/ArticleDetail/AppreciationButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const AppreciationButton = ({
updateAppreciation({
cache,
left,
id: article.id,
shortHash: article.shortHash,
total,
viewer,
canSuperLike: false,
Expand Down
50 changes: 7 additions & 43 deletions src/views/ArticleDetail/History/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,14 @@ export const ARTICLE_HISTORY_PUBLIC = gql`
${articleVersionFragment}
`

export const ARTICLE_HISTORY_PUBLIC_BY_NODE_ID = gql`
query ArticleHistoryPublicByNodeId($id: ID!, $version: ID!) {
article: node(input: { id: $id }) {
... on Article {
...ArticleHistoryPublicArticle
}
}
version: node(input: { id: $version }) {
... on ArticleVersion {
...ArticleVersion
}
}
}
${articleHistoryPublicFragment}
${articleVersionFragment}
`

export const ARTICLE_HISTORY_PRIVATE = gql`
query ArticleHistoryPrivate($id: ID!, $version: ID!) {
article: node(input: { id: $id }) {
... on Article {
id
access {
circle {
id
...CircleWallCirclePrivate
}
query ArticleHistoryPrivate($shortHash: String!, $version: ID!) {
article(input: { shortHash: $shortHash }) {
id
access {
circle {
id
...CircleWallCirclePrivate
}
}
}
Expand Down Expand Up @@ -131,23 +112,6 @@ export const ARTICLE_LATEST_VERSION = gql`
}
`

export const ARTICLE_LATEST_VERSION_BY_NODE_ID = gql`
query ArticleLatestVersionByNodeId($id: ID!) {
article: node(input: { id: $id }) {
... on Article {
id
versions(input: { first: 1 }) {
edges {
node {
id
}
}
}
}
}
}
`

export const ARTICLE_HISTORY_TRANSLATION = gql`
query ArticleHistoryTranslation($version: ID!, $language: UserLanguage!) {
version: node(input: { id: $version }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const Donators = ({
>
<section className={styles.avatarList}>
{frontDonators.map((user, index) => (
<>
<Fragment key={index}>
{index < maxAvatarNum && (
<Fragment key={index}>
<Fragment>
<AvatarItem user={user || undefined} />
</Fragment>
)}
Expand All @@ -82,7 +82,7 @@ const Donators = ({
{donatorsCount - maxAvatarNum > 99 && <>99+</>}
</span>
)}
</>
</Fragment>
))}
</section>
{isAuthor && donatorsCount > 0 && (
Expand Down
27 changes: 0 additions & 27 deletions src/views/ArticleDetail/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ export const ARTICLE_AVAILABLE_TRANSLATIONS = gql`
}
`

export const ARTICLE_AVAILABLE_TRANSLATIONS_BY_NODE_ID = gql`
query ArticleAvailableTranslationsByNodeId($id: ID!) {
article: node(input: { id: $id }) {
... on Article {
id
availableTranslations
}
}
}
`

export const ARTICLE_DETAIL_PUBLIC = gql`
query ArticleDetailPublic(
$shortHash: String
Expand All @@ -125,22 +114,6 @@ export const ARTICLE_DETAIL_PUBLIC = gql`
${articlePublicFragment}
`

export const ARTICLE_DETAIL_PUBLIC_BY_NODE_ID = gql`
query ArticleDetailPublicByNodeId(
$id: ID!
$language: UserLanguage!
$includeTranslation: Boolean = false
$includeCanSuperLike: Boolean = true
) {
article: node(input: { id: $id }) {
... on Article {
...ArticlePublicArticle
}
}
}
${articlePublicFragment}
`

export const ARTICLE_DETAIL_PRIVATE = gql`
query ArticleDetailPrivate($id: ID!, $includeCanSuperLike: Boolean!) {
article: node(input: { id: $id }) {
Expand Down

0 comments on commit 9066e25

Please sign in to comment.