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 /editor/forms | |
parent | 28417d795a6922c3df3c2c0aea78a51648b0428e (diff) |
Use the common fileLoader element
Diffstat (limited to 'editor/forms')
-rwxr-xr-x | editor/forms/selector.ml | 39 |
1 files changed, 4 insertions, 35 deletions
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 ) |