Commit 8543cfe2 authored by Karen Konou's avatar Karen Konou

Folder view: workaround for back folder (hacky)

parent 4c0d1876
'use strict';
exports.back = function() {
return function() {
history.back();
}
}
\ No newline at end of file
...@@ -2,10 +2,11 @@ module Gargantext.Components.FolderView where ...@@ -2,10 +2,11 @@ module Gargantext.Components.FolderView where
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..), fTreeID) import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..), fTreeID)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (compare, pure, ($), (<$>), (<>), Ordering) import Gargantext.Prelude (Ordering, Unit, compare, pure, ($), (<$>), (<>))
import Gargantext.Routes (AppRoute(Home), SessionRoute(..), appPath, nodeTypeAppRoute) import Gargantext.Routes (AppRoute(Home), SessionRoute(..), appPath, nodeTypeAppRoute)
import Gargantext.Sessions (Session, get, sessionId) import Gargantext.Sessions (Session, get, sessionId)
import Gargantext.Types (NodeType(..), SessionId, fldr) import Gargantext.Types (NodeType(..), SessionId, fldr)
...@@ -13,42 +14,46 @@ import Gargantext.Utils.Reactix as R2 ...@@ -13,42 +14,46 @@ import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
foreign import back :: Effect Unit
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.FolderView" here = R2.here "Gargantext.Components.FolderView"
type Props = type Props =
( nodeId :: Int ( nodeId :: Int
, session :: Session , session :: Session
, backFolder :: Boolean
) )
data FolderStyle = FolderUp | FolderChild data FolderStyle = FolderUp | FolderChild
folderViewLoad :: R2.Leaf Props folderView :: R2.Leaf Props
folderViewLoad props = R.createElement folderViewLoadCpt props [] folderView props = R.createElement folderViewCpt props []
folderViewLoadCpt :: R.Component Props folderViewCpt :: R.Component Props
folderViewLoadCpt = here.component "folderViewLoadCpt" cpt where folderViewCpt = here.component "folderViewCpt" cpt where
cpt {nodeId, session} _ = do cpt {nodeId, session, backFolder} _ = do
useLoader {nodeId, session} loadFolders $ useLoader {nodeId, session, backFolder} loadFolders $
\folders -> folderView {folders, nodeId, session} \folders -> folderViewMain {folders, nodeId, session, backFolder}
type FolderViewProps = type FolderViewProps =
( (
nodeId :: Int nodeId :: Int
, folders:: FTree , folders:: FTree
, session :: Session , session :: Session
, backFolder :: Boolean
) )
folderView :: Record FolderViewProps -> R.Element folderViewMain :: Record FolderViewProps -> R.Element
folderView props = R.createElement folderViewCpt props [] folderViewMain props = R.createElement folderViewMainCpt props []
folderViewCpt :: R.Component FolderViewProps folderViewMainCpt :: R.Component FolderViewProps
folderViewCpt = here.component "folderViewCpt" cpt where folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt {nodeId, session, folders: (NTree (LNode {parent_id: parentId}) (folders))} _ = do cpt {nodeId, session, backFolder, folders: (NTree (LNode {parent_id: parentId}) (folders))} _ = do
let sid = sessionId session let sid = sessionId session
let foldersS = A.sortBy sortFolders folders let foldersS = A.sortBy sortFolders folders
let children = makeFolderElements foldersS sid let children = makeFolderElements foldersS sid
let parent = makeParentFolder parentId sid let parent = makeParentFolder parentId sid backFolder
pure $ H.div {className: "folders"} $ parent <> children pure $ H.div {className: "folders"} $ parent <> children
...@@ -57,12 +62,15 @@ folderViewCpt = here.component "folderViewCpt" cpt where ...@@ -57,12 +62,15 @@ folderViewCpt = here.component "folderViewCpt" cpt where
makeFolderElementsMap :: NTree LNode -> R.Element makeFolderElementsMap :: NTree LNode -> R.Element
makeFolderElementsMap (NTree (LNode node) _) = folder {style: FolderChild, text: node.name, nodeId: node.id, nodeType: node.nodeType, sid: sid} [] makeFolderElementsMap (NTree (LNode node) _) = folder {style: FolderChild, text: node.name, nodeId: node.id, nodeType: node.nodeType, sid: sid} []
makeParentFolder :: Maybe Int -> SessionId -> Array R.Element makeParentFolder :: Maybe Int -> SessionId -> Boolean -> Array R.Element
makeParentFolder (Just parentId) sid = makeParentFolder (Just parentId) sid _ =
-- FIXME: The NodeType here should not be hardcoded to FolderPrivate but we currently can't get the actual NodeType -- FIXME: The NodeType here should not be hardcoded to FolderPrivate but we currently can't get the actual NodeType
-- without performing another API call. Also parentId is never being returned by this API even when it clearly exists -- without performing another API call. Also parentId is never being returned by this API even when it clearly exists
[ folder {style: FolderUp, text: "..", nodeId: parentId, nodeType: FolderPrivate, sid: sid} [] ] [ folder {style: FolderUp, text: "..", nodeId: parentId, nodeType: FolderPrivate, sid: sid} [] ]
makeParentFolder Nothing _ = [] makeParentFolder Nothing _ true = [ H.button {className: "btn btn-primary", on: { click: back } } [ H.i { className: "fa fa-folder-open" } []
, H.br {}
, H.text ".."] ]
makeParentFolder Nothing _ _ = []
sortFolders :: FTree -> FTree -> Ordering sortFolders :: FTree -> FTree -> Ordering
sortFolders a b = compare (fTreeID a) (fTreeID b) sortFolders a b = compare (fTreeID a) (fTreeID b)
......
...@@ -90,7 +90,7 @@ corpusLayoutSelectionCpt = here.component "corpusLayoutSelection" cpt where ...@@ -90,7 +90,7 @@ corpusLayoutSelectionCpt = here.component "corpusLayoutSelection" cpt where
pure $ renderContent viewType nodeId session key pure $ renderContent viewType nodeId session key
renderContent Folders nodeId session key = FV.folderViewLoad { nodeId, session } renderContent Folders nodeId session key = FV.folderView { nodeId, session, backFolder: true }
renderContent Code nodeId session key = corpusLayoutWithKey { key, nodeId, session } renderContent Code nodeId session key = corpusLayoutWithKey { key, nodeId, session }
......
...@@ -146,7 +146,7 @@ tutorialCpt = here.component "tutorial" cpt where ...@@ -146,7 +146,7 @@ tutorialCpt = here.component "tutorial" cpt where
pure $ H.div { className: "mx-auto container" } pure $ H.div { className: "mx-auto container" }
[ H.div {className: "d-flex justify-content-center"} [ H.div {className: "d-flex justify-content-center"}
[FV.folderViewLoad {session, nodeId}] [FV.folderView {session, nodeId, backFolder: false}]
, H.h1 {} [H.text "Welcome!"] , H.h1 {} [H.text "Welcome!"]
, H.h2 {} [H.text "For easy start, just watch the tutorials"] , H.h2 {} [H.text "For easy start, just watch the tutorials"]
, summary , summary
......
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