| 1 | /** |
| 2 | * 发布弹框本地状态管理 |
| 3 | * 管理弹框内各种临时状态,如 loading、弹窗显示状态等 |
| 4 | */ |
| 5 | |
| 6 | import { useCallback, useState } from 'react' |
| 7 | |
| 8 | export interface PublishModalState { |
| 9 | // 创建发布loading |
| 10 | createLoading: boolean |
| 11 | setCreateLoading: (loading: boolean) => void |
| 12 | // 抖音扫码发布弹窗 |
| 13 | douyinQRCodeVisible: boolean |
| 14 | setDouyinQRCodeVisible: (visible: boolean) => void |
| 15 | douyinPermalink: string |
| 16 | setDouyinPermalink: (permalink: string) => void |
| 17 | // 发布详情弹框 |
| 18 | publishDetailVisible: boolean |
| 19 | setPublishDetailVisible: (visible: boolean) => void |
| 20 | currentPublishTaskId: string | undefined |
| 21 | setCurrentPublishTaskId: (taskId: string | undefined) => void |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * 管理发布弹框内各种弹窗的显示状态 |
| 26 | */ |
| 27 | export function usePublishModalState(): PublishModalState { |
| 28 | // 创建发布loading |
| 29 | const [createLoading, setCreateLoading] = useState(false) |
| 30 | // 抖音扫码发布弹窗状态 |
| 31 | const [douyinQRCodeVisible, setDouyinQRCodeVisible] = useState(false) |
| 32 | const [douyinPermalink, setDouyinPermalink] = useState('') |
| 33 | // 发布详情弹框状态 |
| 34 | const [publishDetailVisible, setPublishDetailVisible] = useState(false) |
| 35 | const [currentPublishTaskId, setCurrentPublishTaskId] = useState<string | undefined>(undefined) |
| 36 | |
| 37 | return { |
| 38 | createLoading, |
| 39 | setCreateLoading, |
| 40 | douyinQRCodeVisible, |
| 41 | setDouyinQRCodeVisible, |
| 42 | douyinPermalink, |
| 43 | setDouyinPermalink, |
| 44 | publishDetailVisible, |
| 45 | setPublishDetailVisible, |
| 46 | currentPublishTaskId, |
| 47 | setCurrentPublishTaskId, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * 关闭发布详情弹框 |
| 53 | */ |
| 54 | export function usePublishDetailModalActions( |
| 55 | setPublishDetailVisible: (visible: boolean) => void, |
| 56 | setCurrentPublishTaskId: (taskId: string | undefined) => void, |
| 57 | ) { |
| 58 | const closePublishDetailModal = useCallback(() => { |
| 59 | setPublishDetailVisible(false) |
| 60 | setCurrentPublishTaskId(undefined) |
| 61 | }, [setPublishDetailVisible, setCurrentPublishTaskId]) |
| 62 | |
| 63 | return { closePublishDetailModal } |
| 64 | } |
| 65 |