Skip to content

Commit

Permalink
feat(campaign): query multi-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Jul 15, 2024
1 parent 73b1d1f commit 7c3b7cb
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 19 deletions.
7 changes: 6 additions & 1 deletion src/components/Campaign/DigestList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class CampaignDigestList extends React.Component<
}

private _renderNameCell(_: any, record: CampaignDigest): React.ReactNode {
return <CampaignLink shortHash={record.shortHash} name={record.name} />
return (
<CampaignLink
shortHash={record.shortHash}
name={record.name || '未命名'}
/>
)
}

private _renderStateCell(_: any, record: CampaignDigest): React.ReactNode {
Expand Down
20 changes: 16 additions & 4 deletions src/definitions/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
GQLIcymiTopic,
GQLUserRestrictionType,
GQLCampaignState,
GQLDatetimeRangeInput,
GQLDatetimeRange,
GQLCampaignStage,
} from './schema'

Expand Down Expand Up @@ -168,16 +168,28 @@ export type CampaignDigest = {
id: string
shortHash: string
name: string
nameEn: string
nameZhHans: string
state: GQLCampaignState
applicationPeriod: GQLDatetimeRangeInput
writingPeriod: GQLDatetimeRangeInput
applicationPeriod: GQLDatetimeRange
writingPeriod: GQLDatetimeRange
}

type CampaignStage = {
id: string
name: string
nameEn: string
nameZhHans: string
period?: GQLDatetimeRange
}

export type CampaignDetail = CampaignDigest & {
description: string
descriptionEn: string
descriptionZhHans: string
cover: string
link: string
stages: Array<GQLCampaignStage>
stages: Array<CampaignStage>
participants: Connection<UserDigest>
articles: Connection<ArticleDigest>
}
Expand Down
42 changes: 35 additions & 7 deletions src/definitions/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ export type GQLCampaignInput = {
shortHash: Scalars['String']['input']
}

export type GQLCampaignParticipantsInput = {
after?: InputMaybe<Scalars['String']['input']>
first?: InputMaybe<Scalars['Int']['input']>
/** return all state participants */
oss?: InputMaybe<Scalars['Boolean']['input']>
}

