Email for professionals and teams
fix(shortcuts): resolve ESLint cascading render warnings and type refinements
ivic9e5ff4cd39d
diff --git a/src/components/message-actions/message-actions.tsx b/src/components/message-actions/message-actions.tsxindex 4e37385..17ec59a 100644--- a/src/components/message-actions/message-actions.tsx+++ b/src/components/message-actions/message-actions.tsx@@ -1,6 +1,6 @@"use client";-import { createElement, useState, useMemo } from "react";+import { createElement, useState, useMemo, useCallback } from "react";import { useRouter } from "next/navigation";import { Archive, Ban, BellOff, Forward, Mail, MailOpen, MoreVertical, Reply, ReplyAll, ShieldAlert, Trash2 } from "lucide-react";import { useCompose } from "@/components/compose/compose-context";@@ -48,7 +48,7 @@ export function MessageActions({const [error, setError] = useState<string | null>(null);const [moreOpen, setMoreOpen] = useState(false);- async function runAction(action: BulkMessageAction) {+ const runAction = useCallback(async (action: BulkMessageAction) => {setMoreOpen(false);setPendingAction(action);setError(null);@@ -62,7 +62,41 @@ export function MessageActions({} finally {setPendingAction(null);}- }+ }, [messageId, direction, router]);++ const replyable = useMemo(() => message ?? {+ direction,+ fromAddr: senderAddress,+ toAddr: "",+ ccAddr: null,+ providerMessageId: null,+ references: null,+ threadId: null,+ }, [message, direction, senderAddress]);+ const canReplyAll = hasAdditionalRecipients(replyable, ownAddresses);++ const handleReply = useCallback(async (mode: ReplyMode) => {+ setPendingAction(mode);+ setError(null);+ try {+ const draftId = await createReplyDraft({+ mailboxId,+ senderAddress,+ ownAddress,+ subject,+ bodyText,+ bodyHtml,+ sentAt: messageMeta?.createdAt,+ recipients: getReplyRecipients(replyable, ownAddresses, mode),+ threading: getReplyThreading(replyable),+ });+ openDraftComposer(draftId);+ } catch (replyError) {+ setError(replyError instanceof Error ? replyError.message : "Could not start reply");+ } finally {+ setPendingAction(null);+ }+ }, [mailboxId, senderAddress, ownAddress, subject, bodyText, bodyHtml, messageMeta?.createdAt, replyable, ownAddresses, openDraftComposer]);const shortcuts = useMemo(() => [@@ -111,7 +145,7 @@ export function MessageActions({action: () => router.back(),},],- [status, direction, runAction, router]+ [status, direction, runAction, handleReply, router]);useHotkeys(shortcuts);@@ -141,40 +175,6 @@ export function MessageActions({}}- const replyable = message ?? {- direction,- fromAddr: senderAddress,- toAddr: "",- ccAddr: null,- providerMessageId: null,- references: null,- threadId: null,- };- const canReplyAll = hasAdditionalRecipients(replyable, ownAddresses);-- async function handleReply(mode: ReplyMode) {- setPendingAction(mode);- setError(null);- try {- const draftId = await createReplyDraft({- mailboxId,- senderAddress,- ownAddress,- subject,- bodyText,- bodyHtml,- sentAt: messageMeta?.createdAt,- recipients: getReplyRecipients(replyable, ownAddresses, mode),- threading: getReplyThreading(replyable),- });- openDraftComposer(draftId);- } catch (replyError) {- setError(replyError instanceof Error ? replyError.message : "Could not start reply");- } finally {- setPendingAction(null);- }- }-async function handleForward() {if (!message || !messageMeta) return;setPendingAction("forward");@@ -194,7 +194,6 @@ export function MessageActions({setPendingAction(null);}}-async function onBlockContact() {setMoreOpen(false);setError(null);diff --git a/src/components/shortcuts/command-palette.tsx b/src/components/shortcuts/command-palette.tsxindex 5d05cde..3293cce 100644--- a/src/components/shortcuts/command-palette.tsx+++ b/src/components/shortcuts/command-palette.tsx@@ -10,23 +10,21 @@ interface CommandPaletteProps {commands: CommandItem[];}-export function CommandPalette({- isOpen,+function CommandPaletteDialog({onClose,commands,-}: CommandPaletteProps) {+}: {+ onClose: () => void;+ commands: CommandItem[];+}) {const [query, setQuery] = useState("");const [selectedIndex, setSelectedIndex] = useState(0);const inputRef = useRef<HTMLInputElement>(null);const listRef = useRef<HTMLDivElement>(null);useEffect(() => {- if (isOpen) {- setQuery("");- setSelectedIndex(0);- setTimeout(() => inputRef.current?.focus(), 50);- }- }, [isOpen]);+ inputRef.current?.focus();+ }, []);const filteredCommands = useMemo(() => {if (!query.trim()) return commands;@@ -42,9 +40,10 @@ export function CommandPalette({});}, [commands, query]);- useEffect(() => {- setSelectedIndex(0);- }, [filteredCommands]);+ const activeIndex = Math.min(+ selectedIndex,+ Math.max(0, filteredCommands.length - 1)+ );const handleKeyDown = (e: React.KeyboardEvent) => {if (e.key === "ArrowDown") {@@ -57,8 +56,8 @@ export function CommandPalette({);} else if (e.key === "Enter") {e.preventDefault();- if (filteredCommands[selectedIndex]) {- filteredCommands[selectedIndex].perform();+ if (filteredCommands[activeIndex]) {+ filteredCommands[activeIndex].perform();onClose();}} else if (e.key === "Escape") {@@ -67,8 +66,6 @@ export function CommandPalette({}};- if (!isOpen) return null;-const grouped = filteredCommands.reduce((acc, item) => {if (!acc[item.category]) acc[item.category] = [];acc[item.category].push(item);@@ -95,11 +92,14 @@ export function CommandPalette({ref={inputRef}type="text"value={query}- onChange={(e) => setQuery(e.target.value)}+ onChange={(e) => {+ setQuery(e.target.value);+ setSelectedIndex(0);+ }}placeholder="Type a command or search actions..."className="w-full bg-transparent text-neutral-900 dark:text-neutral-100 placeholder-neutral-400 text-[15px] focus:outline-none"/>- <kbd className="px-2 py-0.5 text-xs font-semibold text-neutral-400 bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md shadow-xs">+ <kbd className="px-2 py-0.5 text-xs font-semibold text-neutral-400 bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md shadow-2xs">ESC</kbd></div>@@ -120,7 +120,7 @@ export function CommandPalette({{category}</div>{items.map((item) => {- const isCurrent = flatIndex === selectedIndex;+ const isCurrent = flatIndex === activeIndex;const itemIndex = flatIndex;flatIndex++;const Icon = item.icon;@@ -204,3 +204,12 @@ export function CommandPalette({</div>);}++export function CommandPalette({+ isOpen,+ onClose,+ commands,+}: CommandPaletteProps) {+ if (!isOpen) return null;+ return <CommandPaletteDialog onClose={onClose} commands={commands} />;+}diff --git a/src/components/shortcuts/shortcuts-context.tsx b/src/components/shortcuts/shortcuts-context.tsxindex 0f2cf12..bf22eac 100644--- a/src/components/shortcuts/shortcuts-context.tsx+++ b/src/components/shortcuts/shortcuts-context.tsx@@ -12,12 +12,10 @@ import {ShieldAlert,Trash2,MailPlus,- Search,Settings,HelpCircle,} from "lucide-react";import { useCompose } from "@/components/compose/compose-context";-import { useMailSearch } from "@/components/mail-search/mail-search-context";import type { ShortcutDefinition, CommandItem } from "./types";import { useHotkeys } from "./use-hotkeys";import { CommandPalette } from "./command-palette";@@ -55,7 +53,6 @@ export function ShortcutsProvider({}) {const router = useRouter();const { openComposer } = useCompose();- const { setQuery } = useMailSearch();const [isCommandPaletteOpen, setIsCommandPaletteOpen] = useState(false);const [isHelpModalOpen, setIsHelpModalOpen] = useState(false);diff --git a/src/components/shortcuts/types.ts b/src/components/shortcuts/types.tsindex 6c73e32..97abb97 100644--- a/src/components/shortcuts/types.ts+++ b/src/components/shortcuts/types.ts@@ -1,3 +1,5 @@+import type React from "react";+export type ModifierKey = 'ctrl' | 'meta' | 'alt' | 'shift';export interface ShortcutDefinition {diff --git a/src/components/shortcuts/use-hotkeys.ts b/src/components/shortcuts/use-hotkeys.tsindex 9afa238..baa1a50 100644--- a/src/components/shortcuts/use-hotkeys.ts+++ b/src/components/shortcuts/use-hotkeys.ts@@ -54,7 +54,7 @@ export function useHotkeys(options: UseHotkeysOptions = { enabled: true }) {const sequenceBufferRef = useRef<string[]>([]);- const sequenceTimerRef = useRef<number | null>(null);+ const sequenceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);const shortcutsRef = useRef<ShortcutDefinition[]>(shortcuts);useEffect(() => {@@ -96,10 +96,10 @@ export function useHotkeys(sequenceBufferRef.current.push(key);if (sequenceTimerRef.current) {- window.clearTimeout(sequenceTimerRef.current);+ clearTimeout(sequenceTimerRef.current);}- sequenceTimerRef.current = window.setTimeout(() => {+ sequenceTimerRef.current = setTimeout(() => {sequenceBufferRef.current = [];}, 800);@@ -135,7 +135,7 @@ export function useHotkeys(return () => {window.removeEventListener("keydown", handleKeyDown);if (sequenceTimerRef.current) {- window.clearTimeout(sequenceTimerRef.current);+ clearTimeout(sequenceTimerRef.current);}};}, [options.enabled]);diff --git a/src/components/sidebar-footer.tsx b/src/components/sidebar-footer.tsxindex d037b90..faef89d 100644--- a/src/components/sidebar-footer.tsx+++ b/src/components/sidebar-footer.tsx@@ -25,7 +25,7 @@ export function SidebarFooter() {?</kbd></button>- <p className="text-[11px] text-neutral-400">+ <p className="px-1 text-[11px] text-neutral-400">Powered by{" "}<ahref={`https://mailflare.co/?ref=${typeof window !== "undefined" ? location.hostname : ""}&v=${packageJson.version}`}