From d4396ca7eb4819e79472111113f8b441d1a8f8ab Mon Sep 17 00:00:00 2001 From: Nizzy Date: Thu, 1 May 2025 09:05:40 -0700 Subject: [PATCH 1/4] padding fix --- apps/mail/components/mail/mail-display.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/mail/components/mail/mail-display.tsx b/apps/mail/components/mail/mail-display.tsx index 6bc67a5ba..24867cb54 100644 --- a/apps/mail/components/mail/mail-display.tsx +++ b/apps/mail/components/mail/mail-display.tsx @@ -631,7 +631,7 @@ const MailDisplay = ({ emailData, index, totalEmails, demo }: Props) => { {formatDate(emailData?.receivedOn)} -
+

To:{' '} {(() => { @@ -761,7 +761,7 @@ const MailDisplay = ({ emailData, index, totalEmails, demo }: Props) => {

)} {emailData?.attachments && emailData?.attachments.length > 0 ? ( -
+
{emailData?.attachments.map((attachment, index) => (
) : null} -
+
-
-
- ))} - {message.searchContent.results.length > 5 && ( - - )} -
- )} - - {message.type === 'email' && message.emailContent && ( -
- {message.emailContent.subject && ( -
- Subject: {message.emailContent.subject} -
- )} -
{message.emailContent.content}
-
- - -
-
- )} */}
)) )} - {/* Invisible element to scroll to */}
- {JSON.stringify(error)} - {/* Loading indicator */} {status === 'submitted' && (
- zero is thinking... + + zero is thinking... +
)} + {status === 'error' &&
Error, please try again later
}
@@ -469,7 +246,7 @@ export function AIChat({ editor, onMessagesChange, onReset }: AIChatProps) { form="ai-chat-form" type="submit" className="border-border/50 inline-flex h-7 cursor-pointer items-center justify-center gap-1.5 overflow-hidden rounded-md border bg-white pl-1.5 pr-1 dark:bg-[#262626]" - disabled={!input.trim()} + disabled={!input.trim() || status !== 'ready'} >
diff --git a/apps/mail/components/ui/nav-user.tsx b/apps/mail/components/ui/nav-user.tsx index bed745d8a..cf6595eaa 100644 --- a/apps/mail/components/ui/nav-user.tsx +++ b/apps/mail/components/ui/nav-user.tsx @@ -31,6 +31,7 @@ import { signOut, useSession } from '@/lib/auth-client'; import { AddConnectionDialog } from '../connection/add'; import { putConnection } from '@/actions/connections'; import { useSidebar } from '@/components/ui/sidebar'; +import { useBrainState } from '@/hooks/use-summary'; import { dexieStorageProvider } from '@/lib/idb'; import { EnableBrain } from '@/actions/brain'; import { useRouter } from 'next/navigation'; @@ -101,6 +102,8 @@ export function NavUser() { ); }; + const { data: brainState } = useBrainState(); + const handleThemeToggle = () => { setTheme(theme === 'dark' ? 'light' : 'dark'); }; @@ -266,14 +269,6 @@ export function NavUser() { Terms
- -

Debug

- -
- -

Clear Local Cache

-
-
@@ -394,12 +389,14 @@ export function NavUser() {

Clear Local Cache

- {/* -
- -

Enable Brain Activity

-
-
*/} + {!brainState?.enabled ? ( + +
+ +

Enable Brain Activity

+
+
+ ) : null} diff --git a/apps/mail/hooks/use-summary.ts b/apps/mail/hooks/use-summary.ts index d04ec7f45..e25ab83e5 100644 --- a/apps/mail/hooks/use-summary.ts +++ b/apps/mail/hooks/use-summary.ts @@ -1,11 +1,12 @@ 'use client'; -import { GetSummary } from '@/actions/getSummary'; -import { string } from 'zod'; +import { GetState, GetSummary } from '@/actions/getSummary'; +import { useSession } from '@/lib/auth-client'; import useSWR from 'swr'; export const useSummary = (threadId: string | null) => { + const { data: session } = useSession(); const { data, isLoading } = useSWR<{ short: string; long: string } | null>( - threadId ? `ai:summary:${threadId}` : null, + session && threadId ? `ai:summary:${threadId}` : null, async () => { if (!threadId) return null; return await GetSummary(threadId); @@ -14,3 +15,15 @@ export const useSummary = (threadId: string | null) => { return { data, isLoading }; }; + +export const useBrainState = () => { + const { data: session } = useSession(); + const { data, isLoading } = useSWR<{ enabled: boolean } | null>( + session ? `brain:state:${session?.connectionId}` : null, + async () => { + return await GetState(); + }, + ); + + return { data, isLoading }; +}; From b4fd304526b747259e55527a6e9f72c7a9ca60bd Mon Sep 17 00:00:00 2001 From: Aj Wazzan Date: Thu, 1 May 2025 09:26:56 -0700 Subject: [PATCH 3/4] Refactor AIChat and EmailComposer components. Remove unused imports and improve error handling in AIChat. Update attachment display logic and formatting in EmailComposer. --- apps/mail/components/create/ai-chat.tsx | 10 +++------ .../mail/components/create/email-composer.tsx | 22 ++++++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/mail/components/create/ai-chat.tsx b/apps/mail/components/create/ai-chat.tsx index 149cefac3..58368581d 100644 --- a/apps/mail/components/create/ai-chat.tsx +++ b/apps/mail/components/create/ai-chat.tsx @@ -43,12 +43,6 @@ interface Message { }; } -interface AIChatProps { - editor: any; - onMessagesChange?: (messages: Message[]) => void; - onReset?: () => void; -} - const renderThread = (thread: { id: string; title: string; snippet: string }) => { const [, setThreadId] = useQueryState('threadId'); const { data: getThread } = useThread(thread.id); @@ -219,7 +213,9 @@ export function AIChat() { )} - {status === 'error' &&
Error, please try again later
} + {(status === 'error' || !!error) && ( +
Error, please try again later
+ )} diff --git a/apps/mail/components/create/email-composer.tsx b/apps/mail/components/create/email-composer.tsx index 3ceee313c..06b8530d5 100644 --- a/apps/mail/components/create/email-composer.tsx +++ b/apps/mail/components/create/email-composer.tsx @@ -17,6 +17,7 @@ import { Command, Paperclip, Plus } from 'lucide-react'; import { zodResolver } from '@hookform/resolvers/zod'; import { Avatar, AvatarFallback } from '../ui/avatar'; import { aiCompose } from '@/actions/ai-composer'; +import { cn, formatFileSize } from '@/lib/utils'; import { useThread } from '@/hooks/use-threads'; import { useSession } from '@/lib/auth-client'; import { createDraft } from '@/actions/drafts'; @@ -27,7 +28,6 @@ import { useRef, useState } from 'react'; import { useQueryState } from 'nuqs'; import pluralize from 'pluralize'; import { useEffect } from 'react'; -import { cn } from '@/lib/utils'; import { toast } from 'sonner'; import { z } from 'zod'; @@ -693,32 +693,38 @@ export function EmailComposer({ {attachments && attachments.length > 0 && ( - - - + +
-

Attachments

+

+ Attachments +

{attachments.map((file, index) => (

{file.name}

- {(file.size / (1024 * 1024)).toFixed(2)} MB + {formatFileSize(file.size)}

From bb1da21783c899d79c5a5f0453544682010ce0c5 Mon Sep 17 00:00:00 2001 From: Aj Wazzan Date: Thu, 1 May 2025 09:32:45 -0700 Subject: [PATCH 4/4] Refactor mail actions and components. Improve error handling in sendEmail function, remove unused imports, and optimize bulk selection logic in BulkSelectActions. Update unsubscribe tracking logic in handleUnsubscribe function. --- apps/mail/actions/mail.ts | 3 --- apps/mail/actions/send.ts | 17 +++++++++-------- apps/mail/components/mail/mail.tsx | 2 +- apps/mail/lib/email-utils.client.tsx | 10 ++++------ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/apps/mail/actions/mail.ts b/apps/mail/actions/mail.ts index 457d5bc93..8aaf3399e 100644 --- a/apps/mail/actions/mail.ts +++ b/apps/mail/actions/mail.ts @@ -4,9 +4,6 @@ import { IGetThreadResponse } from '@/app/api/driver/types'; import { ParsedMessage } from '@/types'; export const getMail = async ({ id }: { id: string }): Promise => { - if (!id) { - throw new Error('Missing required fields'); - } try { const driver = await getActiveDriver(); const mailData = await driver.get(id); diff --git a/apps/mail/actions/send.ts b/apps/mail/actions/send.ts index 7792e1e5f..73464cb90 100644 --- a/apps/mail/actions/send.ts +++ b/apps/mail/actions/send.ts @@ -1,9 +1,9 @@ 'use server'; +import { updateWritingStyleMatrix } from '@/services/writing-style-service'; import { createDriver } from '@/app/api/driver'; import { getActiveConnection } from './utils'; import { ISendEmail } from '@/types'; -import { updateWritingStyleMatrix } from '@/services/writing-style-service'; import { after } from 'next/server'; export async function sendEmail({ @@ -19,7 +19,9 @@ export async function sendEmail({ draftId, }: ISendEmail & { draftId?: string }) { if (!to || !subject || !message) { - throw new Error('Missing required fields'); + throw new Error( + `Missing required fields, ${to ? '' : 'to'} ${subject ? '' : 'subject'} ${message ? '' : 'message'}`, + ); } const connection = await getActiveConnection(); @@ -56,14 +58,13 @@ export async function sendEmail({ after(async () => { try { - console.warn('Saving writing style matrix...') - await updateWritingStyleMatrix(connection.id, message) - console.warn('Saved writing style matrix.') + console.warn('Saving writing style matrix...'); + await updateWritingStyleMatrix(connection.id, message); + console.warn('Saved writing style matrix.'); } catch (error) { - console.error('Failed to save writing style matrix', error) + console.error('Failed to save writing style matrix', error); } - }) + }); return { success: true }; } - diff --git a/apps/mail/components/mail/mail.tsx b/apps/mail/components/mail/mail.tsx index 3428feceb..5507bc8ad 100644 --- a/apps/mail/components/mail/mail.tsx +++ b/apps/mail/components/mail/mail.tsx @@ -286,7 +286,7 @@ function BulkSelectActions() { setIsLoading(true); toast.promise( Promise.all( - mail.bulkSelected.map(async (bulkSelected) => { + mail.bulkSelected.filter(Boolean).map(async (bulkSelected) => { await new Promise((resolve) => setTimeout(resolve, 499)); const emailData = await getMail({ id: bulkSelected }); if (emailData) { diff --git a/apps/mail/lib/email-utils.client.tsx b/apps/mail/lib/email-utils.client.tsx index 3605bd7be..554a771c7 100644 --- a/apps/mail/lib/email-utils.client.tsx +++ b/apps/mail/lib/email-utils.client.tsx @@ -13,10 +13,6 @@ export const handleUnsubscribe = async ({ emailData }: { emailData: ParsedMessag listUnsubscribePost: emailData.listUnsubscribePost, }); if (listUnsubscribeAction) { - track('Unsubscribe', { - domain: emailData.sender.email.split('@')?.[1] ?? 'unknown', - }); - switch (listUnsubscribeAction.type) { case 'get': window.open(listUnsubscribeAction.url, '_blank'); @@ -48,12 +44,14 @@ export const handleUnsubscribe = async ({ emailData }: { emailData: ParsedMessag name: listUnsubscribeAction.emailAddress, }, ], - subject: listUnsubscribeAction.subject, + subject: listUnsubscribeAction.subject ?? 'Unsubscribe Request', message: 'Zero sent this email to unsubscribe from this mailing list.', - attachments: [], }); return true; } + track('Unsubscribe', { + domain: emailData.sender.email.split('@')?.[1] ?? 'unknown', + }); } } } catch (error) {