| 1 | /** |
| 2 | * 平台授权 Hook |
| 3 | * 处理各平台的授权跳转逻辑 |
| 4 | */ |
| 5 | |
| 6 | import type { SocialAccount } from '@/api/accounts/account.types' |
| 7 | |
| 8 | import { useCallback } from 'react' |
| 9 | import { useChannelManagerStore } from '@/components/ChannelManager/channelManagerStore' |
| 10 | import { usePublishDialog } from '@/components/PublishDialog/usePublishDialog' |
| 11 | |
| 12 | /** |
| 13 | * 平台授权 Hook |
| 14 | */ |
| 15 | export function usePlatformAuth() { |
| 16 | const setOnAuthSuccess = useChannelManagerStore(state => state.setOnAuthSuccess) |
| 17 | const startAuth = useChannelManagerStore(state => state.startAuth) |
| 18 | |
| 19 | /** |
| 20 | * 处理离线账户头像点击,复用频道管理授权流程 |
| 21 | */ |
| 22 | const handleOfflineAvatarClick = useCallback( |
| 23 | (account: SocialAccount) => { |
| 24 | setOnAuthSuccess((authedAccount) => { |
| 25 | usePublishDialog.getState().syncAccounts([ |
| 26 | ...usePublishDialog.getState().pubList.map(pubItem => pubItem.account), |
| 27 | authedAccount, |
| 28 | ]) |
| 29 | useChannelManagerStore.getState().setOnAuthSuccess(null) |
| 30 | }) |
| 31 | startAuth(account.type, account.groupId) |
| 32 | }, |
| 33 | [setOnAuthSuccess, startAuth], |
| 34 | ) |
| 35 | |
| 36 | return { |
| 37 | handleOfflineAvatarClick, |
| 38 | } |
| 39 | } |
| 40 |