diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 15:27:05 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | 28417d795a6922c3df3c2c0aea78a51648b0428e (patch) | |
tree | 28af6bd86e2127003855574b4c777efa1cd07207 /editor/state/storage.ml | |
parent | 72e3b16bbd258e63f047392c973ba5e8f0a823c8 (diff) |
Added import button in editor
Diffstat (limited to 'editor/state/storage.ml')
-rwxr-xr-x | editor/state/storage.ml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/editor/state/storage.ml b/editor/state/storage.ml index a790a9d..1bb8b81 100755 --- a/editor/state/storage.ml +++ b/editor/state/storage.ml @@ -157,3 +157,27 @@ let to_json (* Also add the home page *) let pages = Array.of_list @@ (save_for_id None)::pages in Brr.Json.encode (Jv.Id.to_jv pages) + +let of_json + : Jstr.t -> (unit, Jv.Error.t) result + = fun json -> + let result = Json.decode json in + Result.map + (fun v -> + Array.iter (Jv.Id.of_jv v) + ~f:(fun element -> + let key = element##.id + and content = object%js + val title = element##.title + val content = element##.content + val date = element##.date + end in + ignore @@ + save + ~check:(fun _ -> true) + content + key + )) + result + + |