Skip to content

Commit

Permalink
Merge pull request #707 from thematters/fix/moment-report
Browse files Browse the repository at this point in the history
fix(report): handle moment reports
  • Loading branch information
gary02 authored Aug 27, 2024
2 parents f6128ce + edd50fb commit 50694ea
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
44 changes: 37 additions & 7 deletions src/definitions/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
GQLArticleState,
GQLUserState,
GQLCommentState,
GQLMomentState,
GQLPageInfo,
GQLUUID,
GQLUserInfo,
Expand Down Expand Up @@ -129,6 +130,7 @@ export type ArticleDigest = {
isSpam: boolean | null
}
}
__typename: 'Article'
}

export type ArticleDetail = ArticleDigest & {
Expand Down Expand Up @@ -162,6 +164,19 @@ export type CommentDigest = {
pinned: boolean
upvotes: number
downvotes: number
__typename: 'Comment'
}

/**
* Moment
*/
export type MomentDigest = {
id: string
author: UserDigest
content: string
momentState: GQLMomentState
createdAt: Date
__typename: 'Moment'
}

export type CommentDetail = CommentDigest
Expand Down Expand Up @@ -210,13 +225,28 @@ export type CampaignDetail = CampaignDigest & {
/**
* Report
*/
export type ReportDigest = {
id: string
reporter: UserDigest
target: ArticleDigest | CommentDigest
reason: string
createdAt: Date
}
export type ReportDigest =
| {
id: string
reporter: UserDigest
target: ArticleDigest
reason: string
createdAt: Date
}
| {
id: string
reporter: UserDigest
target: CommentDigest
reason: string
createdAt: Date
}
| {
id: string
reporter: UserDigest
target: MomentDigest
reason: string
createdAt: Date
}

/**
* Pagination
Expand Down
1 change: 1 addition & 0 deletions src/gql/fragments/article/digest.gql
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ fragment ArticleDigest on Article {
isSpam
}
}
__typename
}
1 change: 1 addition & 0 deletions src/gql/fragments/comment/digest.gql
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ fragment CommentDigest on Comment {
pinned
upvotes
downvotes
__typename
}
12 changes: 12 additions & 0 deletions src/gql/fragments/moment/digest.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import "../user/id.gql"

fragment MomentDigest on Moment {
id
content
momentState: state
createdAt
author {
...UserId
}
__typename
}
5 changes: 5 additions & 0 deletions src/gql/queries/reportList.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "../fragments/connection.gql"
#import "../fragments/comment/digest.gql"
#import "../fragments/article/digest.gql"
#import "../fragments/moment/digest.gql"

query OSSReportList($input: ConnectionArgs!) {
oss {
Expand All @@ -17,12 +18,16 @@ query OSSReportList($input: ConnectionArgs!) {
reason
createdAt
target {
__typename
... on Comment {
...CommentDigest
}
... on Article {
...ArticleDigest
}
... on Moment {
...MomentDigest
}
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/pages/ReportList/ReportDigestList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,33 @@ class ReportDigestList extends React.Component<
}

private _renderCommentCell(_: any, record: ReportDigest): React.ReactNode {
return 'content' in record.target ? (
console.log(record)
return record.target.__typename === 'Comment' ? (
<CommentLink id={record.target.id} content={record.target.content} />
) : null
}

private _renderArticleCell(_: any, record: ReportDigest): React.ReactNode {
return 'title' in record.target ? (
console.log(record)
return record.target.__typename === 'Article' ? (
<ArticleLink id={record.target.id} title={record.target.title} />
) : null
}

private _renderMomentCell(_: any, record: ReportDigest): React.ReactNode {
return record.target.__typename === 'Moment' ? record.target.content : null
}

private _renderStateCell(_: any, record: ReportDigest): React.ReactNode {
return 'title' in record.target ? (
return record.target.__typename === 'Article' ? (
<ArticleSetState state={record.target.state} id={record.target.id} />
) : (
) : record.target.__typename === 'Comment' ? (
<CommentSetState
commentState={record.target.commentState}
ids={[record.target.id]}
/>
) : (
record.target.momentState
)
}

Expand Down Expand Up @@ -143,6 +151,14 @@ class ReportDigestList extends React.Component<
render={this._renderArticleCell}
/>

<Table.Column<ReportDigest>
dataIndex="target.content"
title="动态"
key="id"
width={200}
render={this._renderMomentCell}
/>

<Table.Column<ReportDigest>
dataIndex="target.author"
title="評論 / 文章作者"
Expand Down

0 comments on commit 50694ea

Please sign in to comment.