• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jcubic / 10xDevs / 18574558796

16 Oct 2025 08:56PM UTC coverage: 21.131% (+0.2%) from 20.966%
18574558796

push

github

jcubic
add confirmation dialog

59 of 85 branches covered (69.41%)

Branch coverage included in aggregate %.

423 of 2196 relevant lines covered (19.26%)

2.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.28
/src/components/notes/NotesContext.tsx
1
'use client';
1✔
2

3
import { createContext, useContext, useState, type ReactNode } from 'react';
×
4
import type { NoteTreeNode } from '@/types/tree';
5
import type { SaveStatus } from '@/types/notes';
6

7
interface NotesContextValue {
8
  notes: NoteTreeNode[];
9
  selectedNoteId: number | null;
10
  saveStatus: SaveStatus;
11
  setNotes: (notes: NoteTreeNode[] | ((prev: NoteTreeNode[]) => NoteTreeNode[])) => void;
12
  setSelectedNoteId: (noteId: number | null) => void;
13
  setSaveStatus: (status: SaveStatus) => void;
14
  updateNoteContent: (noteId: number, content: string) => void;
15
  updateNoteName: (noteId: number, name: string) => void;
16
  markNoteDirty: (noteId: number, dirty: boolean) => void;
17
  getSelectedNote: () => NoteTreeNode | null;
18
  getNote: (noteId: number) => NoteTreeNode | null;
19
}
20

21
const NotesContext = createContext<NotesContextValue | undefined>(undefined);
×
22

23
export function useNotesContext() {
×
24
  const context = useContext(NotesContext);
×
25
  if (context === undefined) {
×
26
    throw new Error('useNotesContext must be used within a NotesProvider');
×
27
  }
×
28
  return context;
×
29
}
×
30

31
interface NotesProviderProps {
32
  children: ReactNode;
33
  initialNotes?: NoteTreeNode[];
34
  initialSelectedNoteId?: number | null;
35
}
36

37
export function NotesProvider({
×
38
  children,
×
39
  initialNotes = [],
×
40
  initialSelectedNoteId = null
×
41
}: NotesProviderProps) {
×
42
  const [notes, setNotes] = useState<NoteTreeNode[]>(initialNotes);
×
43
  const [selectedNoteId, setSelectedNoteId] = useState<number | null>(
×
44
    initialSelectedNoteId
×
45
  );
×
46
  const [saveStatus, setSaveStatus] = useState<SaveStatus>('idle');
×
47

48
  const updateNoteContent = (noteId: number, content: string) => {
×
49
    setNotes((prevNotes) =>
×
50
      prevNotes.map((note) =>
×
51
        note.id === noteId
×
52
          ? {
×
53
              ...note,
×
54
              data: {
×
55
                ...note.data!,
×
56
                content,
×
57
                dirty: true
×
58
              }
×
59
            }
×
60
          : note
×
61
      )
×
62
    );
×
63
  };
×
64

65
  const updateNoteName = (noteId: number, name: string) => {
×
66
    setNotes((prevNotes) =>
×
67
      prevNotes.map((note) => (note.id === noteId ? { ...note, name } : note))
×
68
    );
×
69
  };
×
70

71
  const markNoteDirty = (noteId: number, dirty: boolean) => {
×
72
    setNotes((prevNotes) =>
×
73
      prevNotes.map((note) =>
×
74
        note.id === noteId
×
75
          ? {
×
76
              ...note,
×
77
              data: {
×
78
                ...note.data!,
×
79
                dirty
×
80
              }
×
81
            }
×
82
          : note
×
83
      )
×
84
    );
×
85
  };
×
86

87
  const getSelectedNote = (): NoteTreeNode | null => {
×
88
    if (!selectedNoteId) return null;
×
89
    return notes.find((note) => note.id === selectedNoteId) || null;
×
90
  };
×
91

92
  const getNote = (noteId: number): NoteTreeNode | null => {
×
93
    return notes.find((note) => note.id === noteId) || null;
×
94
  };
×
95

96
  const value: NotesContextValue = {
×
97
    notes,
×
98
    selectedNoteId,
×
99
    saveStatus,
×
100
    setNotes,
×
101
    setSelectedNoteId,
×
102
    setSaveStatus,
×
103
    updateNoteContent,
×
104
    updateNoteName,
×
105
    markNoteDirty,
×
106
    getSelectedNote,
×
107
    getNote
×
108
  };
×
109

110
  return <NotesContext.Provider value={value}>{children}</NotesContext.Provider>;
×
111
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc