1
- import { Accessor , Component , Match , Show , Switch , createSignal } from "solid-js" ;
2
- import { Note as NoteDetails } from "../core/types" ;
1
+ import { Accessor , Component , Match , Switch , createSignal , untrack } from "solid-js" ;
3
2
import NoteViewPlain from "./note/view_plain" ;
4
- import NoteEdit from "./note/edit" ;
5
3
import NoteViewRendered from "./note/view_rendered" ;
6
4
import Icon from "./icon" ;
7
5
import { copyToClipboard } from "../core/helpers" ;
8
6
import { ToastType , useToast } from "../contexts/ToastProvider" ;
7
+ import { SetStoreFunction , Store } from "solid-js/store" ;
8
+ import Editor , { EditorState } from "./editor/editor" ;
9
+
10
+ const AUTO_SAVE_TIMEOUT = 2400 ;
9
11
10
12
export enum NoteMode {
11
13
RENDERED = "rendered" ,
@@ -16,10 +18,12 @@ export enum NoteMode {
16
18
type NoteProps = {
17
19
mode : NoteMode ,
18
20
setMode : ( mode : NoteMode ) => any ,
19
- noteDetails : NoteDetails ,
20
- content : Accessor < string | undefined > ,
21
+ content : Accessor < string > ,
21
22
setContent : ( content : string ) => any ,
22
23
isEditAllowed : boolean ,
24
+ state : Store < EditorState >
25
+ setState : SetStoreFunction < EditorState >
26
+ onSave : ( content : string ) => any
23
27
}
24
28
25
29
const Note : Component < NoteProps > = ( props ) => {
@@ -86,16 +90,21 @@ const Note: Component<NoteProps> = (props) => {
86
90
</ label >
87
91
</ div >
88
92
</ div >
89
- < Show when = { props . content ( ) } >
90
- { content => < Switch fallback = { < NoteViewRendered content = { content } /> } >
91
- < Match when = { props . mode === NoteMode . PLAIN } >
92
- < NoteViewPlain content = { content } />
93
- </ Match >
94
- < Match when = { props . mode === NoteMode . EDIT } >
95
- < NoteEdit note = { props . noteDetails } content = { content } onChange = { props . setContent } isFullscreen = { isFullscreen } />
96
- </ Match >
97
- </ Switch > }
98
- </ Show >
93
+ < Switch fallback = { < NoteViewRendered content = { props . content } /> } >
94
+ < Match when = { props . mode === NoteMode . PLAIN } >
95
+ < NoteViewPlain content = { props . content } />
96
+ </ Match >
97
+ < Match when = { props . mode === NoteMode . EDIT } >
98
+ < Editor
99
+ content = { untrack ( props . content ) }
100
+ autoSaveTimeout = { AUTO_SAVE_TIMEOUT }
101
+ onSave = { props . onSave }
102
+ state = { props . state }
103
+ setState = { props . setState }
104
+ isFullscreen = { isFullscreen }
105
+ />
106
+ </ Match >
107
+ </ Switch >
99
108
</ div >
100
109
)
101
110
}
0 commit comments