1- import { Tables } from "@/types/database.types" ;
21import { Task } from "@/lib/tasks/getTasks" ;
32import TaskCard from "@/components/VercelChat/tools/tasks/TaskCard" ;
43import TaskSkeleton from "./TaskSkeleton" ;
54import TaskDetailsDialog from "@/components/VercelChat/dialogs/tasks/TaskDetailsDialog" ;
6- import { useArtistProvider } from "@/providers/ArtistProvider" ;
75import { useUserProvider } from "@/providers/UserProvder" ;
8- import { useMemo } from "react" ;
9- import { useQuery } from "@tanstack/react-query" ;
10-
11- type AccountEmail = Tables < "account_emails" > ;
126
137interface TasksListProps {
148 tasks : Task [ ] ;
@@ -18,42 +12,6 @@ interface TasksListProps {
1812
1913const TasksList : React . FC < TasksListProps > = ( { tasks, isLoading, isError } ) => {
2014 const { userData } = useUserProvider ( ) ;
21- const { selectedArtist } = useArtistProvider ( ) ;
22-
23- // Extract unique account IDs from tasks
24- const accountIds = useMemo (
25- ( ) => [ ...new Set ( tasks . map ( task => task . account_id ) ) ] ,
26- [ tasks ]
27- ) ;
28-
29- // Batch fetch emails for all task owners
30- const { data : accountEmails = [ ] } = useQuery < AccountEmail [ ] > ( {
31- queryKey : [ "task-owner-emails" , accountIds ] ,
32- queryFn : async ( ) => {
33- if ( accountIds . length === 0 || ! userData ) return [ ] ;
34- const params = new URLSearchParams ( ) ;
35- accountIds . forEach ( id => params . append ( "accountIds" , id ) ) ;
36- params . append ( "currentAccountId" , userData . id ) ;
37- if ( selectedArtist ) {
38- params . append ( "artistAccountId" , selectedArtist . account_id ) ;
39- }
40- const response = await fetch ( `/api/account-emails?${ params } ` ) ;
41- if ( ! response . ok ) throw new Error ( "Failed to fetch emails" ) ;
42- return response . json ( ) ;
43- } ,
44- enabled : accountIds . length > 0 && ! ! userData ,
45- } ) ;
46-
47- // Create lookup map for O(1) email access
48- const emailByAccountId = useMemo ( ( ) => {
49- const map = new Map < string , string > ( ) ;
50- accountEmails . forEach ( ae => {
51- if ( ae . account_id && ae . email ) {
52- map . set ( ae . account_id , ae . email ) ;
53- }
54- } ) ;
55- return map ;
56- } , [ accountEmails ] ) ;
5715
5816 if ( isError ) {
5917 return < div className = "text-sm text-red-600 dark:text-red-400" > Failed to load tasks</ div > ;
@@ -90,7 +48,7 @@ const TasksList: React.FC<TasksListProps> = ({ tasks, isLoading, isError }) => {
9048 >
9149 < TaskCard
9250 task = { task }
93- ownerEmail = { emailByAccountId . get ( task . account_id ) }
51+ ownerEmail = { task . owner_email ?? undefined }
9452 />
9553 </ div >
9654 </ TaskDetailsDialog >
0 commit comments