Skip to content

Commit

Permalink
feat(article): add featured field
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Oct 8, 2023
1 parent a010510 commit ca035ae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/constants/article/index.ts
Expand Up @@ -29,6 +29,7 @@ export interface Article {
public: ArticlePublic
state: PublishState
lang: ArticleLanguage
featured: boolean
disabled_comments: boolean
meta?: {
likes: number
Expand Down
28 changes: 18 additions & 10 deletions src/pages/Article/Editor/State.tsx
@@ -1,5 +1,5 @@
import React from 'react'
import { Button, Form, Select, Divider, Space, Radio, FormInstance } from 'antd'
import { Button, Form, Select, Divider, Space, Switch, FormInstance } from 'antd'
import * as Icon from '@ant-design/icons'
import { publishStates } from '@/constants/publish'
import { articleOrigins } from '@/constants/article/origin'
Expand Down Expand Up @@ -90,15 +90,23 @@ export const StateForm: React.FC<StateFormProps> = (props) => {
})}
/>
</Form.Item>
<Form.Item required={true} name="disabled_comments" label="文章评论" rules={[requiredRule]}>
<Radio.Group style={{ width: '100%' }}>
<Radio.Button value={false} style={{ width: '50%', whiteSpace: 'nowrap' }}>
<Icon.CheckCircleOutlined /> 允许
</Radio.Button>
<Radio.Button value={true} style={{ width: '50%', whiteSpace: 'nowrap' }}>
<Icon.StopOutlined /> 禁止
</Radio.Button>
</Radio.Group>
<Form.Item
required={true}
name="featured"
label="精选文章"
rules={[requiredRule]}
valuePropName="checked"
>
<Switch checkedChildren="是" unCheckedChildren="否" style={{ width: 50 }} />
</Form.Item>
<Form.Item
required={true}
name="disabled_comments"
label="禁止评论"
rules={[requiredRule]}
valuePropName="checked"
>
<Switch checkedChildren="是" unCheckedChildren="否" style={{ width: 50 }} />
</Form.Item>
<Divider />
<Button
Expand Down
1 change: 1 addition & 0 deletions src/pages/Article/Editor/index.tsx
Expand Up @@ -42,6 +42,7 @@ const DEFAULT_ARTICLE: Article = Object.freeze({
state: PublishState.Published,
public: ArticlePublic.Public,
lang: ArticleLanguage.Chinese,
featured: false,
disabled_comments: false,
tags: [],
categories: [],
Expand Down
10 changes: 10 additions & 0 deletions src/pages/Article/List/index.tsx
Expand Up @@ -43,6 +43,7 @@ const DEFAULT_FILTER_PARAMS = Object.freeze({
sort: SortTypeWithHot.Desc,
tag_slug: SELECT_ALL_VALUE as SelectAllType | string,
category_slug: SELECT_ALL_VALUE as SelectAllType | string,
featured: SELECT_ALL_VALUE as SelectAllType | boolean,
lang: SELECT_ALL_VALUE as SelectAllType | ArticleLanguage,
public: SELECT_ALL_VALUE as SelectAllType | ArticlePublic,
origin: SELECT_ALL_VALUE as SelectAllType | ArticleOrigin,
Expand Down Expand Up @@ -163,6 +164,15 @@ export const ArticleList: React.FC = () => {
<Space className={styles.toolbar} align="center" wrap>
<Space direction="vertical">
<Space wrap>
<Button
type={filterParams.featured === true ? 'primary' : 'default'}
icon={filterParams.featured === true ? <Icon.StarFilled /> : <Icon.StarOutlined />}
onClick={() => {
filterParams.featured = filterParams.featured === true ? SELECT_ALL_VALUE : true
}}
>
精选文章
</Button>
<Select
className={styles.select}
loading={loading.state.value}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Article/List/style.module.less
Expand Up @@ -9,14 +9,14 @@
.select {
width: 120px;
}
.categoriesSelect {
width: 136px;
}
.tagSelect {
width: 160px;
}
.search {
width: 280px;
}
.categoriesSelect {
width: 230px;
}
}
}

0 comments on commit ca035ae

Please sign in to comment.