Skip to content

Commit

Permalink
feat: v1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Jan 1, 2022
1 parent c217b3e commit 989e45b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

### v1.3.2 (2022-01-01)

- Add Comment `reviseCommentIPLocation`

### v1.3.0 (2021-12-26)

- Add `slug` field for Article
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "veact-admin",
"version": "1.3.1",
"version": "1.3.2",
"author": "Surmon",
"license": "MIT",
"repository": {
Expand Down
103 changes: 93 additions & 10 deletions src/pages/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import {
useComputed,
} from 'veact'
import { useLoading } from 'veact-use'
import { Button, Card, Input, Select, Divider, Modal, Space } from 'antd'
import { Button, Card, Input, Select, Divider, Modal, Space, message } from 'antd'
import {
DeleteOutlined,
StopOutlined,
RocketOutlined,
EditOutlined,
GlobalOutlined,
CheckOutlined,
ReloadOutlined,
} from '@ant-design/icons'
Expand All @@ -35,6 +36,7 @@ import {
GetCommentsParams,
deleteComments,
putComment,
reviseCommentIPLocation,
updateCommentsState,
} from '@/store/comment'
import {
Expand Down Expand Up @@ -190,6 +192,57 @@ export const CommentPage: React.FC = () => {
})
}

const ipLocationTask = useShallowReactive({
done: [] as string[],
fail: [] as string[],
todo: [] as string[],
running: false,
})

const doIPLocationTask = () => {
const doRevise = async (commentID: string) => {
try {
await reviseCommentIPLocation(commentID)
ipLocationTask.done.push(commentID)
} catch (error) {
ipLocationTask.fail.push(commentID)
} finally {
ipLocationTask.todo = ipLocationTask.todo
.slice()
.filter((id) => id !== commentID)
}
}

if (ipLocationTask.todo.length) {
ipLocationTask.running = true
doRevise(ipLocationTask.todo[0]).then(() => {
// 延时 3 秒
window.setTimeout(() => doIPLocationTask(), 3000)
})
} else {
ipLocationTask.running = false
const messages = [
'任务结束',
`done: ${ipLocationTask.done.length}`,
`fail: ${ipLocationTask.fail.length}`,
]
message.info(messages.join(','))
}
}

const handleReviseComemntsIPLocation = () => {
const todoCommentIDs = comment.data
.filter((c) => Boolean(c.ip) && !c.ip_location?.region_code)
.map((c) => c._id!)
if (todoCommentIDs.length) {
ipLocationTask.todo.push(...todoCommentIDs)
doIPLocationTask()
message.info(`开始任务,共 ${todoCommentIDs.length} 条数据`)
} else {
message.info('没有需要修正的数据')
}
}

useWatch(filterParams, () => fetchData())

onMounted(() => {
Expand All @@ -202,15 +255,45 @@ export const CommentPage: React.FC = () => {
bordered={false}
className={styles.comment}
extra={
<Button
type="primary"
size="small"
target="_blank"
icon={<RocketOutlined />}
href={getBlogGuestbookUrl()}
>
去留言板
</Button>
<Space>
<Button.Group>
{ipLocationTask.running && (
<Button
size="small"
onClick={() => {
Modal.info({
title: '任务详情',
content: JSON.stringify(ipLocationTask, null, 2),
})
}}
>
TODO: {ipLocationTask.todo.length}
<Divider type="vertical" />
DONE: {ipLocationTask.done.length}
<Divider type="vertical" />
FAIL: {ipLocationTask.fail.length}
</Button>
)}
<Button
size="small"
icon={<GlobalOutlined />}
disabled={ipLocationTask.running}
loading={ipLocationTask.running}
onClick={() => handleReviseComemntsIPLocation()}
>
修正本页数据 IP location
</Button>
</Button.Group>
<Button
type="primary"
size="small"
target="_blank"
icon={<RocketOutlined />}
href={getBlogGuestbookUrl()}
>
去留言板
</Button>
</Space>
}
>
<Space align="center" className={styles.toolbar}>
Expand Down
6 changes: 6 additions & 0 deletions src/store/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ export function deleteComments(commentIds: Array<string>, postIds: Array<number>
.delete(COMMENT_API_PATH, { data: { comment_ids: commentIds, post_ids: postIds } })
.then((response) => response.result)
}

export function reviseCommentIPLocation(commentID: string) {
return nodepress
.put(`${COMMENT_API_PATH}/${commentID}/ip_location`)
.then((response) => response.result)
}

0 comments on commit 989e45b

Please sign in to comment.