Skip to content

Let's use AI to Earn!

refactor(web): To avoid duplicate clicks during posting, ensure ID uniqueness, and add an "Post Now" function. (#193)

布莱恩·奥夫托·杰森张6914cc5ed92b
diff --git a/project/web/src/app/i18n/locales/en/publish.json b/project/web/src/app/i18n/locales/en/publish.json
index bb9843d9..987161a9 100644
--- a/project/web/src/app/i18n/locales/en/publish.json
+++ b/project/web/src/app/i18n/locales/en/publish.json
@@ -8,7 +8,7 @@
"customizePerAccount": "Customize per account",
"cancelPublish": "Cancel Publish",
"schedulePublish": "Schedule Publish",
- "publishNow": "Publish now",
+ "publishNow": "Now",
"copyLink": "Copy link",
"delete": "Delete"
},
diff --git a/project/web/src/components/PublishDialog/index.tsx b/project/web/src/components/PublishDialog/index.tsx
index 79305e6a..92a7ecb0 100644
--- a/project/web/src/components/PublishDialog/index.tsx
+++ b/project/web/src/components/PublishDialog/index.tsx
@@ -4,8 +4,10 @@ import type {
import type { SocialAccount } from '@/api/types/account.type'
import {
ArrowRightOutlined,
+ CloseOutlined,
ExclamationCircleFilled,
InfoCircleOutlined,
+ SendOutlined,
} from '@ant-design/icons'
import { Button, message, Modal, Tooltip } from 'antd'
import {
@@ -472,17 +474,61 @@ const PublishDialog = memo(
setWarningParamsMap(warningParamsMap)
}, [warningParamsMap])
+ /**
+ * Publish content immediately (publishTime is set to current time)
+ */
+ const pubClickNow = useCallback(async () => {
+ setCreateLoading(true)
+ const publishTime = getUtcDays(getDays()).format()
+
+ for (const item of pubListChoosed) {
+ const res = await apiCreatePublish({
+ topics: [],
+ flowId: generateUUID(),
+ type: item.params.video?.cover.ossUrl
+ ? PubType.VIDEO
+ : PubType.ImageText,
+ title: item.params.title || '',
+ desc: item.params.des,
+ accountId: item.account.id,
+ accountType: item.account.type,
+ videoUrl: item.params.video?.ossUrl,
+ coverUrl:
+ item.params.video?.cover.ossUrl
+ || (item.params.images && item.params.images.length > 0
+ ? item.params.images[0].ossUrl
+ : undefined),
+ imgUrlList:
+ item.params.images
+ ?.map(v => v.ossUrl)
+ .filter((url): url is string => url !== undefined) || [],
+ publishTime,
+ option: item.params.option,
+ })
+ if (res?.code !== 0) {
+ return setCreateLoading(false)
+ }
+ }
+ onClose()
+ setCreateLoading(false)
+
+ if (onPubSuccess)
+ onPubSuccess()
+ }, [pubListChoosed])
+
+ /**
+ * Publish content with scheduled time (from calendar picker)
+ */
const pubClick = useCallback(async () => {
setCreateLoading(true)
const publishTime = getUtcDays(
pubTime || getDays().add(6, 'minute'),
).format()
- const flowId = generateUUID()
for (const item of pubListChoosed) {
const res = await apiCreatePublish({
topics: [],
- flowId,
+ flowId: generateUUID(),
type: item.params.video?.cover.ossUrl
? PubType.VIDEO
: PubType.ImageText,
@@ -553,6 +599,14 @@ const PublishDialog = memo(
<span className="publishDialog-con-head-title">
{t('title')}
</span>
+ <CloseOutlined
+ onClick={closeDialog}
+ style={{
+ fontSize: '16px',
+ cursor: 'pointer',
+ color: '#999',
+ }}
+ />
</div>
<div className="publishDialog-con-acconts">
{pubList.map((pubItem) => {
@@ -891,32 +945,55 @@ const PublishDialog = memo(
</Button>
)}
</div>
- <div style={{ display: 'flex', gap: 12 }}>
- <Button size="large" onClick={closeDialog}>
- {t('buttons.cancelPublish')}
- </Button>
- <Button
- size="large"
- type="primary"
- loading={createLoading}
- onClick={() => {
- for (const [key, errVideoItem] of errParamsMap) {
- if (errVideoItem) {
- const pubItem = pubListChoosed.find(
- v => v.account.id === key,
- )!
- if (step === 1) {
- setExpandedPubItem(pubItem)
+ <div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end' }}>
+ <Button.Group size="large">
+ <Button
+ type="primary"
+ loading={createLoading}
+ disabled={createLoading}
+ icon={<SendOutlined />}
+ style={{ margin: '0' }}
+ onClick={() => {
+ for (const [key, errVideoItem] of errParamsMap) {
+ if (errVideoItem) {
+ const pubItem = pubListChoosed.find(
+ v => v.account.id === key,
+ )!
+ if (step === 1) {
+ setExpandedPubItem(pubItem)
+ }
+ message.warning(errVideoItem.parErrMsg)
+ return
}
- message.warning(errVideoItem.parErrMsg)
- return
}
- }
- pubClick()
- }}
- >
- {t('buttons.schedulePublish')}
- </Button>
+ pubClickNow()
+ }}
+ >
+ {t('buttons.publishNow')}
+ </Button>
+ <Button
+ type="primary"
+ loading={createLoading}
+ disabled={createLoading}
+ onClick={() => {
+ for (const [key, errVideoItem] of errParamsMap) {
+ if (errVideoItem) {
+ const pubItem = pubListChoosed.find(
+ v => v.account.id === key,
+ )!
+ if (step === 1) {
+ setExpandedPubItem(pubItem)
+ }
+ message.warning(errVideoItem.parErrMsg)
+ return
+ }
+ }
+ pubClick()
+ }}
+ >
+ {t('buttons.schedulePublish')}
+ </Button>
+ </Button.Group>
</div>
</>
)}