Skip to content

Commit 5289386

Browse files
committed
refactor: code quality cleanup — dead code, boilerplate, types, constants, AI comments
- Remove dead code: resumeTimer (no-op), onSwipeGesture (ignores callback), themePreset from useAppStore (duplicated), prevNotesRef (unused) - Consolidate boilerplate: booleanSetter helper in useAppStore, onEvent helper in api.ts, data-driven KeybindsModal, removed 11 redundant setters - Fix Rust: clippy needless_borrows_for_generic_args, unexpected_cfgs lint - Improve types: GraphControls interface, typed openAIChat response - Extract ~25 magic numbers to named constants - Remove ~15 pedagogical AI-style comments
1 parent 0e28a95 commit 5289386

21 files changed

Lines changed: 343 additions & 393 deletions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ tauri-plugin-notification = "2.0.0-rc.5"
3232
[target.'cfg(target_os = "macos")'.dependencies]
3333
cocoa = "0.25"
3434
objc = "0.2"
35+
36+
[lints.rust]
37+
unexpected_cfgs = "allow"

src-tauri/src/commands/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub async fn schedule_timer(
103103
.notification()
104104
.builder()
105105
.title("PaperCache Timer")
106-
.body(&format!("⏱ Timer finished: {}", label))
106+
.body(format!("⏱ Timer finished: {}", label))
107107
.show();
108108
let _ = app_clone.emit("timer-complete", &id_clone);
109109
});

src-tauri/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ mod commands;
77
mod macos;
88
mod tray;
99

10+
#[allow(dead_code)]
11+
const FOCUS_LOSS_DEBOUNCE_MS: u64 = 200;
12+
#[allow(dead_code)]
13+
const WINDOW_STATE_RESTORE_DELAY_MS: u64 = 300;
14+
1015

1116
use commands::shortcuts::GlobalShortcutState;
1217
use commands::notifications::NotificationState;
@@ -87,7 +92,7 @@ pub fn run() {
8792
let dialog_open = is_dialog_open.clone();
8893
std::thread::spawn(move || {
8994
std::thread::sleep(
90-
std::time::Duration::from_millis(200),
95+
std::time::Duration::from_millis(FOCUS_LOSS_DEBOUNCE_MS),
9196
);
9297
if g2.load(Ordering::SeqCst) == gen_at_spawn
9398
&& !dialog_open.load(Ordering::SeqCst)
@@ -109,7 +114,7 @@ pub fn run() {
109114
// Plugin's on_window_ready fires too early for available_monitors() on macOS.
110115
let win = window.clone();
111116
std::thread::spawn(move || {
112-
std::thread::sleep(std::time::Duration::from_millis(300));
117+
std::thread::sleep(std::time::Duration::from_millis(WINDOW_STATE_RESTORE_DELAY_MS));
113118
let _ = win.clone().run_on_main_thread(move || {
114119
let _ = win.restore_state(StateFlags::POSITION | StateFlags::SIZE);
115120
if let Ok(app_dir) = win.app_handle().path().app_config_dir() {

src/App.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import { NoteTitleBar } from './components/NoteTitleBar'
2323
import { Editor, type EditorRef } from './components/Editor'
2424
import Settings from './Settings'
2525

26+
const TOAST_TIMEOUT_MS = 5000
27+
const FOCUS_DELAY_MS = 50
28+
const MODAL_Z_INDEX = 9999
29+
const KEYBINDS_Z_INDEX = 10000
30+
const TOAST_Z_INDEX = 99999
31+
2632
function App() {
2733
const notes = useAppStore((state) => state.notes)
2834
const setNotes = useAppStore((state) => state.setNotes)
@@ -50,7 +56,6 @@ function App() {
5056

5157
const searchInputRef = useRef<HTMLInputElement>(null)
5258

53-
// Custom Hooks
5459
useNoteStorage()
5560
useVariables()
5661
useReminders()
@@ -63,7 +68,6 @@ function App() {
6368
useAppStore.getState().setIsHyprland(isHyp)
6469
})
6570

66-
// Show a toast before the app auto-restarts for an update
6771
const disposeUpdateReady = window.electronAPI.onUpdateReady(() => {
6872
useAppStore.getState().addToast({
6973
message: '✨ PaperCache updated — restarting in 3 seconds…',
@@ -94,26 +98,23 @@ function App() {
9498
}
9599
}, [])
96100

97-
// Auto-dismiss toasts after 5 seconds
98101
const toastTimersRef = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map())
99102
useEffect(() => {
100103
const timers = toastTimersRef.current
101104
const currentIds = new Set(toasts.map((t) => t.id))
102105

103-
// Clear timers for removed toasts
104106
for (const [id, timer] of timers) {
105107
if (!currentIds.has(id)) {
106108
clearTimeout(timer)
107109
timers.delete(id)
108110
}
109111
}
110112

111-
// Set timers for new toasts
112113
for (const toast of toasts) {
113114
if (!timers.has(toast.id)) {
114115
timers.set(
115116
toast.id,
116-
setTimeout(() => removeToast(toast.id), 5000)
117+
setTimeout(() => removeToast(toast.id), TOAST_TIMEOUT_MS)
117118
)
118119
}
119120
}
@@ -123,7 +124,7 @@ function App() {
123124
if (showNoteSearch && searchInputRef.current) {
124125
setTimeout(() => {
125126
searchInputRef.current?.focus()
126-
}, 50)
127+
}, FOCUS_DELAY_MS)
127128
}
128129
}, [showNoteSearch])
129130

@@ -205,13 +206,11 @@ function App() {
205206
const note = currentNotes[idx]
206207
const newContent = note.content.slice(0, from) + insert + note.content.slice(to)
207208

208-
// Side-effects outside of state updater
209209
window.electronAPI.saveNote(note.id, newContent)
210210
if (idx === currentNoteIndex) {
211211
editorRef.current?.dispatch({ changes: { from, to, insert } })
212212
}
213213

214-
// Pure state update
215214
setNotes((prevNotes) =>
216215
prevNotes.map((n) => (n.id === noteId ? { ...n, content: newContent } : n))
217216
)
@@ -257,7 +256,7 @@ function App() {
257256
bottom: 0,
258257
backgroundColor: 'rgba(0, 0, 0, 0.75)',
259258
backdropFilter: 'blur(5px)',
260-
zIndex: 9999,
259+
zIndex: MODAL_Z_INDEX,
261260
overflow: 'auto',
262261
}}
263262
>
@@ -276,7 +275,7 @@ function App() {
276275
bottom: 0,
277276
backgroundColor: 'rgba(0, 0, 0, 0.75)',
278277
backdropFilter: 'blur(5px)',
279-
zIndex: 10000,
278+
zIndex: KEYBINDS_Z_INDEX,
280279
overflow: 'auto',
281280
}}
282281
>
@@ -294,7 +293,7 @@ function App() {
294293
display: 'flex',
295294
flexDirection: 'column',
296295
gap: 8,
297-
zIndex: 99999,
296+
zIndex: TOAST_Z_INDEX,
298297
}}
299298
>
300299
{toasts.map((toast) => (

0 commit comments

Comments
 (0)