From 369b454ed44fbfce0152cedf6682c51fc291e929 Mon Sep 17 00:00:00 2001 From: Aditya Date: Sun, 21 Jun 2026 00:29:16 +0530 Subject: [PATCH] fix: resolve architecture rule violations from AGENTS.md --- electron/preload.ts | 12 +++++++++--- src/App.tsx | 24 +++++++++++------------- src/components/MainActionMenu.tsx | 14 ++++++-------- src/components/NoteSearch.tsx | 30 ++++++++++++++---------------- src/components/NoteTitleBar.tsx | 16 +++++++--------- src/components/RemindersPage.tsx | 11 +++++++++-- src/hooks/useGlobalHotkey.ts | 26 ++++++++++++-------------- src/hooks/useNoteStorage.ts | 5 ++++- src/types.d.ts | 6 +++--- 9 files changed, 75 insertions(+), 69 deletions(-) diff --git a/electron/preload.ts b/electron/preload.ts index 9a5c11c..0f11d7f 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -15,16 +15,22 @@ contextBridge.exposeInMainWorld('electronAPI', { openExternal: (url: string) => ipcRenderer.send('open-external', url), openFile: (path: string) => ipcRenderer.send('open-file', path), onSwipeGesture: (callback: (direction: string) => void) => { - ipcRenderer.on('swipe-gesture', (_event, direction) => callback(direction)) + const handler = (_event: any, direction: string) => callback(direction) + ipcRenderer.on('swipe-gesture', handler) + return () => ipcRenderer.removeListener('swipe-gesture', handler) }, setLaunchAtStartup: (value: boolean) => ipcRenderer.send('set-launch-startup', value), updateGlobalShortcut: (action: string, oldShortcut: string, newShortcut: string) => ipcRenderer.send('update-global-shortcut', { action, oldShortcut, newShortcut }), onTriggerNewNote: (callback: () => void) => { - ipcRenderer.on('trigger-new-note', () => callback()) + const handler = () => callback() + ipcRenderer.on('trigger-new-note', handler) + return () => ipcRenderer.removeListener('trigger-new-note', handler) }, onTriggerTasks: (callback: () => void) => { - ipcRenderer.on('trigger-tasks', () => callback()) + const handler = () => callback() + ipcRenderer.on('trigger-tasks', handler) + return () => ipcRenderer.removeListener('trigger-tasks', handler) }, safeStorageEncrypt: (val: string) => ipcRenderer.invoke('safe-storage-encrypt', val), safeStorageDecrypt: (val: string) => ipcRenderer.invoke('safe-storage-decrypt', val), diff --git a/src/App.tsx b/src/App.tsx index 30e4311..49b21b1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,19 +36,17 @@ import { getSecure } from './lib/safeStorage' import { MathEvaluator } from './lib/editor/MathEvaluator' function App() { - const { - notes, - setNotes, - currentNoteIndex, - setCurrentNoteIndex, - zoomLevel, - showGraphView, - setShowGraphView, - showRemindersView, - setShowRemindersView, - showNoteSearch, - setShowMainActionMenu, - } = useAppStore() + const notes = useAppStore((state) => state.notes) + const setNotes = useAppStore((state) => state.setNotes) + const currentNoteIndex = useAppStore((state) => state.currentNoteIndex) + const setCurrentNoteIndex = useAppStore((state) => state.setCurrentNoteIndex) + const zoomLevel = useAppStore((state) => state.zoomLevel) + const showGraphView = useAppStore((state) => state.showGraphView) + const setShowGraphView = useAppStore((state) => state.setShowGraphView) + const showRemindersView = useAppStore((state) => state.showRemindersView) + const setShowRemindersView = useAppStore((state) => state.setShowRemindersView) + const showNoteSearch = useAppStore((state) => state.showNoteSearch) + const setShowMainActionMenu = useAppStore((state) => state.setShowMainActionMenu) const { themePreset, diff --git a/src/components/MainActionMenu.tsx b/src/components/MainActionMenu.tsx index f1131b7..4012074 100644 --- a/src/components/MainActionMenu.tsx +++ b/src/components/MainActionMenu.tsx @@ -2,14 +2,12 @@ import { useAppStore } from '../store/useAppStore' import { useSettingsStore } from '../store/useSettingsStore' export function MainActionMenu() { - const { - notes, - currentNoteIndex, - showMainActionMenu, - setShowNoteSearch, - setShowGraphView, - setShowRemindersView, - } = useAppStore() + const notes = useAppStore((state) => state.notes) + const currentNoteIndex = useAppStore((state) => state.currentNoteIndex) + const showMainActionMenu = useAppStore((state) => state.showMainActionMenu) + const setShowNoteSearch = useAppStore((state) => state.setShowNoteSearch) + const setShowGraphView = useAppStore((state) => state.setShowGraphView) + const setShowRemindersView = useAppStore((state) => state.setShowRemindersView) const { bgType, bgColor, textColor, fontFamily } = useSettingsStore() diff --git a/src/components/NoteSearch.tsx b/src/components/NoteSearch.tsx index af0e56d..2792b39 100644 --- a/src/components/NoteSearch.tsx +++ b/src/components/NoteSearch.tsx @@ -2,22 +2,20 @@ import { useAppStore } from '../store/useAppStore' import { getFolderColor } from '../utils' export function NoteSearch() { - const { - notes, - setNotes, - currentNoteIndex, - setCurrentNoteIndex, - showNoteSearch, - setShowNoteSearch, - noteSearchQuery, - setNoteSearchQuery, - searchSelectedIndex, - setSearchSelectedIndex, - showNoteActionMenu, - setShowNoteActionMenu, - actionMenuIndex, - setActionMenuIndex, - } = useAppStore() + const notes = useAppStore((state) => state.notes) + const setNotes = useAppStore((state) => state.setNotes) + const currentNoteIndex = useAppStore((state) => state.currentNoteIndex) + const setCurrentNoteIndex = useAppStore((state) => state.setCurrentNoteIndex) + const showNoteSearch = useAppStore((state) => state.showNoteSearch) + const setShowNoteSearch = useAppStore((state) => state.setShowNoteSearch) + const noteSearchQuery = useAppStore((state) => state.noteSearchQuery) + const setNoteSearchQuery = useAppStore((state) => state.setNoteSearchQuery) + const searchSelectedIndex = useAppStore((state) => state.searchSelectedIndex) + const setSearchSelectedIndex = useAppStore((state) => state.setSearchSelectedIndex) + const showNoteActionMenu = useAppStore((state) => state.showNoteActionMenu) + const setShowNoteActionMenu = useAppStore((state) => state.setShowNoteActionMenu) + const actionMenuIndex = useAppStore((state) => state.actionMenuIndex) + const setActionMenuIndex = useAppStore((state) => state.setActionMenuIndex) if (!showNoteSearch) return null diff --git a/src/components/NoteTitleBar.tsx b/src/components/NoteTitleBar.tsx index ce32e6c..92bb0d5 100644 --- a/src/components/NoteTitleBar.tsx +++ b/src/components/NoteTitleBar.tsx @@ -1,15 +1,13 @@ import { useAppStore } from '../store/useAppStore' export function NoteTitleBar() { - const { - notes, - setNotes, - currentNoteIndex, - isRenaming, - setIsRenaming, - renameValue, - setRenameValue, - } = useAppStore() + const notes = useAppStore((state) => state.notes) + const setNotes = useAppStore((state) => state.setNotes) + const currentNoteIndex = useAppStore((state) => state.currentNoteIndex) + const isRenaming = useAppStore((state) => state.isRenaming) + const setIsRenaming = useAppStore((state) => state.setIsRenaming) + const renameValue = useAppStore((state) => state.renameValue) + const setRenameValue = useAppStore((state) => state.setRenameValue) const activeNote = notes[currentNoteIndex] || { id: 'note.md', content: '', mtime: 0 } diff --git a/src/components/RemindersPage.tsx b/src/components/RemindersPage.tsx index c360b7f..9d45c39 100644 --- a/src/components/RemindersPage.tsx +++ b/src/components/RemindersPage.tsx @@ -68,8 +68,15 @@ export const RemindersPage: React.FC = ({ const [now, setNow] = React.useState(() => Date.now()) React.useEffect(() => { - const timer = setInterval(() => setNow(Date.now()), 10000) // update every 10s for better responsiveness - return () => clearInterval(timer) + let timeoutId: ReturnType + const scheduleNext = () => { + timeoutId = setTimeout(() => { + setNow(Date.now()) + scheduleNext() + }, 10000) // update every 10s for better responsiveness + } + scheduleNext() + return () => clearTimeout(timeoutId) }, []) return ( diff --git a/src/hooks/useGlobalHotkey.ts b/src/hooks/useGlobalHotkey.ts index a973d08..46891e8 100644 --- a/src/hooks/useGlobalHotkey.ts +++ b/src/hooks/useGlobalHotkey.ts @@ -2,20 +2,18 @@ import { useEffect } from 'react' import { useAppStore } from '../store/useAppStore' export function useGlobalHotkey() { - const { - showMainActionMenu, - showNoteSearch, - showGraphView, - setShowMainActionMenu, - setShowNoteSearch, - setShowGraphView, - setShowRemindersView, - setZoomLevel, - setNotes, - setCurrentNoteIndex, - setNoteSearchQuery, - setSearchSelectedIndex, - } = useAppStore() + const showMainActionMenu = useAppStore((state) => state.showMainActionMenu) + const showNoteSearch = useAppStore((state) => state.showNoteSearch) + const showGraphView = useAppStore((state) => state.showGraphView) + const setShowMainActionMenu = useAppStore((state) => state.setShowMainActionMenu) + const setShowNoteSearch = useAppStore((state) => state.setShowNoteSearch) + const setShowGraphView = useAppStore((state) => state.setShowGraphView) + const setShowRemindersView = useAppStore((state) => state.setShowRemindersView) + const setZoomLevel = useAppStore((state) => state.setZoomLevel) + const setNotes = useAppStore((state) => state.setNotes) + const setCurrentNoteIndex = useAppStore((state) => state.setCurrentNoteIndex) + const setNoteSearchQuery = useAppStore((state) => state.setNoteSearchQuery) + const setSearchSelectedIndex = useAppStore((state) => state.setSearchSelectedIndex) useEffect(() => { const handleGlobalKeyDown = async (e: KeyboardEvent) => { diff --git a/src/hooks/useNoteStorage.ts b/src/hooks/useNoteStorage.ts index ad6194a..651df7d 100644 --- a/src/hooks/useNoteStorage.ts +++ b/src/hooks/useNoteStorage.ts @@ -3,7 +3,10 @@ import { useAppStore } from '../store/useAppStore' import type { Note } from '../store/useAppStore' export function useNoteStorage() { - const { notes, setNotes, currentNoteIndex, setCurrentNoteIndex } = useAppStore() + const notes = useAppStore((state) => state.notes) + const setNotes = useAppStore((state) => state.setNotes) + const currentNoteIndex = useAppStore((state) => state.currentNoteIndex) + const setCurrentNoteIndex = useAppStore((state) => state.setCurrentNoteIndex) // Load notes initially useEffect(() => { diff --git a/src/types.d.ts b/src/types.d.ts index e32aaf1..f5d801b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -16,11 +16,11 @@ export interface ElectronAPI { quitApp: () => void openExternal: (url: string) => void openFile: (path: string) => void - onSwipeGesture: (callback: (direction: string) => void) => void + onSwipeGesture: (callback: (direction: string) => void) => () => void setLaunchAtStartup: (value: boolean) => void updateGlobalShortcut: (action: string, oldShortcut: string, newShortcut: string) => void - onTriggerNewNote: (callback: () => void) => void - onTriggerTasks: (callback: () => void) => void + onTriggerNewNote: (callback: () => void) => () => void + onTriggerTasks: (callback: () => void) => () => void safeStorageEncrypt: (val: string) => Promise safeStorageDecrypt: (val: string) => Promise onPowerSuspend: (callback: () => void) => () => void