1
1
import { useEffect , useId , useRef , useState } from "react" ;
2
2
import { twMerge } from "tailwind-merge" ;
3
3
import Draggable , { DraggableData , DraggableEvent } from "react-draggable" ;
4
- import { notesService } from "../../../database/notes.service" ;
5
- import { settingsService } from "../../../database/settings.service" ;
4
+ import notes from "../../../database/notes" ;
6
5
import { NoteItem } from "../../../database/db" ;
7
- import { useLiveQuery } from "dexie-react-hooks" ;
8
6
import { themes } from "../../../utilities/themes" ;
9
7
import NoteMenu from "./NoteMenu" ;
10
- import { SETTINGS_KEYS } from "../../../utilities/constants" ;
11
8
import { StarIcon } from "@heroicons/react/16/solid" ;
12
9
13
10
const Note = (
14
11
p : React . HTMLAttributes < HTMLElement > & {
15
12
noteData : NoteItem ;
13
+ useOpaqueNotes ?: boolean ;
16
14
} ,
17
15
) => {
18
16
const id = useId ( ) ;
19
- const useOpaqueNotes = useLiveQuery ( ( ) =>
20
- settingsService . read ( SETTINGS_KEYS . UseOpaqueNotes ) ,
21
- ) ;
22
17
const textareaId = useId ( ) ;
23
18
const nodeRef = useRef < HTMLElement > ( null ) ;
24
19
const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
@@ -32,10 +27,10 @@ const Note = (
32
27
} ) ;
33
28
34
29
useEffect ( ( ) => {
35
- notesService . modify ( p . noteData . id , notePosition ) ;
30
+ notes . modify ( p . noteData . id , notePosition ) ;
36
31
} , [ notePosition , p . noteData . id ] ) ;
37
32
38
- if ( useOpaqueNotes === undefined || ! p . noteData ) {
33
+ if ( ! p . noteData ) {
39
34
return null ;
40
35
}
41
36
@@ -59,7 +54,7 @@ const Note = (
59
54
}
60
55
61
56
async function handleBringForwards ( ) {
62
- const highestId = await notesService . getTopZIndex ( ) ;
57
+ const highestId = await notes . getTopZIndex ( ) ;
63
58
if ( highestId !== notePosition . posZ ) {
64
59
setNotePosition ( ( prevState ) => ( {
65
60
...prevState ,
@@ -86,7 +81,7 @@ const Note = (
86
81
ref = { nodeRef }
87
82
className = { twMerge (
88
83
"absolute rounded shadow-sm hover:shadow-lg" ,
89
- useOpaqueNotes ? theme . noteOpaque : theme . note ,
84
+ p . useOpaqueNotes ? theme . noteOpaque : theme . note ,
90
85
! p . noteData . content &&
91
86
! p . noteData . isPriority &&
92
87
"[&:not(:hover)]:animate-pulse" ,
@@ -113,7 +108,7 @@ const Note = (
113
108
id = { textareaId }
114
109
ref = { textareaRef }
115
110
onChange = { ( ) =>
116
- notesService . modify ( p . noteData . id , {
111
+ notes . modify ( p . noteData . id , {
117
112
content : textareaRef . current ?. value ,
118
113
} )
119
114
}
0 commit comments