diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 15:22:26 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | f6a1a4f2f44e0af679467620f89d0732021cf934 (patch) | |
tree | 96e765c303a53fc246b56dba9137a9d836365e0e | |
parent | 28417d795a6922c3df3c2c0aea78a51648b0428e (diff) |
Use the common fileLoader element
-rwxr-xr-x | editor/actions/import.ml | 2 | ||||
-rwxr-xr-x | editor/forms/selector.ml | 39 | ||||
-rwxr-xr-x | editor/state/state.mli | 1 |
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 |