Commit 7feb3468 authored by Karen Konou's avatar Karen Konou

[URL Share] Redirect to shared url after login

parent 35405f46
Pipeline #5918 failed with stage
in 0 seconds
...@@ -10,22 +10,24 @@ module Gargantext.Components.App.Store ...@@ -10,22 +10,24 @@ module Gargantext.Components.App.Store
) where ) where
import Gargantext.Prelude
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Set as Set import Data.Set as Set
import Data.Tuple (Tuple)
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Lang as Lang import Gargantext.Components.Lang as Lang
import Gargantext.Components.Nodes.Lists.SidePanel as ListsSP import Gargantext.Components.Nodes.Lists.SidePanel as ListsSP
import Gargantext.Components.Nodes.Texts.Types as TextsT import Gargantext.Components.Nodes.Texts.Types as TextsT
import Gargantext.Components.Themes as Themes import Gargantext.Components.Themes as Themes
import Gargantext.Ends (Backend) import Gargantext.Ends (Backend)
import Gargantext.Prelude
import Gargantext.Routes (AppRoute(Home), Tile) import Gargantext.Routes (AppRoute(Home), Tile)
import Gargantext.Sessions (Session, Sessions) import Gargantext.Sessions (Session, Sessions)
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Sessions.Types (OpenNodes(..)) import Gargantext.Sessions.Types (OpenNodes(..))
import Gargantext.Types (FrontendError, Handed(RightHanded), SidePanelState(..)) import Gargantext.Types (FrontendError, Handed(RightHanded), ID, SidePanelState(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Stores as Stores import Gargantext.Utils.Stores as Stores
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
...@@ -45,6 +47,7 @@ type Store = ...@@ -45,6 +47,7 @@ type Store =
, graphVersion :: T2.ReloadS , graphVersion :: T2.ReloadS
, handed :: T.Box Handed , handed :: T.Box Handed
, lang :: T.Box Lang.LandingLang , lang :: T.Box Lang.LandingLang
, loginRedirect :: T.Box (Maybe (Tuple String ID))
, pinnedTreeId :: T.Box (Map String Int) , pinnedTreeId :: T.Box (Map String Int)
, reloadForest :: T2.ReloadS , reloadForest :: T2.ReloadS
, reloadMainPage :: T2.ReloadS , reloadMainPage :: T2.ReloadS
...@@ -73,6 +76,7 @@ type State = ...@@ -73,6 +76,7 @@ type State =
, graphVersion :: T2.Reload , graphVersion :: T2.Reload
, handed :: Handed , handed :: Handed
, lang :: Lang.LandingLang , lang :: Lang.LandingLang
, loginRedirect :: Maybe (Tuple String ID)
, pinnedTreeId :: Map String Int , pinnedTreeId :: Map String Int
, reloadForest :: T2.Reload , reloadForest :: T2.Reload
, reloadMainPage :: T2.Reload , reloadMainPage :: T2.Reload
...@@ -102,6 +106,7 @@ options = ...@@ -102,6 +106,7 @@ options =
, graphVersion : T2.newReload , graphVersion : T2.newReload
, handed : RightHanded , handed : RightHanded
, lang : Lang.LL_EN , lang : Lang.LL_EN
, loginRedirect : Nothing
, pinnedTreeId : Map.empty , pinnedTreeId : Map.empty
, reloadForest : T2.newReload , reloadForest : T2.newReload
, reloadMainPage : T2.newReload , reloadMainPage : T2.newReload
......
...@@ -21,20 +21,22 @@ import Data.Array (head) ...@@ -21,20 +21,22 @@ import Data.Array (head)
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.String as DST import Data.String as DST
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Milliseconds(..), delay, launchAff_) import Effect.Aff (Milliseconds(..), delay, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), Elevation(..), ModalSizing(..), Position(..), TooltipPosition(..), Variant(..)) import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), Elevation(..), ModalSizing(..), Position(..), TooltipPosition(..), Variant(..))
import Gargantext.Components.Login.PasswordForm as PasswordForm
import Gargantext.Components.Login.LoginForm as LoginForm import Gargantext.Components.Login.LoginForm as LoginForm
import Gargantext.Components.Login.PasswordForm as PasswordForm
import Gargantext.Components.Login.Types (FormType(..)) import Gargantext.Components.Login.Types (FormType(..))
import Gargantext.Components.NgramsTable.Loader as NTL import Gargantext.Components.NgramsTable.Loader as NTL
import Gargantext.Ends (Backend(..)) import Gargantext.Ends (Backend(..))
import Gargantext.Hooks.Loader as GHL import Gargantext.Hooks.Loader as GHL
import Gargantext.Sessions (Session(..), Sessions, Action(Logout), unSessions) import Gargantext.Sessions (Session(..), Sessions, Action(Logout), unSessions)
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Types (ID)
import Gargantext.Utils ((?)) import Gargantext.Utils ((?))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
...@@ -51,10 +53,11 @@ here = R2.here "Gargantext.Components.Login" ...@@ -51,10 +53,11 @@ here = R2.here "Gargantext.Components.Login"
-- if not logged user can not save his work -- if not logged user can not save his work
type Props = type Props =
( backend :: T.Box (Maybe Backend) ( backend :: T.Box (Maybe Backend)
, backends :: Array Backend , backends :: Array Backend
, sessions :: T.Box Sessions , sessions :: T.Box Sessions
, visible :: T.Box Boolean , visible :: T.Box Boolean
, loginRedirect :: T.Box (Maybe (Tuple String ID))
) )
login :: R2.Leaf Props login :: R2.Leaf Props
...@@ -83,7 +86,7 @@ loginContainer = R2.leaf loginContainerCpt ...@@ -83,7 +86,7 @@ loginContainer = R2.leaf loginContainerCpt
loginContainerCpt :: R.Component Props loginContainerCpt :: R.Component Props
loginContainerCpt = here.component "container" cpt where loginContainerCpt = here.component "container" cpt where
cpt props@{ sessions, visible } _ = do cpt props@{ sessions, visible, loginRedirect } _ = do
-- | States -- | States
-- | -- |
mBackend <- R2.useLive' props.backend mBackend <- R2.useLive' props.backend
...@@ -110,6 +113,7 @@ loginContainerCpt = here.component "container" cpt where ...@@ -110,6 +113,7 @@ loginContainerCpt = here.component "container" cpt where
, formType , formType
, sessions , sessions
, visible , visible
, loginRedirect
} }
ForgotPassword -> ForgotPassword ->
PasswordForm.component PasswordForm.component
......
...@@ -6,8 +6,9 @@ import Gargantext.Prelude ...@@ -6,8 +6,9 @@ import Gargantext.Prelude
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Foldable (foldl, intercalate) import Data.Foldable (foldl, intercalate)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..), fromMaybe)
import Data.String as String import Data.String as String
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
...@@ -18,9 +19,12 @@ import Gargantext.Components.Login.Types (AuthRequest(..), FormType(..)) ...@@ -18,9 +19,12 @@ import Gargantext.Components.Login.Types (AuthRequest(..), FormType(..))
import Gargantext.Ends (Backend) import Gargantext.Ends (Backend)
import Gargantext.Hooks.FormValidation (VForm, useFormValidation) import Gargantext.Hooks.FormValidation (VForm, useFormValidation)
import Gargantext.Hooks.FormValidation.Unboxed as FV import Gargantext.Hooks.FormValidation.Unboxed as FV
import Gargantext.Hooks.LinkHandler (useLinkHandler)
import Gargantext.Hooks.StateRecord (useStateRecord) import Gargantext.Hooks.StateRecord (useStateRecord)
import Gargantext.Sessions (Session, Sessions, postAuthRequest) import Gargantext.Routes as GR
import Gargantext.Sessions (Session, Sessions, postAuthRequest, sessionId)
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Types (ID, NodeType(..))
import Gargantext.Utils ((?)) import Gargantext.Utils ((?))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
...@@ -33,10 +37,11 @@ here :: R2.Here ...@@ -33,10 +37,11 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Login.Form" here = R2.here "Gargantext.Components.Login.Form"
type Props = type Props =
( backend :: Backend ( backend :: Backend
, formType :: T.Box FormType , formType :: T.Box FormType
, sessions :: T.Box Sessions , sessions :: T.Box Sessions
, visible :: T.Box Boolean , visible :: T.Box Boolean
, loginRedirect :: T.Box (Maybe (Tuple String ID))
) )
component :: R2.Leaf Props component :: R2.Leaf Props
...@@ -47,6 +52,7 @@ componentCpt = here.component "main" cpt where ...@@ -47,6 +52,7 @@ componentCpt = here.component "main" cpt where
, formType , formType
, sessions , sessions
, visible , visible
, loginRedirect
} _ = do } _ = do
-- | States -- | States
-- | -- |
...@@ -56,6 +62,8 @@ componentCpt = here.component "main" cpt where ...@@ -56,6 +62,8 @@ componentCpt = here.component "main" cpt where
onPending' /\ onPending onPending' /\ onPending
<- R2.useBox' false <- R2.useBox' false
loginRedirect' <- R2.useLive' loginRedirect
-- | Hooks -- | Hooks
-- | -- |
{ state { state
...@@ -65,6 +73,8 @@ componentCpt = here.component "main" cpt where ...@@ -65,6 +73,8 @@ componentCpt = here.component "main" cpt where
fv <- useFormValidation fv <- useFormValidation
{ goToRoute } <- useLinkHandler
-- | Behaviors -- | Behaviors
-- | -- |
let let
...@@ -96,6 +106,11 @@ componentCpt = here.component "main" cpt where ...@@ -96,6 +106,11 @@ componentCpt = here.component "main" cpt where
Right session_ -> liftEffect Right session_ -> liftEffect
$ Sessions.change (Sessions.Login session_) sessions $ Sessions.change (Sessions.Login session_) sessions
*> T.write_ false visible *> T.write_ false visible
*> case loginRedirect' of
Just (nodeType /\ nodeId) -> do
T.write_ Nothing loginRedirect
goToRoute $ fromMaybe GR.Login $ GR.nodeTypeAppRoute (fromMaybe Node $ read nodeType) (sessionId session_) nodeId
Nothing -> pure unit
T.write_ false onPending T.write_ false onPending
......
...@@ -12,10 +12,10 @@ import Data.Array as A ...@@ -12,10 +12,10 @@ import Data.Array as A
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Data.Map as M import Data.Map as M
import Data.Maybe (Maybe(..), fromMaybe, maybe) import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Tuple (Tuple(..))
import Data.UUID (UUID) import Data.UUID (UUID)
import Data.UUID as UUID import Data.UUID as UUID
import Effect (Effect) import Effect (Effect)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes) import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.ErrorsView as ErrorsView import Gargantext.Components.ErrorsView as ErrorsView
import Gargantext.Components.Forest (forestLayout) import Gargantext.Components.Forest (forestLayout)
...@@ -622,12 +622,13 @@ listsCpt = here.component "lists" cpt where ...@@ -622,12 +622,13 @@ listsCpt = here.component "lists" cpt where
-------------------------------------------------------------- --------------------------------------------------------------
login' :: Boxes -> R.Element login' :: Boxes -> R.Element
login' { backend, sessions, showLogin: visible } = login' { backend, sessions, showLogin: visible, loginRedirect } =
login login
{ backend { backend
, backends: A.fromFoldable defaultBackends , backends: A.fromFoldable defaultBackends
, sessions , sessions
, visible , visible
, loginRedirect
} }
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -790,6 +791,7 @@ shareCpt = here.component "share" cpt where ...@@ -790,6 +791,7 @@ shareCpt = here.component "share" cpt where
case unSessions sessions' of case unSessions sessions' of
[] -> do [] -> do
R.useEffect' $ T.write_ true boxes.showLogin R.useEffect' $ T.write_ true boxes.showLogin
R.useEffect' $ T.write_ (Just (Tuple nodeType nodeId)) boxes.loginRedirect
R.useEffect' $ goToRoute Login R.useEffect' $ goToRoute Login
pure $ H.text "no session" pure $ H.text "no session"
s -> case head s of s -> case head s of
...@@ -798,5 +800,6 @@ shareCpt = here.component "share" cpt where ...@@ -798,5 +800,6 @@ shareCpt = here.component "share" cpt where
pure $ H.text $ "session route: " <> (show $ fromMaybe Login $ GR.nodeTypeAppRoute (fromMaybe Node $ read nodeType) (sessionId s') nodeId) pure $ H.text $ "session route: " <> (show $ fromMaybe Login $ GR.nodeTypeAppRoute (fromMaybe Node $ read nodeType) (sessionId s') nodeId)
Nothing -> do Nothing -> do
R.useEffect' $ T.write_ true boxes.showLogin R.useEffect' $ T.write_ true boxes.showLogin
R.useEffect' $ T.write_ (Just (Tuple nodeType nodeId)) boxes.loginRedirect
R.useEffect' $ goToRoute Login R.useEffect' $ goToRoute Login
pure $ H.text "no session" pure $ H.text "no session"
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