summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xeditor/actions/import.ml2
-rwxr-xr-xeditor/forms/selector.ml39
-rwxr-xr-xeditor/state/state.mli1
3 files changed, 6 insertions, 36 deletions
diff --git a/editor/actions/import.ml b/editor/actions/import.ml
index fd4bef8..cb0c16d 100755
--- a/editor/actions/import.ml
+++ b/editor/actions/import.ml
@@ -11,7 +11,7 @@ module M = struct
| None -> state
| Some file ->
(* Back to UTF-16 *)
- let content = file.Forms.Selector.content in
+ let content = file.Elements.Input.content in
Brr.Console.(log [content] );
match State.Storage.of_json content with
| Error _ -> state
diff --git a/editor/forms/selector.ml b/editor/forms/selector.ml
index 1354dcc..de11499 100755
--- a/editor/forms/selector.ml
+++ b/editor/forms/selector.ml
@@ -1,47 +1,16 @@
-open Brr
-
-type file =
- { file : File.t
- ; content : Jstr.t
- }
-
+type file = Elements.Input.file
type t = file option
-(** Read the content from the file *)
-let file_loader
- : file option Note.E.send -> File.t -> unit
- = fun event file ->
- let blob = File.as_blob file in
- Fut.await
- (Blob.text blob)
- (Result.iter
- (fun content ->
- event (Some {file; content}) ))
let create
: unit -> t Note.signal * Brr.El.t
= fun () ->
- let add_file_event, add_file_sender = Note.E.create () in
-
- let i = El.input ()
- ~at:[ At.type' (Jstr.v "file")
- ; (At.v (Jstr.v "accept")) (Jstr.v ".json")
- ] in
-
- (* The event return a list of files.
-
- We are only interested by a single on, and keep only the first from the
- list. *)
- let on_change files =
- file_loader add_file_sender (List.hd files) in
-
- Ev.listen
- Ev.change
- (fun _e -> on_change (El.Input.files i)) (El.as_target i);
+ let add_file_event, i = Elements.Input.file_loader
+ (Jstr.v ".json") in
let state = Note.S.hold
None
- add_file_event
+ (Note.E.map (fun v -> Some v) add_file_event)
in
( state
, i )
diff --git a/editor/state/state.mli b/editor/state/state.mli
index 2f3e9c4..4376723 100755
--- a/editor/state/state.mli
+++ b/editor/state/state.mli
@@ -24,6 +24,7 @@ val state_of_storage
val load_page
: Jstr.t option -> t -> t
+(** Create a new empty page, and load it *)
val new_page
: Jstr.t option -> title:Jstr.t -> t -> t