mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 20:14:16 +08:00
自选页新增批量导入:支持 CSV/TXT 文件与粘贴证券代码两种来源,解析出 候选并在弹窗内确认后按 M:N 分组一次性写入(目标分组可多选或就地新建, 默认只勾新增标的,已在自选的可并入所选分组)。 Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
/**
|
|
* 共享 mutation hooks — 消除多页面重复的 useMutation 调用。
|
|
*/
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { api } from './api'
|
|
import { QK } from './queryKeys'
|
|
|
|
/** 切换实时行情 — Layout / Data 共用 */
|
|
export function useToggleRealtimeQuotes() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (enabled: boolean) => api.updateRealtimeQuotes(enabled),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: QK.preferences })
|
|
qc.invalidateQueries({ queryKey: QK.quoteStatus })
|
|
},
|
|
})
|
|
}
|
|
|
|
/** 更新行情轮询间隔 — Layout / Data 共用 */
|
|
export function useUpdateQuoteInterval() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (v: number) => api.updateQuoteInterval(v),
|
|
onSuccess: (data) => {
|
|
qc.setQueryData(QK.quoteInterval, data)
|
|
qc.invalidateQueries({ queryKey: QK.quoteStatus })
|
|
},
|
|
})
|
|
}
|
|
|
|
interface WatchlistBatchAddInput {
|
|
symbols: string[]
|
|
groupId?: string | null
|
|
groupIds?: string[]
|
|
}
|
|
|
|
/** 批量添加自选 — Screener / 截图导入共用 */
|
|
export function useWatchlistBatchAdd() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: ({ symbols, groupId, groupIds }: WatchlistBatchAddInput) =>
|
|
api.watchlistBatchAdd(symbols, '', groupId, groupIds),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: QK.watchlist })
|
|
// 前缀匹配: 实际 key 为 ['watchlist-enriched', extColumnsParam],
|
|
// 不能用 QK.watchlistEnriched()(= undefined) 精确匹配, 否则列表不刷新。
|
|
qc.invalidateQueries({ queryKey: ['watchlist-enriched'] })
|
|
},
|
|
})
|
|
}
|