- Created a .cursorignore file to manage local environment files. - Updated .env.example to reflect changes in the public app URL. - Modified the gmail workspace configuration to include the drive-suite path. - Enhanced email view components to support attachment handling and fallback for plain text bodies. - Improved user experience by updating attachment display logic and integrating inline attachment support.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo } from "react"
|
|
import { useQueries } from "@tanstack/react-query"
|
|
import { useAuthReady } from "../use-auth-ready"
|
|
import { fetchMessageAttachments } from "./use-message-attachments"
|
|
import type { EmailAttachment } from "@/lib/email-data"
|
|
|
|
export type ListAttachmentFetchState = "idle" | "loading" | "done"
|
|
|
|
export function useListMessageAttachments(messageIds: string[]) {
|
|
const { ready, authenticated } = useAuthReady()
|
|
const stableIds = useMemo(
|
|
() => [...new Set(messageIds)].sort(),
|
|
[messageIds]
|
|
)
|
|
|
|
const queries = useQueries({
|
|
queries: stableIds.map((id) => ({
|
|
queryKey: ["message-attachments", id] as const,
|
|
queryFn: () => fetchMessageAttachments(id),
|
|
enabled: ready && authenticated,
|
|
staleTime: 5 * 60_000,
|
|
})),
|
|
})
|
|
|
|
return useMemo(() => {
|
|
const byId = new Map<string, EmailAttachment[]>()
|
|
const stateById = new Map<string, ListAttachmentFetchState>()
|
|
|
|
stableIds.forEach((id, index) => {
|
|
const q = queries[index]
|
|
if (!q) {
|
|
stateById.set(id, "idle")
|
|
return
|
|
}
|
|
if (q.isPending || q.isFetching) {
|
|
stateById.set(id, "loading")
|
|
return
|
|
}
|
|
stateById.set(id, "done")
|
|
if (q.data?.length) byId.set(id, q.data)
|
|
})
|
|
|
|
return { byId, stateById }
|
|
}, [stableIds, queries])
|
|
}
|