export type GQLCampaignStage = {
__typename?: 'CampaignStage'
id: Scalars['ID']['output']
Expand Down Expand Up @@ -1392,6 +1399,7 @@ export type GQLEmailLoginInput = {
export type GQLEntityType =
| 'announcement'
| 'article'
| 'campaign'
| 'circle'
| 'collection'
| 'draft'
Expand Down Expand Up @@ -4193,7 +4201,7 @@ export type GQLWriting = GQLArticle | GQLMoment
export type GQLWritingChallenge = GQLCampaign &
GQLNode & {
__typename?: 'WritingChallenge'
applicationPeriod: GQLDatetimeRange
applicationPeriod?: Maybe<GQLDatetimeRange>
applicationState?: Maybe<GQLCampaignApplicationState>
articles: GQLArticleConnection
cover?: Maybe<Scalars['String']['output']>
Expand All @@ -4205,15 +4213,23 @@ export type GQLWritingChallenge = GQLCampaign &
shortHash: Scalars['String']['output']
stages: Array<GQLCampaignStage>
state: GQLCampaignState
writingPeriod: GQLDatetimeRange
writingPeriod?: Maybe<GQLDatetimeRange>
}

export type GQLWritingChallengeArticlesArgs = {
input: GQLCampaignArticlesInput
}

export type GQLWritingChallengeDescriptionArgs = {
input?: InputMaybe<GQLTranslationArgs>
}

export type GQLWritingChallengeNameArgs = {
input?: InputMaybe<GQLTranslationArgs>
}

export type GQLWritingChallengeParticipantsArgs = {
input: GQLConnectionArgs
input: GQLCampaignParticipantsInput
}

export type GQLWritingConnection = GQLConnection & {
Expand Down Expand Up @@ -4599,6 +4615,7 @@ export type GQLResolversTypes = ResolversObject<{
Omit<GQLCampaignEdge, 'node'> & { node: GQLResolversTypes['Campaign'] }
>
CampaignInput: GQLCampaignInput
CampaignParticipantsInput: GQLCampaignParticipantsInput
CampaignStage: ResolverTypeWrapper<CampaignStageModel>
CampaignStageInput: GQLCampaignStageInput
CampaignState: GQLCampaignState
Expand Down Expand Up @@ -5200,6 +5217,7 @@ export type GQLResolversParentTypes = ResolversObject<{
node: GQLResolversParentTypes['Campaign']
}
CampaignInput: GQLCampaignInput
CampaignParticipantsInput: GQLCampaignParticipantsInput
CampaignStage: CampaignStageModel
CampaignStageInput: GQLCampaignStageInput
CampaignsInput: GQLCampaignsInput
Expand Down Expand Up @@ -9597,7 +9615,7 @@ export type GQLWritingChallengeResolvers<
ParentType extends GQLResolversParentTypes['WritingChallenge'] = GQLResolversParentTypes['WritingChallenge']
> = ResolversObject<{
applicationPeriod?: Resolver<
GQLResolversTypes['DatetimeRange'],
Maybe<GQLResolversTypes['DatetimeRange']>,
ParentType,
ContextType
>
Expand All @@ -9613,10 +9631,20 @@ export type GQLWritingChallengeResolvers<
RequireFields<GQLWritingChallengeArticlesArgs, 'input'>
>
cover?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>
description?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>
description?: Resolver<
GQLResolversTypes['String'],
ParentType,
ContextType,
Partial<GQLWritingChallengeDescriptionArgs>
>
id?: Resolver<GQLResolversTypes['ID'], ParentType, ContextType>
link?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>
name?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>
name?: Resolver<
GQLResolversTypes['String'],
ParentType,
ContextType,
Partial<GQLWritingChallengeNameArgs>
>
participants?: Resolver<
GQLResolversTypes['UserConnection'],
ParentType,
Expand All @@ -9631,7 +9659,7 @@ export type GQLWritingChallengeResolvers<
>
state?: Resolver<GQLResolversTypes['CampaignState'], ParentType, ContextType>
writingPeriod?: Resolver<
GQLResolversTypes['DatetimeRange'],
Maybe<GQLResolversTypes['DatetimeRange']>,
ParentType,
ContextType
>
Expand Down
8 changes: 6 additions & 2 deletions src/gql/fragments/campaign/detail.gql
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
fragment CampaignDetail on WritingChallenge {
id
...CampaignDigest
description
description(input: { language: zh_hant })
descriptionEn: description(input: { language: en })
descriptionZhHans: description(input: { language: zh_hans })
cover
link
stages {
id
name
name(input: { language: zh_hant })
nameEn: name(input: { language: en })
nameZhHans: name(input: { language: zh_hans })
period {
start
end
Expand Down
4 changes: 3 additions & 1 deletion src/gql/fragments/campaign/digest.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
fragment CampaignDigest on WritingChallenge {
id
name
name(input: { language: zh_hant })
nameEn: name(input: { language: en })
nameZhHans: name(input: { language: zh_hans })
shortHash
state
applicationPeriod {
Expand Down
28 changes: 24 additions & 4 deletions src/pages/CampaignDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class CampaignDetail extends React.Component<CampaignDetailChildProps> {

return (
<>
<DescriptionList size="large" title="基本資訊" col={3}>
<Description term="標題(繁體)">{campaign.nameEn}</Description>
<Description term="標題(英文)">{campaign.nameEn}</Description>
<Description term="標題(簡體)">{campaign.nameZhHans}</Description>
</DescriptionList>

<DescriptionList size="large" title="簡介" col={2}>
<Description term="報名期">
<DateTime date={campaign.applicationPeriod.start} /> ~{' '}
Expand Down Expand Up @@ -93,7 +99,9 @@ class CampaignDetail extends React.Component<CampaignDetailChildProps> {
<DescriptionList size="large" title="投稿選項" col={1}>
{campaign.stages.map((s) => (
<Description term="" key={s.id}>
<LevelTag level={LevelEnum.NULL}>{s.name}</LevelTag>
<LevelTag level={LevelEnum.NULL}>{s.name}(繁)</LevelTag>
<LevelTag level={LevelEnum.NULL}>{s.nameEn} (英)</LevelTag>
<LevelTag level={LevelEnum.NULL}>{s.nameZhHans}(簡)</LevelTag>
{s.period ? (
<>
<DateTime date={s.period?.start} /> ~{' '}
Expand All @@ -105,12 +113,24 @@ class CampaignDetail extends React.Component<CampaignDetailChildProps> {
</DescriptionList>
<Divider size="large" />

<DescriptionList size="large" title="簡介">
<Col span={24} style={{ marginBottom: 16 }}>
<DescriptionList size="large" title="簡介" col={1}>
<Description term="繁體">
<section
dangerouslySetInnerHTML={{ __html: campaign.description }}
/>
</Col>
</Description>

<Description term="英文">
<section
dangerouslySetInnerHTML={{ __html: campaign.descriptionEn }}
/>
</Description>

<Description term="簡體">
<section
dangerouslySetInnerHTML={{ __html: campaign.descriptionZhHans }}
/>
</Description>
</DescriptionList>
<Divider size="large" />

Expand Down

0 comments on commit 7c3b7cb

Please sign in to comment.