From e66534eefb5979c1ec5e0a28e9c29969ae2c9884 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Sun, 13 Oct 2024 11:55:20 +0200
Subject: improve REST API

---
 frontend/app/Page/EditValue.hs | 4 +---
 frontend/app/Schema.hs         | 8 ++++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

(limited to 'frontend/app')

diff --git a/frontend/app/Page/EditValue.hs b/frontend/app/Page/EditValue.hs
index 7945874..942d9db 100644
--- a/frontend/app/Page/EditValue.hs
+++ b/frontend/app/Page/EditValue.hs
@@ -11,13 +11,11 @@ import ACMS.API.REST.Collection qualified as API.REST.Collection
 import Control.Monad.Catch (SomeException, try)
 import Data.Aeson qualified as A
 import Data.Aeson.KeyMap qualified as AM
-import Data.ByteString.Lazy.UTF8 qualified as LB
 import Data.Maybe
 import Effect (Eff)
 import Form qualified as F
 import Miso
 import Miso.String (toMisoString)
-import Safe (headMay)
 import Schema
 import Collection
 
@@ -31,7 +29,7 @@ data Model = Model
 initialModel :: CollectionItem -> JSM (Either SomeException Model)
 initialModel collectionItem = do
   schema' <- try (API.REST.Collection.schema collectionItem.collection)
-  input' <- try (headMay <$> API.REST.Collection.read collectionItem)
+  input' <- try (API.REST.Collection.read collectionItem)
   pure do
     schema <- schema'
     input <- input'
diff --git a/frontend/app/Schema.hs b/frontend/app/Schema.hs
index 8e49d47..c15e1d1 100644
--- a/frontend/app/Schema.hs
+++ b/frontend/app/Schema.hs
@@ -9,6 +9,9 @@ module Schema
   )
 where
 
+#ifdef ghcjs_HOST_OS
+import Data.Text qualified as T
+#endif
 import Control.Applicative ((<|>))
 import Data.Aeson qualified as A
 import Data.Aeson.Key qualified as AK
@@ -42,6 +45,11 @@ instance A.FromJSON Schema where
       <*> v A..: "title"
       <*> v A..: "type"
 
+#ifdef ghcjs_HOST_OS
+instance A.FromJSONKey MisoString where
+  parseJSON = fromMisoString @T.Text <$> parseJSON
+#endif
+
 data Property
   = Type MisoString
   | Reference MisoString
-- 
cgit v1.2.3