Commit a2d69c48 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch '371-dev-user-profile' of...

Merge branch '371-dev-user-profile' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-merge
parents 28e0d4d7 30143611
......@@ -13,6 +13,7 @@ type Username = String
type Password = String
type Token = String
type TreeId = Int
type UserId = Int
newtype AuthRequest = AuthRequest
{ username :: Username
......@@ -41,6 +42,7 @@ derive newtype instance JSON.WriteForeign AuthInvalid
newtype AuthData = AuthData
{ token :: Token
, tree_id :: TreeId
, user_id :: UserId
}
derive instance Generic AuthData _
derive instance Newtype AuthData _
......@@ -50,5 +52,5 @@ derive newtype instance JSON.WriteForeign AuthData
instance Eq AuthData where
eq = genericEq
_AuthData :: Iso' AuthData { token :: Token, tree_id :: TreeId }
_AuthData :: Iso' AuthData { token :: Token, tree_id :: TreeId, user_id :: UserId }
_AuthData = iso (\(AuthData v) -> v) AuthData
......@@ -21,8 +21,7 @@ import Gargantext.Config.REST (logRESTError)
import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as Routes
import Gargantext.Sessions (WithSession, WithSessionContext, sessionId)
import Gargantext.Sessions (Session(..), WithSession, WithSessionContext, sessionId)
import Gargantext.Types (FrontendError)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
......@@ -101,11 +100,13 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt where
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
let Session {userId} = session
cacheState <- T.useBox LT.CacheOn
useLoader { errorHandler
, loader: getUserInfoWithReload
, path: { nodeId, reload: reload', session }
, path: { nodeId: userId, reload: reload', session }
, render: \userInfo@{ ui_username } ->
H.ul { className: "col-md-12 list-group" } [
display { title: fromMaybe "no name" (Just ui_username) }
......@@ -126,7 +127,8 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt where
onUpdateUserInfo :: T.Box (Array FrontendError) -> T2.ReloadS -> UserInfo -> Effect Unit
onUpdateUserInfo errors reload ui = do
launchAff_ $ do
res <- saveUserInfo session nodeId ui
let Session {userId} = session
res <- saveUserInfo session userId ui
handleRESTError errors res $ \_ ->
liftEffect $ T2.reload reload
......
......@@ -117,8 +117,8 @@ postAuthRequest backend ar@(AuthRequest {username}) =
decode (Left _err) = Left "Error when sending REST.post"
decode (Right (AuthResponse ar2))
| {inval: Just (AuthInvalid {message})} <- ar2 = Left message
| {valid: Just (AuthData {token, tree_id})} <- ar2 =
Right $ Session { backend, caches: Map.empty, token, treeId: tree_id, username }
| {valid: Just (AuthData {token, tree_id, user_id})} <- ar2 =
Right $ Session { backend, caches: Map.empty, token, treeId: tree_id, username, userId: user_id }
| otherwise = Left "Invalid response from server"
get :: forall a p. JSON.ReadForeign a => ToUrl Session p =>
......
......@@ -6,6 +6,8 @@ module Gargantext.Sessions.Types
, cleanBackendUrl
) where
import Gargantext.Prelude
import Data.Array as A
import Data.Either (Either(..))
import Data.Eq.Generic (genericEq)
......@@ -23,10 +25,9 @@ import Data.Show.Generic (genericShow)
import Data.String as DST
import Data.Tuple (Tuple)
import Foreign.Object as Object
import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Components.Login.Types (TreeId, UserId)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Ends (class ToUrl, Backend(..), backendUrl, sessionPath)
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute)
import Gargantext.Types (NodePath, SessionId(..), nodePath)
import Gargantext.Utils.JSON as GJSON
......@@ -43,6 +44,7 @@ newtype Session = Session
, token :: String
, treeId :: TreeId
, username :: String
, userId :: UserId
}
------------------------------------------------------------------------
......@@ -57,8 +59,8 @@ instance JSON.ReadForeign Session where
let rUp = r { caches = Map.fromFoldable (GUT.mapFst (fromMaybe 0 <<< Int.fromString) <$> objTuple) }
pure $ Session rUp
instance JSON.WriteForeign Session where
writeImpl (Session { backend, caches, token, treeId, username }) =
JSON.writeImpl { backend, caches: caches', token, treeId, username }
writeImpl (Session { backend, caches, token, treeId, username, userId}) =
JSON.writeImpl { backend, caches: caches', token, treeId, username, userId }
where
caches' = JSON.writeImpl $ Object.fromFoldable (GUT.mapFst show <$> Map.toUnfoldable caches :: Array (Tuple String NT.CacheState))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment