Commit d2a24e7f authored by Karen Konou's avatar Karen Konou

Folder view: refresh tree when performing actions

parent 47a33fae
...@@ -48,6 +48,7 @@ type Props = ...@@ -48,6 +48,7 @@ type Props =
, session :: Session , session :: Session
, backFolder :: Boolean , backFolder :: Boolean
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reloadForest :: T.Box T2.Reload
) )
data FolderStyle = FolderUp | FolderChild data FolderStyle = FolderUp | FolderChild
...@@ -57,12 +58,12 @@ folderView props = R.createElement folderViewCpt props [] ...@@ -57,12 +58,12 @@ folderView props = R.createElement folderViewCpt props []
folderViewCpt :: R.Component Props folderViewCpt :: R.Component Props
folderViewCpt = here.component "folderViewCpt" cpt where folderViewCpt = here.component "folderViewCpt" cpt where
cpt {nodeId, session, backFolder, tasks} _ = do cpt {nodeId, session, backFolder, tasks, reloadForest} _ = do
setPopoverRef <- R.useRef Nothing setPopoverRef <- R.useRef Nothing
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
useLoader { nodeId, session, reload: reload'} loadFolders $ useLoader { nodeId, session, reload: reload'} loadFolders $
\folders -> folderViewMain {folders, nodeId, session, backFolder, tasks, reload, setPopoverRef} \folders -> folderViewMain {folders, nodeId, session, backFolder, tasks, reload, setPopoverRef, reloadForest}
type FolderViewProps = type FolderViewProps =
( (
...@@ -72,6 +73,7 @@ type FolderViewProps = ...@@ -72,6 +73,7 @@ type FolderViewProps =
, backFolder :: Boolean , backFolder :: Boolean
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reload :: T.Box T2.Reload , reload :: T.Box T2.Reload
, reloadForest :: T.Box T2.Reload
, setPopoverRef :: R.Ref (Maybe (Boolean -> Effect Unit)) , setPopoverRef :: R.Ref (Maybe (Boolean -> Effect Unit))
) )
...@@ -80,11 +82,11 @@ folderViewMain props = R.createElement folderViewMainCpt props [] ...@@ -80,11 +82,11 @@ folderViewMain props = R.createElement folderViewMainCpt props []
folderViewMainCpt :: R.Component FolderViewProps folderViewMainCpt :: R.Component FolderViewProps
folderViewMainCpt = here.component "folderViewMainCpt" cpt where folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt {nodeId, session, backFolder, tasks, setPopoverRef, reload, folders: tree@(NTree (LNode {parent_id: parentId, nodeType}) (folders))} _ = do cpt {nodeId, session, backFolder, tasks, setPopoverRef, reload, reloadForest, folders: tree@(NTree (LNode {parent_id: parentId, nodeType}) (folders))} _ = do
let foldersS = A.sortBy sortFolders folders let foldersS = A.sortBy sortFolders folders
let backHome = isBackHome nodeType let backHome = isBackHome nodeType
let parent = makeParentFolder parentId session backFolder backHome let parent = makeParentFolder parentId session backFolder backHome
let children = makeFolderElements foldersS {session, setPopoverRef, nodeId, tasks, reload} let children = makeFolderElements foldersS {session, setPopoverRef, nodeId, tasks, reload, reloadForest}
pure $ H.div {className: "fv folders"} $ parent <> children pure $ H.div {className: "fv folders"} $ parent <> children
...@@ -98,7 +100,8 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -98,7 +100,8 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
, setPopoverRef: props.setPopoverRef , setPopoverRef: props.setPopoverRef
, parentId: props.nodeId , parentId: props.nodeId
, tasks: props.tasks , tasks: props.tasks
, reload: props.reload} [] , reload: props.reload
, reloadForest: props.reloadForest} []
makeParentFolder :: Maybe Int -> Session -> Boolean -> Boolean -> Array R.Element makeParentFolder :: Maybe Int -> Session -> Boolean -> Boolean -> Array R.Element
makeParentFolder (Just parentId) session _ _ = makeParentFolder (Just parentId) session _ _ =
...@@ -159,6 +162,7 @@ type FolderProps = ...@@ -159,6 +162,7 @@ type FolderProps =
, parentId :: Int , parentId :: Int
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reload :: T.Box T2.Reload , reload :: T.Box T2.Reload
, reloadForest :: T.Box T2.Reload
| FolderSimpleProps | FolderSimpleProps
) )
...@@ -167,9 +171,9 @@ folder = R.createElement folderCpt ...@@ -167,9 +171,9 @@ folder = R.createElement folderCpt
folderCpt :: R.Component FolderProps folderCpt :: R.Component FolderProps
folderCpt = here.component "folderCpt" cpt where folderCpt = here.component "folderCpt" cpt where
cpt props@{style, text, nodeId, session, nodeType, setPopoverRef, parentId, tasks, reload} _ = do cpt props@{style, text, nodeId, session, nodeType, setPopoverRef, parentId, tasks, reload, reloadForest} _ = do
let sid = sessionId session let sid = sessionId session
let dispatch a = performAction a {setPopoverRef, session, nodeId, parentId, tasks, reload} let dispatch a = performAction a {setPopoverRef, session, nodeId, parentId, tasks, reload, reloadForest}
popoverRef <- R.useRef null popoverRef <- R.useRef null
R.useEffect' $ do R.useEffect' $ do
...@@ -253,6 +257,7 @@ type PerformActionProps = ...@@ -253,6 +257,7 @@ type PerformActionProps =
, parentId :: Int , parentId :: Int
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reload :: T.Box T2.Reload , reload :: T.Box T2.Reload
, reloadForest :: T.Box T2.Reload
) )
performAction :: Action -> Record PerformActionProps -> Aff Unit performAction :: Action -> Record PerformActionProps -> Aff Unit
...@@ -280,6 +285,7 @@ performAction = performAction' where ...@@ -280,6 +285,7 @@ performAction = performAction' where
refreshFolders p = do refreshFolders p = do
liftEffect $ T2.reload p.reload liftEffect $ T2.reload p.reload
liftEffect $ T2.reload p.reloadForest
closePopover p closePopover p
deleteNode' nt p@{ nodeId: id, parentId: parent_id } = do deleteNode' nt p@{ nodeId: id, parentId: parent_id } = do
......
...@@ -15,9 +15,9 @@ import Effect (Effect) ...@@ -15,9 +15,9 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_, throwError) import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Exception (error) import Effect.Exception (error)
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.CodeEditor as CE import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.FolderView as FV import Gargantext.Components.FolderView as FV
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.InputWithEnter (inputWithEnter) import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Node (NodePoly(..), HyperdataList) import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..)) import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..))
...@@ -38,15 +38,15 @@ import Toestand as T ...@@ -38,15 +38,15 @@ import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus" here = R2.here "Gargantext.Components.Nodes.Corpus"
type Props = ( nodeId :: Int, session :: Session, tasks :: T.Box GAT.Storage ) type Props = ( nodeId :: Int, session :: Session, tasks :: T.Box GAT.Storage, reloadForest :: T2.ReloadS )
corpusLayout :: R2.Leaf Props corpusLayout :: R2.Leaf Props
corpusLayout props = R.createElement corpusLayoutCpt props [] corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayoutCpt :: R.Component Props corpusLayoutCpt :: R.Component Props
corpusLayoutCpt = here.component "corpusLayout" cpt where corpusLayoutCpt = here.component "corpusLayout" cpt where
cpt { nodeId, session, tasks } _ = do cpt { nodeId, session, tasks, reloadForest } _ = do
pure $ corpusLayoutMain { key, nodeId, session, tasks } pure $ corpusLayoutMain { key, nodeId, session, tasks, reloadForest }
where where
key = show (sessionId session) <> "-" <> show nodeId key = show (sessionId session) <> "-" <> show nodeId
...@@ -55,6 +55,7 @@ type KeyProps = ...@@ -55,6 +55,7 @@ type KeyProps =
, key :: String , key :: String
, session :: Session , session :: Session
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reloadForest :: T2.ReloadS
) )
corpusLayoutMain :: R2.Leaf KeyProps corpusLayoutMain :: R2.Leaf KeyProps
...@@ -63,7 +64,7 @@ corpusLayoutMain props = R.createElement corpusLayoutMainCpt props [] ...@@ -63,7 +64,7 @@ corpusLayoutMain props = R.createElement corpusLayoutMainCpt props []
corpusLayoutMainCpt :: R.Component KeyProps corpusLayoutMainCpt :: R.Component KeyProps
corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt
where where
cpt { nodeId, key, session, tasks } _ = do cpt { nodeId, key, session, tasks, reloadForest } _ = do
viewType <- T.useBox Folders viewType <- T.useBox Folders
pure $ H.div {} [ pure $ H.div {} [
...@@ -73,7 +74,7 @@ corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt ...@@ -73,7 +74,7 @@ corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt
, H.div { className: "col-1" } [ FV.homeButton ] , H.div { className: "col-1" } [ FV.homeButton ]
] ]
] ]
, H.div {} [corpusLayoutSelection {state: viewType, key, session, nodeId, tasks}] , H.div {} [corpusLayoutSelection {state: viewType, key, session, nodeId, tasks, reloadForest}]
] ]
type SelectionProps = type SelectionProps =
...@@ -82,6 +83,7 @@ type SelectionProps = ...@@ -82,6 +83,7 @@ type SelectionProps =
, session :: Session , session :: Session
, state :: T.Box ViewType , state :: T.Box ViewType
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reloadForest :: T2.ReloadS
) )
corpusLayoutSelection :: R2.Leaf SelectionProps corpusLayoutSelection :: R2.Leaf SelectionProps
...@@ -89,14 +91,14 @@ corpusLayoutSelection props = R.createElement corpusLayoutSelectionCpt props [] ...@@ -89,14 +91,14 @@ corpusLayoutSelection props = R.createElement corpusLayoutSelectionCpt props []
corpusLayoutSelectionCpt :: R.Component SelectionProps corpusLayoutSelectionCpt :: R.Component SelectionProps
corpusLayoutSelectionCpt = here.component "corpusLayoutSelection" cpt where corpusLayoutSelectionCpt = here.component "corpusLayoutSelection" cpt where
cpt { nodeId, session, key, state, tasks} _ = do cpt { nodeId, session, key, state, tasks, reloadForest} _ = do
state' <- T.useLive T.unequal state state' <- T.useLive T.unequal state
viewType <- T.read state viewType <- T.read state
pure $ renderContent viewType nodeId session key tasks pure $ renderContent viewType nodeId session key tasks reloadForest
renderContent Folders nodeId session key tasks = FV.folderView { nodeId, session, backFolder: true, tasks } renderContent Folders nodeId session key tasks reloadForest = FV.folderView { nodeId, session, backFolder: true, tasks, reloadForest }
renderContent Code nodeId session key tasks = corpusLayoutWithKey { key, nodeId, session } renderContent Code nodeId session key tasks _ = corpusLayoutWithKey { key, nodeId, session }
type CorpusKeyProps = type CorpusKeyProps =
( nodeId :: Int ( nodeId :: Int
......
...@@ -24,6 +24,7 @@ import Reactix as R ...@@ -24,6 +24,7 @@ import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Routing.Hash (setHash) import Routing.Hash (setHash)
import Toestand as T import Toestand as T
import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Home" here = R2.here "Gargantext.Components.Nodes.Home"
...@@ -59,6 +60,7 @@ type HomeProps s l = ...@@ -59,6 +60,7 @@ type HomeProps s l =
, sessions :: s , sessions :: s
, showLogin :: l , showLogin :: l
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, reloadForest :: T.Box T2.Reload
) )
homeLayout :: forall s l. T.Read s Sessions => T.ReadWrite l Boolean homeLayout :: forall s l. T.Read s Sessions => T.ReadWrite l Boolean
...@@ -68,7 +70,7 @@ homeLayoutCpt :: forall s l. T.Read s Sessions => T.ReadWrite l Boolean ...@@ -68,7 +70,7 @@ homeLayoutCpt :: forall s l. T.Read s Sessions => T.ReadWrite l Boolean
=> R.Component (HomeProps s l) => R.Component (HomeProps s l)
homeLayoutCpt = here.component "homeLayout" cpt homeLayoutCpt = here.component "homeLayout" cpt
where where
cpt { backend, lang, sessions, showLogin, tasks} _ = do cpt { backend, lang, sessions, showLogin, tasks, reloadForest} _ = do
backend' <- T.useLive T.unequal backend backend' <- T.useLive T.unequal backend
sessions' <- T.useLive T.unequal sessions sessions' <- T.useLive T.unequal sessions
let landingData = langLandingData lang let landingData = langLandingData lang
...@@ -77,7 +79,7 @@ homeLayoutCpt = here.component "homeLayout" cpt ...@@ -77,7 +79,7 @@ homeLayoutCpt = here.component "homeLayout" cpt
[ H.div { className: "home-title container1" } [ H.div { className: "home-title container1" }
[ jumboTitle landingData ] [ jumboTitle landingData ]
, H.div { className: "home-research-form container1" } [] -- TODO , H.div { className: "home-research-form container1" } [] -- TODO
, joinButtonOrTutorial tasks sessions' (click backend') , joinButtonOrTutorial tasks reloadForest sessions' (click backend')
, H.div { className: "home-public container1" } , H.div { className: "home-public container1" }
[ renderPublic { } [ renderPublic { }
, H.div { className:"col-12 d-flex justify-content-center" } , H.div { className:"col-12 d-flex justify-content-center" }
...@@ -98,11 +100,11 @@ homeLayoutCpt = here.component "homeLayout" cpt ...@@ -98,11 +100,11 @@ homeLayoutCpt = here.component "homeLayout" cpt
T.write_ true showLogin T.write_ true showLogin
Just b -> T.write_ true showLogin Just b -> T.write_ true showLogin
joinButtonOrTutorial :: forall e. T.Box GAT.Storage -> Sessions -> (e -> Effect Unit) -> R.Element joinButtonOrTutorial :: forall e. T.Box GAT.Storage -> T2.ReloadS -> Sessions -> (e -> Effect Unit) -> R.Element
joinButtonOrTutorial tasks sessions click = joinButtonOrTutorial tasks reloadForest sessions click =
if Sessions.null sessions if Sessions.null sessions
then joinButton click then joinButton click
else tutorial {tasks, sessions: Sessions.unSessions sessions} else tutorial {tasks, reloadForest, sessions: Sessions.unSessions sessions}
joinButton :: forall e. (e -> Effect Unit) -> R.Element joinButton :: forall e. (e -> Effect Unit) -> R.Element
joinButton click = joinButton click =
...@@ -148,12 +150,12 @@ summary = ...@@ -148,12 +150,12 @@ summary =
, H.ol {} (map toSummary tutos) ] ] , H.ol {} (map toSummary tutos) ] ]
toSummary (Tuto x) = H.li {} [ H.a {href: "#" <> x.id} [ H.text x.title ]] toSummary (Tuto x) = H.li {} [ H.a {href: "#" <> x.id} [ H.text x.title ]]
tutorial :: R2.Leaf (sessions :: Array Session, tasks :: T.Box GAT.Storage) tutorial :: R2.Leaf (sessions :: Array Session, tasks :: T.Box GAT.Storage, reloadForest :: T.Box T2.Reload)
tutorial props = R.createElement tutorialCpt props [] tutorial props = R.createElement tutorialCpt props []
tutorialCpt :: R.Component (sessions :: Array Session, tasks:: T.Box GAT.Storage) tutorialCpt :: R.Component (sessions :: Array Session, tasks :: T.Box GAT.Storage, reloadForest :: T.Box T2.Reload)
tutorialCpt = here.component "tutorial" cpt where tutorialCpt = here.component "tutorial" cpt where
cpt {sessions, tasks} _ = do cpt {sessions, tasks, reloadForest} _ = do
let folders = makeFolders sessions let folders = makeFolders sessions
pure $ H.div { className: "mx-auto container" } pure $ H.div { className: "mx-auto container" }
...@@ -178,7 +180,7 @@ tutorialCpt = here.component "tutorial" cpt where ...@@ -178,7 +180,7 @@ tutorialCpt = here.component "tutorial" cpt where
sessionToFolder session@(Session {treeId, username, backend: (Backend {name})}) = sessionToFolder session@(Session {treeId, username, backend: (Backend {name})}) =
H.tr {} [ H.tr {} [
H.div { className: "d-flex justify-content-center" } [ H.text (username <> "@" <> name) ] H.div { className: "d-flex justify-content-center" } [ H.text (username <> "@" <> name) ]
, H.div {} [ FV.folderView {session, tasks, nodeId: treeId, backFolder: false} ] ] , H.div {} [ FV.folderView {session, tasks, reloadForest, nodeId: treeId, backFolder: false} ] ]
startTutos :: Array Tuto startTutos :: Array Tuto
startTutos = startTutos =
......
...@@ -279,7 +279,7 @@ corpusCpt = here.component "corpus" cpt where ...@@ -279,7 +279,7 @@ corpusCpt = here.component "corpus" cpt where
cpt props@{ boxes, nodeId } _ = do cpt props@{ boxes, nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session -> pure $ authed (Record.merge { content: \session ->
corpusLayout { nodeId, session, tasks: boxes.tasks } } sessionProps) [] corpusLayout { nodeId, session, tasks: boxes.tasks, reloadForest: boxes.reloadForest } } sessionProps) []
type CorpusDocumentProps = type CorpusDocumentProps =
( corpusId :: CorpusId ( corpusId :: CorpusId
...@@ -340,8 +340,8 @@ home :: R2.Component Props ...@@ -340,8 +340,8 @@ home :: R2.Component Props
home = R.createElement homeCpt home = R.createElement homeCpt
homeCpt :: R.Component Props homeCpt :: R.Component Props
homeCpt = here.component "home" cpt where homeCpt = here.component "home" cpt where
cpt props@{ boxes: boxes@{ backend, sessions, showLogin, tasks } } _ = do cpt props@{ boxes: boxes@{ backend, sessions, showLogin, tasks, reloadForest} } _ = do
pure $ homeLayout { backend, lang: LL_EN, sessions, showLogin, tasks } pure $ homeLayout { backend, lang: LL_EN, sessions, showLogin, tasks, reloadForest }
lists :: R2.Component SessionNodeProps lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt lists = R.createElement listsCpt
...@@ -410,7 +410,7 @@ teamCpt = here.component "team" cpt where ...@@ -410,7 +410,7 @@ teamCpt = here.component "team" cpt where
cpt props@{ boxes, nodeId } _ = do cpt props@{ boxes, nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session -> pure $ authed (Record.merge { content: \session ->
corpusLayout { nodeId, session, tasks: boxes.tasks} } sessionProps) [] corpusLayout { nodeId, session, tasks: boxes.tasks, reloadForest: boxes.reloadForest } } sessionProps) []
texts :: R2.Component SessionNodeProps texts :: R2.Component SessionNodeProps
texts = R.createElement textsCpt texts = R.createElement textsCpt
......
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