Commit 4a29c949 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[texts] add side panel with doc view

parent 784d5604
...@@ -11,4 +11,8 @@ ...@@ -11,4 +11,8 @@
top: 50%; top: 50%;
} }
.table .doc-chooser {
cursor: pointer;
}
/*# sourceMappingURL=Styles.css.map */ /*# sourceMappingURL=Styles.css.map */
...@@ -8,3 +8,7 @@ ...@@ -8,3 +8,7 @@
position: absolute position: absolute
left: 50% left: 50%
top: 50% top: 50%
.table
.doc-chooser
cursor: pointer
...@@ -118,7 +118,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -118,7 +118,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
corpusLayout { nodeId, session } corpusLayout { nodeId, session }
] ]
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested [ CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested [
documentLayout { corpusId: Just corpusId, nodeId, listId, session } documentLayout { listId, mCorpusId: Just corpusId, nodeId, session } []
] ]
Dashboard sid nodeId -> withSession sid $ \session -> forested [ Dashboard sid nodeId -> withSession sid $ \session -> forested [
dashboardLayout { nodeId, session } dashboardLayout { nodeId, session }
...@@ -126,7 +126,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where ...@@ -126,7 +126,7 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
Document sid listId nodeId -> Document sid listId nodeId ->
withSession sid $ withSession sid $
\session -> forested [ \session -> forested [
documentLayout { corpusId: Nothing, nodeId, listId, session } documentLayout { listId, mCorpusId: Nothing, nodeId, session } []
] ]
Folder sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ] Folder sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
FolderPrivate sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ] FolderPrivate sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
......
...@@ -15,6 +15,7 @@ import Data.String as Str ...@@ -15,6 +15,7 @@ import Data.String as Str
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst) import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log, log2)
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
...@@ -33,7 +34,7 @@ import Gargantext.Hooks.Loader (useLoader, useLoaderWithCacheAPI, HashedResponse ...@@ -33,7 +34,7 @@ import Gargantext.Hooks.Loader (useLoader, useLoaderWithCacheAPI, HashedResponse
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI)) import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete) import Gargantext.Sessions (Session, sessionId, get, delete)
import Gargantext.Types (NodeID, NodeType(..), OrderBy(..), TableResult, TabSubType, TabType, showTabType') import Gargantext.Types (ListId, NodeID, NodeType(..), OrderBy(..), TableResult, TabSubType, TabType, showTabType')
import Gargantext.Utils (sortWith) import Gargantext.Utils (sortWith)
import Gargantext.Utils.CacheAPI as GUC import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.QueryString (joinQueryStrings, mQueryParamS, queryParam, queryParamS) import Gargantext.Utils.QueryString (joinQueryStrings, mQueryParamS, queryParam, queryParamS)
...@@ -97,7 +98,7 @@ docViewLayoutCpt = R.hooksComponentWithModule thisModule "docViewLayout" cpt ...@@ -97,7 +98,7 @@ docViewLayoutCpt = R.hooksComponentWithModule thisModule "docViewLayout" cpt
cpt layout _children = do cpt layout _children = do
query <- R.useState' "" query <- R.useState' ""
let params = T.initialParams let params = T.initialParams
pure $ docView { layout, params, query } pure $ docView { layout, params, query } []
type Props = ( type Props = (
layout :: Record LayoutProps layout :: Record LayoutProps
...@@ -105,8 +106,8 @@ type Props = ( ...@@ -105,8 +106,8 @@ type Props = (
, query :: R.State Query , query :: R.State Query
) )
docView :: Record Props -> R.Element docView :: R2.Component Props
docView props = R.createElement docViewCpt props [] docView = R.createElement docViewCpt
docViewCpt :: R.Component Props docViewCpt :: R.Component Props
docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt where docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt where
...@@ -255,7 +256,9 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where ...@@ -255,7 +256,9 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where
Tuple res.count docs Tuple res.count docs
case cacheState of case cacheState of
(NT.CacheOn /\ _) -> do (NT.CacheOn /\ _) -> do
let paint (Tuple count docs) = page params (props { totalRecords = count }) docs let paint (Tuple count docs) = page { documents: docs
, layout: props { totalRecords = count }
, params } []
mkRequest :: PageParams -> GUC.Request mkRequest :: PageParams -> GUC.Request
mkRequest p = GUC.makeGetRequest session $ tableRoute p mkRequest p = GUC.makeGetRequest session $ tableRoute p
...@@ -276,7 +279,7 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where ...@@ -276,7 +279,7 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where
, layout: props { params = fst paramsS , layout: props { params = fst paramsS
, totalRecords = count } , totalRecords = count }
, localCategories , localCategories
, params: paramsS } , params: paramsS } []
useLoader (path { params = fst paramsS }) loader render useLoader (path { params = fst paramsS }) loader render
type PageProps = ( type PageProps = (
...@@ -285,14 +288,14 @@ type PageProps = ( ...@@ -285,14 +288,14 @@ type PageProps = (
, params :: T.Params , params :: T.Params
) )
page :: T.Params -> Record PageLayoutProps -> Array DocumentsView -> R.Element page :: R2.Component PageProps
page params layout documents = R.createElement pageCpt { documents, layout, params } [] page = R.createElement pageCpt
pageCpt :: R.Component PageProps pageCpt :: R.Component PageProps
pageCpt = R.hooksComponentWithModule thisModule "pageCpt" cpt where pageCpt = R.hooksComponentWithModule thisModule "pageCpt" cpt where
cpt { documents, layout, params } _ = do cpt { documents, layout, params } _ = do
paramsS <- R.useState' params paramsS <- R.useState' params
pure $ pagePaint { documents, layout, params: paramsS } pure $ pagePaint { documents, layout, params: paramsS } []
type PagePaintProps = ( type PagePaintProps = (
documents :: Array DocumentsView documents :: Array DocumentsView
...@@ -300,25 +303,29 @@ type PagePaintProps = ( ...@@ -300,25 +303,29 @@ type PagePaintProps = (
, params :: R.State T.Params , params :: R.State T.Params
) )
pagePaint :: Record PagePaintProps -> R.Element pagePaint :: R2.Component PagePaintProps
pagePaint props = R.createElement pagePaintCpt props [] pagePaint = R.createElement pagePaintCpt
pagePaintCpt :: R.Component PagePaintProps pagePaintCpt :: R.Component PagePaintProps
pagePaintCpt = R.hooksComponentWithModule thisModule "pagePaintCpt" cpt where pagePaintCpt = R.hooksComponentWithModule thisModule "pagePaintCpt" cpt
cpt { documents, layout, params } _ = do where
localCategories <- R.useState' (mempty :: LocalCategories) cpt { documents, layout, params } _ = do
pure $ pagePaintRaw { documents: A.fromFoldable filteredRows, layout, localCategories, params } localCategories <- R.useState' (mempty :: LocalCategories)
where pure $ pagePaintRaw { documents: A.fromFoldable filteredRows
orderWith = , layout
case convOrderBy (fst params).orderBy of , localCategories
Just DateAsc -> sortWith \(DocumentsView { date }) -> date , params } []
Just DateDesc -> sortWith \(DocumentsView { date }) -> Down date where
Just SourceAsc -> sortWith \(DocumentsView { source }) -> Str.toLower source orderWith =
Just SourceDesc -> sortWith \(DocumentsView { source }) -> Down $ Str.toLower source case convOrderBy (fst params).orderBy of
Just TitleAsc -> sortWith \(DocumentsView { title }) -> Str.toLower title Just DateAsc -> sortWith \(DocumentsView { date }) -> date
Just TitleDesc -> sortWith \(DocumentsView { title }) -> Down $ Str.toLower title Just DateDesc -> sortWith \(DocumentsView { date }) -> Down date
_ -> identity -- the server ordering is enough here Just SourceAsc -> sortWith \(DocumentsView { source }) -> Str.toLower source
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents Just SourceDesc -> sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc -> sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc -> sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
_ -> identity -- the server ordering is enough here
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents
type PagePaintRawProps = ( type PagePaintRawProps = (
...@@ -328,13 +335,19 @@ type PagePaintRawProps = ( ...@@ -328,13 +335,19 @@ type PagePaintRawProps = (
, params :: R.State T.Params , params :: R.State T.Params
) )
pagePaintRaw :: Record PagePaintRawProps -> R.Element pagePaintRaw :: R2.Component PagePaintRawProps
pagePaintRaw props = R.createElement pagePaintRawCpt props [] pagePaintRaw = R.createElement pagePaintRawCpt
pagePaintRawCpt :: R.Component PagePaintRawProps pagePaintRawCpt :: R.Component PagePaintRawProps
pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt where pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt where
cpt { documents cpt { documents
, layout: { corpusId, frontends, listId, nodeId, session, sidePanelTriggers, totalRecords } , layout: { corpusId
, frontends
, listId
, nodeId
, session
, sidePanelTriggers
, totalRecords }
, localCategories , localCategories
, params } _ = do , params } _ = do
pure $ T.table pure $ T.table
...@@ -356,13 +369,14 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh ...@@ -356,13 +369,14 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
| otherwise = Routes.Document sid listId | otherwise = Routes.Document sid listId
colNames = T.ColumnName <$> [ "Tag", "Date", "Title", "Source"] colNames = T.ColumnName <$> [ "Tag", "Date", "Title", "Source"]
wrapColElts = const identity wrapColElts = const identity
getCategory (localCategories /\ _) {_id, category} = fromMaybe category (localCategories ^. at _id) getCategory (lc /\ _) {_id, category} = fromMaybe category (lc ^. at _id)
rows localCategories = row <$> A.toUnfoldable documents rows lc@(_ /\ setLocalCategories) = row <$> A.toUnfoldable documents
where where
row dv@(DocumentsView r) = row dv@(DocumentsView r) =
{ row: { row:
T.makeRow [ -- H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ] T.makeRow [ -- H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ]
caroussel { category: cat, nodeId, row: dv, session, setLocalCategories } [] caroussel { category: cat, nodeId, row: dv, session, setLocalCategories } []
, docChooser { listId, mCorpusId: corpusId, nodeId: r._id, sidePanelTriggers } []
--, H.input { type: "checkbox", defaultValue: checked, on: {click: click Trash} } --, H.input { type: "checkbox", defaultValue: checked, on: {click: click Trash} }
-- TODO show date: Year-Month-Day only -- TODO show date: Year-Month-Day only
, H.div { style } [ R2.showText r.date ] , H.div { style } [ R2.showText r.date ]
...@@ -372,34 +386,42 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh ...@@ -372,34 +386,42 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
] ]
, delete: true } , delete: true }
where where
cat = getCategory localCategories r cat = getCategory lc r
(_ /\ setLocalCategories) = localCategories
checked = Trash == cat checked = Trash == cat
style = trashStyle cat style = trashStyle cat
className = gi cat className = gi cat
--------------------------------------------------------- type DocChooser = (
sampleData' :: DocumentsView listId :: ListId
sampleData' = DocumentsView { _id : 1 , mCorpusId :: Maybe NodeID
, url : "" , nodeId :: NodeID
, date : 2010 , sidePanelTriggers :: Record SidePanelTriggers
, title : "title" )
, source : "source"
, category : UnRead docChooser :: R2.Component DocChooser
, ngramCount : 1} docChooser = R.createElement docChooserCpt
sampleData :: Array DocumentsView docChooserCpt :: R.Component DocChooser
--sampleData = replicate 10 sampleData' docChooserCpt = R.hooksComponentWithModule thisModule "docChooser" cpt
sampleData = map (\(Tuple t s) -> DocumentsView { _id : 1 where
, url : "" cpt { mCorpusId: Nothing } _ = do
, date : 2017 pure $ H.div {} []
, title: t
, source: s cpt { listId
, category : UnRead , mCorpusId: Just corpusId
, ngramCount : 10}) sampleDocuments , nodeId
, sidePanelTriggers: { triggerAnnotatedDocIdChange } } _ = do
sampleDocuments :: Array (Tuple String String) pure $ H.div { className: "doc-chooser" } [
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"] H.span { className: "fa fa-eye"
, on: { click: onClick } } []
]
where
onClick _ = do
-- log2 "[docChooser] onClick, listId" listId
-- log2 "[docChooser] onClick, corpusId" corpusId
-- log2 "[docChooser] onClick, nodeId" nodeId
R2.callTrigger triggerAnnotatedDocIdChange { corpusId, listId, nodeId }
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ query :: Array String { query :: Array String
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.DocsTable.Types where ...@@ -3,6 +3,7 @@ module Gargantext.Components.DocsTable.Types where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>)) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Tuple (Tuple(..))
import Gargantext.Prelude import Gargantext.Prelude
...@@ -92,3 +93,26 @@ instance decodeResponse :: DecodeJson Response where ...@@ -92,3 +93,26 @@ instance decodeResponse :: DecodeJson Response where
type LocalCategories = Map Int Category type LocalCategories = Map Int Category
type Query = String type Query = String
---------------------------------------------------------
sampleData' :: DocumentsView
sampleData' = DocumentsView { _id : 1
, url : ""
, date : 2010
, title : "title"
, source : "source"
, category : UnRead
, ngramCount : 1}
sampleData :: Array DocumentsView
--sampleData = replicate 10 sampleData'
sampleData = map (\(Tuple t s) -> DocumentsView { _id : 1
, url : ""
, date : 2017
, title: t
, source: s
, category : UnRead
, ngramCount : 10}) sampleDocuments
sampleDocuments :: Array (Tuple String String)
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"]
...@@ -35,8 +35,8 @@ type Props = ( ...@@ -35,8 +35,8 @@ type Props = (
, treeReloadRef :: R.Ref (Maybe ReloadS) , treeReloadRef :: R.Ref (Maybe ReloadS)
) )
forest :: Record Props -> R.Element forest :: R2.Component Props
forest props = R.createElement forestCpt props [] forest = R.createElement forestCpt
forestCpt :: R.Component Props forestCpt :: R.Component Props
forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where forestCpt = R.hooksComponentWithModule thisModule "forest" cpt where
...@@ -133,7 +133,7 @@ forestLayoutCpt :: R.Component ForestLayoutProps ...@@ -133,7 +133,7 @@ forestLayoutCpt :: R.Component ForestLayoutProps
forestLayoutCpt = R.hooksComponentWithModule thisModule "forestLayout" cpt forestLayoutCpt = R.hooksComponentWithModule thisModule "forestLayout" cpt
where where
cpt props@{ handed } children = do cpt props@{ handed } children = do
pure $ R.fragment [ topBar { handed } [], forestLayoutRaw props children ] pure $ R.fragment [ topBar { handed } [], forestLayoutMain props children ]
-- a component, for which first child element is placed inside the top bar -- a component, for which first child element is placed inside the top bar
-- while the remaining ones are put into the main view -- while the remaining ones are put into the main view
...@@ -146,46 +146,27 @@ forestLayoutWithTopBarCpt = R.hooksComponentWithModule thisModule "forestLayoutW ...@@ -146,46 +146,27 @@ forestLayoutWithTopBarCpt = R.hooksComponentWithModule thisModule "forestLayoutW
cpt props@{ handed } children = do cpt props@{ handed } children = do
let { head: topBarChild, tail: mainChildren } = let { head: topBarChild, tail: mainChildren } =
fromMaybe { head: H.div {} [], tail: [] } $ A.uncons children fromMaybe { head: H.div {} [], tail: [] } $ A.uncons children
pure $ R.fragment [ topBar { handed } [ topBarChild ], forestLayoutMain props mainChildren ] pure $ R.fragment [
topBar { handed } [ topBarChild ]
forestLayoutRaw :: R2.Component ForestLayoutProps , forestLayoutMain props mainChildren
forestLayoutRaw props = R.createElement forestLayoutRawCpt props ]
forestLayoutRawCpt :: R.Component ForestLayoutProps
forestLayoutRawCpt = R.hooksComponentWithModule thisModule "forestLayoutRaw" cpt
where
cpt { appReload
, asyncTasksRef
, backend
, frontends
, handed
, route
, sessions
, showLogin
, treeReloadRef } children = do
let ordering =
case fst handed of
LeftHanded -> A.reverse
RightHanded -> identity
pure $ R2.row $ ordering [
H.div { className: "col-md-2", style: { paddingTop: "60px" } } ([
forest { appReload
, asyncTasksRef
, backend
, frontends
, handed: fst handed
, route
, sessions
, showLogin
, treeReloadRef } ] <> children)
]
forestLayoutMain :: R2.Component ForestLayoutProps forestLayoutMain :: R2.Component ForestLayoutProps
forestLayoutMain props = R.createElement forestLayoutMainCpt props forestLayoutMain props = R.createElement forestLayoutMainCpt props
forestLayoutMainCpt :: R.Component ForestLayoutProps forestLayoutMainCpt :: R.Component ForestLayoutProps
forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" cpt forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" cpt
where
cpt props children = do
pure $ forestLayoutRaw props [
mainPage {} children
]
forestLayoutRaw :: R2.Component ForestLayoutProps
forestLayoutRaw props = R.createElement forestLayoutRawCpt props
forestLayoutRawCpt :: R.Component ForestLayoutProps
forestLayoutRawCpt = R.hooksComponentWithModule thisModule "forestLayoutRaw" cpt
where where
cpt { appReload cpt { appReload
, asyncTasksRef , asyncTasksRef
...@@ -201,7 +182,7 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c ...@@ -201,7 +182,7 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c
LeftHanded -> A.reverse LeftHanded -> A.reverse
RightHanded -> identity RightHanded -> identity
pure $ R2.row $ ordering [ pure $ R2.row $ ordering ([
H.div { className: "col-md-2", style: { paddingTop: "60px" } } [ H.div { className: "col-md-2", style: { paddingTop: "60px" } } [
forest { appReload forest { appReload
, asyncTasksRef , asyncTasksRef
...@@ -211,9 +192,9 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c ...@@ -211,9 +192,9 @@ forestLayoutMainCpt = R.hooksComponentWithModule thisModule "forestLayoutMain" c
, route , route
, sessions , sessions
, showLogin , showLogin
, treeReloadRef } ] , treeReloadRef } []
, mainPage {} children ]
] ] <> children)
mainPage :: R2.Component () mainPage :: R2.Component ()
mainPage = R.createElement mainPageCpt mainPage = R.createElement mainPageCpt
......
...@@ -225,7 +225,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt ...@@ -225,7 +225,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
, route , route
, sessions , sessions
, showLogin , showLogin
, treeReloadRef } , treeReloadRef } []
] ]
mSidebar :: Maybe GET.MetaData mSidebar :: Maybe GET.MetaData
......
...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record as Record
import Gargantext.Prelude (bind, pure, show, unit, ($), (<>), (<<<)) import Gargantext.Prelude (bind, pure, show, unit, ($), (<>), (<<<))
...@@ -22,7 +23,7 @@ import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField ...@@ -22,7 +23,7 @@ import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, sessionId) import Gargantext.Sessions (Session, get, sessionId)
import Gargantext.Types (CTabNgramType(..), NodeType(..), TabSubType(..), TabType(..), ScoreType(..)) import Gargantext.Types (CTabNgramType(..), ListId, NodeID, NodeType(..), TabSubType(..), TabType(..), ScoreType(..))
import Gargantext.Utils as U import Gargantext.Utils as U
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -35,8 +36,8 @@ publicationDate (Document doc@{publication_year: Just py, publication_month: Not ...@@ -35,8 +36,8 @@ publicationDate (Document doc@{publication_year: Just py, publication_month: Not
publicationDate (Document doc@{publication_year: Just py, publication_month: Just pm, publication_day: Nothing}) = (U.zeroPad 2 py) <> "-" <> (U.zeroPad 2 pm) publicationDate (Document doc@{publication_year: Just py, publication_month: Just pm, publication_day: Nothing}) = (U.zeroPad 2 py) <> "-" <> (U.zeroPad 2 pm)
publicationDate (Document doc@{publication_year: Just py, publication_month: Just pm, publication_day: Just pd}) = (U.zeroPad 2 py) <> "-" <> (U.zeroPad 2 pm) <> "-" <> (U.zeroPad 2 pd) publicationDate (Document doc@{publication_year: Just py, publication_month: Just pm, publication_day: Just pd}) = (U.zeroPad 2 py) <> "-" <> (U.zeroPad 2 pm) <> "-" <> (U.zeroPad 2 pd)
docViewWrapper :: Record Props -> R.Element docViewWrapper :: R2.Component Props
docViewWrapper props = R.createElement docViewWrapperCpt props [] docViewWrapper = R.createElement docViewWrapperCpt
docViewWrapperCpt :: R.Component Props docViewWrapperCpt :: R.Component Props
docViewWrapperCpt = R.hooksComponentWithModule thisModule "docViewWrapper" cpt docViewWrapperCpt = R.hooksComponentWithModule thisModule "docViewWrapper" cpt
...@@ -44,15 +45,15 @@ docViewWrapperCpt = R.hooksComponentWithModule thisModule "docViewWrapper" cpt ...@@ -44,15 +45,15 @@ docViewWrapperCpt = R.hooksComponentWithModule thisModule "docViewWrapper" cpt
cpt { loaded, path } _ = do cpt { loaded, path } _ = do
state <- R.useState' $ initialState { loaded } state <- R.useState' $ initialState { loaded }
pure $ docView { loaded, path, state } pure $ docView { loaded, path, state } []
type DocViewProps = ( type DocViewProps = (
state :: R.State State state :: R.State State
| Props | Props
) )
docView :: Record DocViewProps -> R.Element docView :: R2.Component DocViewProps
docView props = R.createElement docViewCpt props [] docView = R.createElement docViewCpt
docViewCpt :: R.Component DocViewProps docViewCpt :: R.Component DocViewProps
docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
...@@ -126,44 +127,40 @@ docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt ...@@ -126,44 +127,40 @@ docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
NodePoly {hyperdata: Document doc} = document NodePoly {hyperdata: Document doc} = document
type LayoutProps = ( type LayoutProps = (
corpusId :: Maybe Int listId :: ListId
, listId :: Int , mCorpusId :: Maybe NodeID
, nodeId :: Int , nodeId :: NodeID
, session :: Session , session :: Session
) )
documentLayout :: Record LayoutProps -> R.Element documentLayout :: R2.Component LayoutProps
documentLayout props = R.createElement documentLayoutCpt props [] documentLayout = R.createElement documentLayoutCpt
documentLayoutCpt :: R.Component LayoutProps documentLayoutCpt :: R.Component LayoutProps
documentLayoutCpt = R.hooksComponentWithModule thisModule "documentLayout" cpt documentLayoutCpt = R.hooksComponentWithModule thisModule "documentLayout" cpt
where where
cpt { corpusId, listId, nodeId, session } _ = do cpt props@{ nodeId, session } _ = do
let sid = sessionId session let sid = sessionId session
pure $ documentLayoutWithKey { corpusId pure $ documentLayoutWithKey (Record.merge props { key: show sid <> "-" <> show nodeId }) []
, key: show sid <> "-" <> show nodeId
, listId
, nodeId
, session }
type KeyLayoutProps = ( type KeyLayoutProps = (
key :: String key :: String
| LayoutProps | LayoutProps
) )
documentLayoutWithKey :: Record KeyLayoutProps -> R.Element documentLayoutWithKey :: R2.Component KeyLayoutProps
documentLayoutWithKey props = R.createElement documentLayoutWithKeyCpt props [] documentLayoutWithKey = R.createElement documentLayoutWithKeyCpt
documentLayoutWithKeyCpt :: R.Component KeyLayoutProps documentLayoutWithKeyCpt :: R.Component KeyLayoutProps
documentLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "documentLayoutWithKey" cpt documentLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "documentLayoutWithKey" cpt
where where
cpt { corpusId, listId, nodeId, session } _ = do cpt { listId, mCorpusId, nodeId, session } _ = do
useLoader path loadData $ \loaded -> useLoader path loadData $ \loaded ->
docViewWrapper {path, loaded} docViewWrapper { loaded, path } []
where where
tabType = TabDocument (TabNgramType CTabTerms) tabType = TabDocument (TabNgramType CTabTerms)
path = { corpusId, listIds: [listId], nodeId, session, tabType } path = { listIds: [listId], mCorpusId, nodeId, session, tabType }
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -174,14 +171,14 @@ loadData :: DocPath -> Aff LoadedData ...@@ -174,14 +171,14 @@ loadData :: DocPath -> Aff LoadedData
loadData {session, nodeId, listIds, tabType} = do loadData {session, nodeId, listIds, tabType} = do
document <- loadDocument session nodeId document <- loadDocument session nodeId
ngramsTable <- loadNgramsTable ngramsTable <- loadNgramsTable
{ session { listIds
, nodeId , nodeId
, listIds
, params: { offset : 0, limit : 100, orderBy: Nothing, searchType: SearchDoc} , params: { offset : 0, limit : 100, orderBy: Nothing, searchType: SearchDoc}
, tabType , scoreType: Occurrences
, searchQuery: "" , searchQuery: ""
, session
, tabType
, termListFilter: Nothing , termListFilter: Nothing
, termSizeFilter: Nothing , termSizeFilter: Nothing
, scoreType: Occurrences
} }
pure {document, ngramsTable} pure { document, ngramsTable }
...@@ -10,14 +10,14 @@ import Gargantext.Prelude ...@@ -10,14 +10,14 @@ import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.NgramsTable.Core (CoreState, Versioned(..) , VersionedNgramsTable) import Gargantext.Components.NgramsTable.Core (CoreState, Versioned(..) , VersionedNgramsTable)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (TabType) import Gargantext.Types (ListId, NodeID, TabType)
type DocPath = type DocPath =
{ corpusId :: Maybe Int { listIds :: Array ListId
, listIds :: Array Int , mCorpusId :: Maybe NodeID
, nodeId :: Int , nodeId :: NodeID
, session :: Session , session :: Session
, tabType :: TabType , tabType :: TabType
} }
type NodeDocument = NodePoly Document type NodeDocument = NodePoly Document
......
...@@ -6,6 +6,7 @@ import Data.Generic.Rep.Show (genericShow) ...@@ -6,6 +6,7 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log, log2)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Reactix as R import Reactix as R
...@@ -20,6 +21,7 @@ import Gargantext.Components.NgramsTable.Loader (clearCache) ...@@ -20,6 +21,7 @@ import Gargantext.Components.NgramsTable.Loader (clearCache)
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild) import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo) import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Document as D
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..), getCorpusInfo, CorpusInfo(..)) import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..), getCorpusInfo, CorpusInfo(..))
import Gargantext.Components.Nodes.Lists.Types as NT import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Texts.SidePanelToggleButton (sidePanelToggleButton) import Gargantext.Components.Nodes.Texts.SidePanelToggleButton (sidePanelToggleButton)
...@@ -28,7 +30,7 @@ import Gargantext.Components.Tab as Tab ...@@ -28,7 +30,7 @@ import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table import Gargantext.Components.Table as Table
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session, Sessions, sessionId, getCacheState, setCacheState) import Gargantext.Sessions (Session, Sessions, sessionId, getCacheState, setCacheState)
import Gargantext.Types (CTabNgramType(..), Handed(..), NodeID, ReloadS, TabSubType(..), TabType(..)) import Gargantext.Types (CTabNgramType(..), Handed(..), ListId, NodeID, ReloadS, TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String thisModule :: String
...@@ -47,38 +49,25 @@ textsWithForestCpt :: R.Component TextsWithForest ...@@ -47,38 +49,25 @@ textsWithForestCpt :: R.Component TextsWithForest
textsWithForestCpt = R.hooksComponentWithModule thisModule "textsWithForest" cpt textsWithForestCpt = R.hooksComponentWithModule thisModule "textsWithForest" cpt
where where
cpt { forestProps cpt { forestProps
, textsProps } _ = do , textsProps: textProps@{ session } } _ = do
controls <- initialControls controls <- initialControls
pure $ Forest.forestLayoutWithTopBar forestProps [ pure $ Forest.forestLayoutWithTopBar forestProps [
topBar { controls } [] topBar { controls } []
, H.div {className: "col-md-10"} [ , H.div { className: "col-md-10" } [
H.div {id: "page-wrapper"} [ H.div {id: "page-wrapper"} [
H.div {className: "container-fluid"} [ H.div {className: "container-fluid"} [
textsLayout (Record.merge textsProps { controls }) [] textsLayout (Record.merge textProps { controls }) []
] ]
] ]
] ]
, sidePanel { controls } [] , H.div { className: "col-md-2" } [
sidePanel { controls, session } []
]
] ]
-------------------------------------------------------- --------------------------------------------------------
type TextsLayoutControls = (
showSidePanel :: R.State SidePanelState
, triggers :: Record SidePanelTriggers
)
initialControls :: R.Hooks (Record TextsLayoutControls)
initialControls = do
showSidePanel <- R.useState' InitialClosed
triggers <- emptySidePanelTriggers
pure $ {
showSidePanel
, triggers
}
type TopBarProps = ( type TopBarProps = (
controls :: Record TextsLayoutControls controls :: Record TextsLayoutControls
) )
...@@ -214,29 +203,34 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -214,29 +203,34 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
} }
where where
initialPath = { corpusId, listId: 0, limit: Nothing, tabType: TabCorpus TabDocs } initialPath = { corpusId
, listId: corpusData.defaultListId
, limit: Nothing
, tabType: TabCorpus TabDocs }
docView' path tabType = docView { cacheState docView' path tabType = docView { cacheState
, corpusData , corpusData
, corpusId , corpusId
, frontends , frontends
, listId: path.listId
-- , path -- , path
, session , session
, tabType , tabType
, sidePanelTriggers } , sidePanelTriggers } []
type DocViewProps a = ( type DocViewProps a = (
cacheState :: R.State NT.CacheState cacheState :: R.State NT.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: Int , corpusId :: NodeID
, frontends :: Frontends , frontends :: Frontends
, listId :: ListId
-- , path :: Record DT.Path -- , path :: Record DT.Path
, session :: Session , session :: Session
, tabType :: TabSubType a , tabType :: TabSubType a
, sidePanelTriggers :: Record SidePanelTriggers , sidePanelTriggers :: Record SidePanelTriggers
) )
docView :: forall a. Record (DocViewProps a) -> R.Element docView :: forall a. R2.Component (DocViewProps a)
docView props = R.createElement docViewCpt props [] docView = R.createElement docViewCpt
docViewCpt :: forall a. R.Component (DocViewProps a) docViewCpt :: forall a. R.Component (DocViewProps a)
docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
...@@ -246,9 +240,9 @@ docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt ...@@ -246,9 +240,9 @@ docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
-- docViewLayoutRec :: forall a. DocViewProps a -> Record DT.LayoutProps -- docViewLayoutRec :: forall a. DocViewProps a -> Record DT.LayoutProps
docViewLayoutRec { cacheState docViewLayoutRec { cacheState
, corpusData: { defaultListId }
, corpusId , corpusId
, frontends , frontends
, listId
, session , session
, tabType: TabDocs , tabType: TabDocs
, sidePanelTriggers } = , sidePanelTriggers } =
...@@ -256,7 +250,7 @@ docViewLayoutRec { cacheState ...@@ -256,7 +250,7 @@ docViewLayoutRec { cacheState
, chart : H.div {} [] , chart : H.div {} []
, corpusId: Just corpusId , corpusId: Just corpusId
, frontends , frontends
, listId: defaultListId , listId
, nodeId: corpusId , nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
, session , session
...@@ -266,9 +260,9 @@ docViewLayoutRec { cacheState ...@@ -266,9 +260,9 @@ docViewLayoutRec { cacheState
, totalRecords: 4737 , totalRecords: 4737
} }
docViewLayoutRec { cacheState docViewLayoutRec { cacheState
, corpusData: { defaultListId }
, corpusId , corpusId
, frontends , frontends
, listId
, session , session
, tabType: TabMoreLikeFav , tabType: TabMoreLikeFav
, sidePanelTriggers } = , sidePanelTriggers } =
...@@ -276,7 +270,7 @@ docViewLayoutRec { cacheState ...@@ -276,7 +270,7 @@ docViewLayoutRec { cacheState
, chart : H.div {} [] , chart : H.div {} []
, corpusId: Just corpusId , corpusId: Just corpusId
, frontends , frontends
, listId: defaultListId , listId
, nodeId: corpusId , nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
, session , session
...@@ -286,9 +280,9 @@ docViewLayoutRec { cacheState ...@@ -286,9 +280,9 @@ docViewLayoutRec { cacheState
, totalRecords: 4737 , totalRecords: 4737
} }
docViewLayoutRec { cacheState docViewLayoutRec { cacheState
, corpusData: { defaultListId }
, corpusId , corpusId
, frontends , frontends
, listId
, session , session
, tabType: TabMoreLikeTrash , tabType: TabMoreLikeTrash
, sidePanelTriggers } = , sidePanelTriggers } =
...@@ -296,7 +290,7 @@ docViewLayoutRec { cacheState ...@@ -296,7 +290,7 @@ docViewLayoutRec { cacheState
, chart : H.div {} [] , chart : H.div {} []
, corpusId: Just corpusId , corpusId: Just corpusId
, frontends , frontends
, listId: defaultListId , listId
, nodeId: corpusId , nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
, session , session
...@@ -306,9 +300,9 @@ docViewLayoutRec { cacheState ...@@ -306,9 +300,9 @@ docViewLayoutRec { cacheState
, totalRecords: 4737 , totalRecords: 4737
} }
docViewLayoutRec { cacheState docViewLayoutRec { cacheState
, corpusData: { defaultListId }
, corpusId , corpusId
, frontends , frontends
, listId
, session , session
, tabType: TabTrash , tabType: TabTrash
, sidePanelTriggers } = , sidePanelTriggers } =
...@@ -316,7 +310,7 @@ docViewLayoutRec { cacheState ...@@ -316,7 +310,7 @@ docViewLayoutRec { cacheState
, chart : H.div {} [] , chart : H.div {} []
, corpusId: Nothing , corpusId: Nothing
, frontends , frontends
, listId: defaultListId , listId
, nodeId: corpusId , nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
, session , session
...@@ -327,9 +321,9 @@ docViewLayoutRec { cacheState ...@@ -327,9 +321,9 @@ docViewLayoutRec { cacheState
} }
-- DUMMY -- DUMMY
docViewLayoutRec { cacheState docViewLayoutRec { cacheState
, corpusData: { defaultListId }
, corpusId , corpusId
, frontends , frontends
, listId
, session , session
, tabType , tabType
, sidePanelTriggers } = , sidePanelTriggers } =
...@@ -337,7 +331,7 @@ docViewLayoutRec { cacheState ...@@ -337,7 +331,7 @@ docViewLayoutRec { cacheState
, chart : H.div {} [] , chart : H.div {} []
, corpusId: Nothing , corpusId: Nothing
, frontends , frontends
, listId: defaultListId , listId
, nodeId: corpusId , nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
, session , session
...@@ -351,7 +345,8 @@ docViewLayoutRec { cacheState ...@@ -351,7 +345,8 @@ docViewLayoutRec { cacheState
-------------------------------------------------------- --------------------------------------------------------
type SidePanelProps = ( type SidePanelProps = (
controls :: Record TextsLayoutControls controls :: Record TextsLayoutControls
, session :: Session
) )
sidePanel :: R2.Component SidePanelProps sidePanel :: R2.Component SidePanelProps
...@@ -364,7 +359,55 @@ sidePanelCpt = R.hooksComponentWithModule thisModule "sidePanel" cpt ...@@ -364,7 +359,55 @@ sidePanelCpt = R.hooksComponentWithModule thisModule "sidePanel" cpt
pure $ H.div {} [] pure $ H.div {} []
cpt { controls: { showSidePanel: (Closed /\ _) } } _ = do cpt { controls: { showSidePanel: (Closed /\ _) } } _ = do
pure $ H.div {} [] pure $ H.div {} []
cpt { controls: { showSidePanel: (Opened /\ _) } } _ = do cpt { controls: { showSidePanel: (Opened /\ _)
pure $ H.div { className: "side-bar" } [ , triggers: { triggerAnnotatedDocIdChange } }
H.h4 {} [ H.text "Side Bar" ] , session } _ = do
] (mCorpusId /\ setMCorpusId) <- R.useState' Nothing
(mListId /\ setMListId) <- R.useState' Nothing
(mNodeId /\ setMNodeId) <- R.useState' Nothing
R.useEffect2 mListId mNodeId $ do
let trigger :: Record TriggerAnnotatedDocIdChangeParams -> Effect Unit
trigger { corpusId, listId, nodeId } = do
-- log2 "[sidePanel trigger] trigger corpusId change" corpusId
-- log2 "[sidePanel trigger] trigger listId change" listId
-- log2 "[sidePanel trigger] trigger nodeId change" nodeId
setMCorpusId $ const $ Just corpusId
setMListId $ const $ Just listId
setMNodeId $ const $ Just nodeId
-- log2 "[sidePanel] trigger" trigger
R2.setTrigger triggerAnnotatedDocIdChange trigger
pure $ do
-- log "[sidePanel] clearing triggerAnnotatedDocIdChange"
R2.clearTrigger triggerAnnotatedDocIdChange
pure $ H.div { className: "side-panel" } [
sidePanelDocView { mCorpusId, mListId, mNodeId, session } []
]
type SidePanelDocView = (
mCorpusId :: Maybe NodeID
, mListId :: Maybe ListId
, mNodeId :: Maybe NodeID
, session :: Session
)
sidePanelDocView :: R2.Component SidePanelDocView
sidePanelDocView = R.createElement sidePanelDocViewCpt
sidePanelDocViewCpt :: R.Component SidePanelDocView
sidePanelDocViewCpt = R.hooksComponentWithModule thisModule "sidePanel" cpt
where
cpt { mListId: Nothing } _ = do
pure $ H.div {} []
cpt { mNodeId: Nothing } _ = do
pure $ H.div {} []
cpt { mCorpusId
, mListId: Just listId
, mNodeId: Just nodeId
, session } _ = do
-- pure $ H.h4 {} [ H.text txt ]
pure $ D.documentLayout { listId, mCorpusId, nodeId, session } []
where
txt = "mCorpusId: " <> show mCorpusId <> ", listId: " <> show listId <> ", nodeId: " <> show nodeId
...@@ -6,7 +6,8 @@ import Reactix as R ...@@ -6,7 +6,8 @@ import Reactix as R
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Types (NodeID) import Gargantext.Types (ListId, NodeID)
import Gargantext.Utils.Reactix as R2
data SidePanelState = InitialClosed | Opened | Closed data SidePanelState = InitialClosed | Opened | Closed
derive instance eqSidePanelState :: Eq SidePanelState derive instance eqSidePanelState :: Eq SidePanelState
...@@ -16,15 +17,39 @@ toggleSidePanelState InitialClosed = Opened ...@@ -16,15 +17,39 @@ toggleSidePanelState InitialClosed = Opened
toggleSidePanelState Closed = Opened toggleSidePanelState Closed = Opened
toggleSidePanelState Opened = Closed toggleSidePanelState Opened = Closed
type TriggerAnnotatedDocIdChangeParams = (
corpusId :: NodeID
, listId :: ListId
, nodeId :: NodeID
)
type SidePanelTriggers = ( type SidePanelTriggers = (
triggerAnnotatedDocIdChange :: R.Ref (Maybe (NodeID -> Effect Unit)) triggerAnnotatedDocIdChange :: R2.Trigger (Record TriggerAnnotatedDocIdChangeParams)
, triggerSidePanel :: R2.Trigger Unit
) )
emptySidePanelTriggers :: R.Hooks (Record SidePanelTriggers) emptySidePanelTriggers :: R.Hooks (Record SidePanelTriggers)
emptySidePanelTriggers = do emptySidePanelTriggers = do
triggerAnnotatedDocIdChange <- R.useRef Nothing triggerAnnotatedDocIdChange <- R.useRef Nothing
triggerSidePanel <- R.useRef Nothing
pure $ { pure $ {
triggerAnnotatedDocIdChange triggerAnnotatedDocIdChange
, triggerSidePanel
} }
type TextsLayoutControls = (
showSidePanel :: R.State SidePanelState
, triggers :: Record SidePanelTriggers
)
initialControls :: R.Hooks (Record TextsLayoutControls)
initialControls = do
showSidePanel <- R.useState' InitialClosed
triggers <- emptySidePanelTriggers
pure $ {
showSidePanel
, triggers
}
...@@ -17,6 +17,7 @@ import Data.Maybe (Maybe(..), fromJust, fromMaybe, isJust) ...@@ -17,6 +17,7 @@ import Data.Maybe (Maybe(..), fromJust, fromMaybe, isJust)
import Data.Nullable (Nullable, null, toMaybe) import Data.Nullable (Nullable, null, toMaybe)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Effect.Console (logShow) import Effect.Console (logShow)
import Effect.Aff (Aff, launchAff, launchAff_, killFiber) import Effect.Aff (Aff, launchAff, launchAff_, killFiber)
...@@ -325,3 +326,22 @@ focus nEl = case toMaybe nEl of ...@@ -325,3 +326,22 @@ focus nEl = case toMaybe nEl of
setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element setIndeterminateCheckbox :: R.Element -> Boolean -> Effect R.Element
setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val setIndeterminateCheckbox el val = pure $ (el .= "indeterminate") val
-- A "trigger" is a ref to a function which is used to make changes without
-- modifying too much DOM.
-- This is to escape passing explicit state to nested child components.
type Trigger a = R.Ref (Maybe (a -> Effect Unit))
callTrigger :: forall a. Trigger a -> a -> Effect Unit
callTrigger tRef arg = case R.readRef tRef of
Nothing -> do
log2 "[callTrigger] trigger is empty" tRef
pure unit
Just t -> t arg
setTrigger :: forall a. Trigger a -> (a -> Effect Unit) -> Effect Unit
setTrigger tRef fun = R.setRef tRef $ Just fun
clearTrigger :: forall a. Trigger a -> Effect Unit
clearTrigger tRef = R.setRef tRef Nothing
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