|
|
|
@ -171,6 +171,7 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
const [error, setError] = useState(null)
|
|
|
|
|
const [isFreshData, setIsFreshData] = useState(false)
|
|
|
|
|
const [refreshTrigger, setRefreshTrigger] = useState(0)
|
|
|
|
|
const [tempBreadcrumb, setTempBreadcrumb] = useState(null);
|
|
|
|
|
|
|
|
|
|
const refresh = useCallback(() => {
|
|
|
|
|
setRefreshTrigger((prev) => prev + 1)
|
|
|
|
@ -234,15 +235,15 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
}
|
|
|
|
|
}, [VKey])
|
|
|
|
|
|
|
|
|
|
const searchMailList = async () => {
|
|
|
|
|
const searchResult = await searchEmailListAction(currentMailboxOPI, 'ALL')
|
|
|
|
|
// 配合List的结构
|
|
|
|
|
const mailList = searchResult.map((ele) => ({
|
|
|
|
|
...ele,
|
|
|
|
|
key: ele.MAI_SN,
|
|
|
|
|
}))
|
|
|
|
|
setMailList(mailList)
|
|
|
|
|
console.info('searchMailList', searchResult)
|
|
|
|
|
const searchMailList = async (params) => {
|
|
|
|
|
// const searchResult = await searchEmailListAction({ ...params, opi_sn: currentMailboxOPI })
|
|
|
|
|
// // 配合List的结构
|
|
|
|
|
// const mailList = searchResult.map((ele) => ({
|
|
|
|
|
// ...ele,
|
|
|
|
|
// key: ele.MAI_SN,
|
|
|
|
|
// }))
|
|
|
|
|
// setMailList(mailList)
|
|
|
|
|
// console.info('searchMailList', searchResult)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getMailList = useCallback(async () => {
|
|
|
|
@ -254,7 +255,7 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
setIsFreshData(false)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTempBreadcrumb(null)
|
|
|
|
|
setLoading(true)
|
|
|
|
|
setError(null)
|
|
|
|
|
setIsFreshData(false)
|
|
|
|
@ -283,10 +284,19 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
getMailList()
|
|
|
|
|
// --- Setup Internal Event Listener ---
|
|
|
|
|
const handleInternalUpdate = (event) => {
|
|
|
|
|
// console.log(`[useEmailList] Received internal event. `, event.detail)
|
|
|
|
|
if (event.detail && event.detail.type === 'listrow') {
|
|
|
|
|
// console.log(`🔔[useEmailList] Received internal event. `, event.detail)
|
|
|
|
|
if (isEmpty(event.detail)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const { type, } = event.detail
|
|
|
|
|
if (type === 'listrow') {
|
|
|
|
|
loadMailListFromCache()
|
|
|
|
|
}
|
|
|
|
|
if (type === 'maillist-search-result') {
|
|
|
|
|
const { data, query } = event.detail
|
|
|
|
|
setMailList(data)
|
|
|
|
|
setTempBreadcrumb([{title: '查找邮件:'+query, iconIndex: 'search'}]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internalEventEmitter.on(EMAIL_CHANNEL_NAME, handleInternalUpdate)
|
|
|
|
|
|
|
|
|
@ -294,11 +304,20 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
const channel = getEmailChangesChannel()
|
|
|
|
|
const handleMessage = (event) => {
|
|
|
|
|
// console.log(`[useEmailList] Received channel event. `, event.data)
|
|
|
|
|
if (isEmpty(event.data)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const { type, } = event.detail
|
|
|
|
|
const cacheKey = isEmpty(COLI_SN) ? `dir-${VKey}` : `order-${VKey}`
|
|
|
|
|
if (event.data.type === 'listrow' && cacheKey === event.data.listKey) {
|
|
|
|
|
if (type === 'listrow' && cacheKey === event.data.listKey) {
|
|
|
|
|
// cacheKey 不相同时, 不需要更新; 邮箱目录不相同
|
|
|
|
|
loadMailListFromCache(event.data)
|
|
|
|
|
}
|
|
|
|
|
if (type === 'maillist-search-result') {
|
|
|
|
|
// 搜索的结果不需要更新所有页面
|
|
|
|
|
// const { data } = event.detail
|
|
|
|
|
// setMailList(data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
channel.addEventListener('message', handleMessage)
|
|
|
|
|
|
|
|
|
@ -309,7 +328,7 @@ export const useEmailList = (mailboxDirNode) => {
|
|
|
|
|
}
|
|
|
|
|
}, [getMailList])
|
|
|
|
|
|
|
|
|
|
return { loading, isFreshData, error, mailList, refresh, markAsRead, markAsProcessed, markAsDeleted, searchMailList }
|
|
|
|
|
return { loading, isFreshData, error, mailList, tempBreadcrumb, refresh, markAsRead, markAsProcessed, markAsDeleted, searchMailList }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const orderMailTypes = new Map([
|
|
|
|
|