Commit edd951c2 authored by Karen Konou's avatar Karen Konou

[Folder view] Merge duplicate functions

parent 4ccd62ec
...@@ -92,13 +92,13 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -92,13 +92,13 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
, reload , reload
, session , session
, setPopoverRef } _ = do , setPopoverRef } _ = do
let foldersS = A.sortBy sortFolders children let folders' = A.sortBy sortFolders children
let parent = makeParentFolder parentNode session let parent = makeParentFolder parentNode session
let childrenEl = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef } let childrenEl = makeFolderElements folders' { boxes, nodeId, reload, session, setPopoverRef }
pure $ H.div {className: "fv folders"} $ parent <> childrenEl pure $ H.div {className: "fv folders"} $ parent <> childrenEl
makeFolderElements foldersS props = makeFolderElementsMap <$> foldersS where makeFolderElements folders' props = makeFolderElementsMap <$> folders' where
makeFolderElementsMap :: TreeNode -> R.Element makeFolderElementsMap :: TreeNode -> R.Element
makeFolderElementsMap node = folder { boxes: props.boxes makeFolderElementsMap node = folder { boxes: props.boxes
, nodeId: node.id , nodeId: node.id
...@@ -115,7 +115,6 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -115,7 +115,6 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
[ folderSimple {style: FolderUp, text: "..", nodeId: parent.id, nodeType: parent.node_type, session: session} [] ] [ folderSimple {style: FolderUp, text: "..", nodeId: parent.id, nodeType: parent.node_type, session: session} [] ]
makeParentFolder Nothing _ = [] makeParentFolder Nothing _ = []
sortFolders :: TreeNode-> TreeNode -> Ordering sortFolders :: TreeNode-> TreeNode -> Ordering
sortFolders a b = compare a.id b.id sortFolders a b = compare a.id b.id
...@@ -128,6 +127,13 @@ type FolderSimpleProps = ...@@ -128,6 +127,13 @@ type FolderSimpleProps =
, session :: Session , session :: Session
) )
getFolderPath :: GT.NodeType -> GT.SessionId -> Int -> AppRoute
getFolderPath nodeType sid nodeId = fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
icon _ nodeType = GT.fldr nodeType false
folderSimple :: R2.Component FolderSimpleProps folderSimple :: R2.Component FolderSimpleProps
folderSimple = R.createElement folderSimpleCpt folderSimple = R.createElement folderSimpleCpt
...@@ -148,14 +154,6 @@ folderSimpleCpt = here.component "folderSimpleCpt" cpt where ...@@ -148,14 +154,6 @@ folderSimpleCpt = here.component "folderSimpleCpt" cpt where
| rootId == nodeId = Home | rootId == nodeId = Home
| otherwise = getFolderPath nType sid nId | otherwise = getFolderPath nType sid nId
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
icon _ nodeType = GT.fldr nodeType false
getFolderPath :: GT.NodeType -> GT.SessionId -> Int -> AppRoute
getFolderPath nodeType sid nodeId = fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
type FolderProps = type FolderProps =
( boxes :: Boxes ( boxes :: Boxes
, parentId :: Int , parentId :: Int
...@@ -202,14 +200,6 @@ folderCpt = here.component "folderCpt" cpt where ...@@ -202,14 +200,6 @@ folderCpt = here.component "folderCpt" cpt where
, H.br {} , H.br {}
, H.text text]] , H.text text]]
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
icon _ nodeType = GT.fldr nodeType false
getFolderPath :: GT.NodeType -> GT.SessionId -> Int -> AppRoute
getFolderPath nodeType sid nodeId = fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
onPopoverClose popoverRef _ = Popover.setOpen popoverRef false onPopoverClose popoverRef _ = Popover.setOpen popoverRef false
popOverIcon = H.span { className: "fv action" } [ popOverIcon = H.span { className: "fv action" } [
......
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