1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
module Gargantext.Components.App where
import Data.Array (fromFoldable)
import Data.Maybe (Maybe(..), maybe')
import Data.Tuple (fst, snd)
import Reactix as R
import Gargantext.Prelude
import Gargantext.Components.Footer (footer)
import Gargantext.Components.Forest (forestLayout, forestLayoutWithTopBar)
import Gargantext.Components.GraphExplorer (explorerLayout)
import Gargantext.Components.Lang (LandingLang(..))
import Gargantext.Components.Login (login)
import Gargantext.Components.Nodes.Annuaire (annuaireLayout)
import Gargantext.Components.Nodes.Annuaire.User (userLayout)
import Gargantext.Components.Nodes.Annuaire.User.Contact (contactLayout)
import Gargantext.Components.Nodes.Corpus (corpusLayout)
import Gargantext.Components.Nodes.Corpus.Dashboard (dashboardLayout)
import Gargantext.Components.Nodes.Corpus.Document (documentMainLayout)
import Gargantext.Components.Nodes.File (fileLayout)
import Gargantext.Components.Nodes.Frame (frameLayout)
import Gargantext.Components.Nodes.Home (homeLayout)
import Gargantext.Components.Nodes.Lists as Lists
import Gargantext.Components.Nodes.Texts as Texts
import Gargantext.Components.SimpleLayout (simpleLayout)
import Gargantext.Config (defaultFrontends, defaultBackends, publicBackend)
import Gargantext.Hooks.Router (useHashRouter)
import Gargantext.Router (router)
import Gargantext.Routes (AppRoute(..))
import Gargantext.Sessions (useSessions)
import Gargantext.Sessions as Sessions
import Gargantext.Types as GT
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.App"
-- TODO (what does this mean?)
-- tree changes endConfig state => trigger endConfig change in outerLayout, layoutFooter etc
app :: {} -> R.Element
app props = R.createElement appCpt props []
appCpt :: R.Component ()
appCpt = R.hooksComponentWithModule thisModule "app" cpt where
frontends = defaultFrontends
cpt _ _ = do
sessions <- useSessions
route <- useHashRouter router Home
asyncTasksRef <- R.useRef Nothing
treeReloadRef <- GUR.newI
showLogin <- R.useState' false
backend <- R.useState' Nothing
appReload <- GUR.new
showCorpus <- R.useState' false
handed <- R.useState' GT.RightHanded
let backends = fromFoldable defaultBackends
let ff f session = R.fragment [ f session, footer { session } ]
let forested = forestLayout { appReload
, asyncTasksRef
, backend
, currentRoute: fst route
, frontends
, handed
, sessions: fst sessions
, showLogin: snd showLogin
, treeReloadRef
}
let forestedTB = forestLayoutWithTopBar { appReload
, asyncTasksRef
, backend
, currentRoute: fst route
, frontends
, handed
, sessions: fst sessions
, showLogin: snd showLogin
, treeReloadRef
}
let defaultView _ = forested [
homeLayout { backend
, lang: LL_EN
, publicBackend
, sessions
, visible: showLogin
}
]
let withSession sid f = maybe' defaultView (ff f) (Sessions.lookup sid (fst sessions))
let sessionUpdate s = snd sessions $ Sessions.Update s
pure $ case fst showLogin of
true -> forested [ login { backend, backends, sessions, visible: showLogin } ]
false ->
case fst route of
Annuaire sid nodeId -> withSession sid $ \session -> forested [
annuaireLayout { frontends, nodeId, session }
]
Corpus sid nodeId -> withSession sid $ \session -> forested [
corpusLayout { nodeId, session }
]
CorpusDocument sid corpusId listId nodeId -> withSession sid $ \session -> forested [
documentMainLayout { listId, mCorpusId: Just corpusId, nodeId, session } []
]
Dashboard sid nodeId -> withSession sid $ \session -> forested [
dashboardLayout { nodeId, session } []
]
Document sid listId nodeId ->
withSession sid $
\session -> forested [
documentMainLayout { listId, mCorpusId: Nothing, nodeId, session } []
]
Folder sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
FolderPrivate sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
FolderPublic sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
FolderShared sid nodeId -> withSession sid $ \session -> forested [ corpusLayout { nodeId, session } ]
Home -> forested [
homeLayout { backend, lang: LL_EN, publicBackend, sessions, visible: showLogin }
]
Lists sid nodeId -> withSession sid $
\session -> Lists.listsWithForest {
forestProps: {
appReload
, asyncTasksRef
, backend
, currentRoute: fst route
, frontends
, handed
, sessions: fst sessions
, showLogin: snd showLogin
, treeReloadRef
}
, listsProps: {
appReload
, asyncTasksRef
, nodeId
, session
, sessionUpdate
, treeReloadRef
}
} []
Login -> login { backend, backends, sessions, visible: showLogin }
PGraphExplorer sid graphId ->
withSession sid $
\session ->
simpleLayout { handed } [
explorerLayout { asyncTasksRef
, backend
, currentRoute: fst route
, frontends
, graphId
, handed: fst handed
, session
, sessions: (fst sessions)
, showLogin
}
]
RouteFile sid nodeId -> withSession sid $ \session -> forested [ fileLayout { nodeId, session } ]
RouteFrameCalc sid nodeId -> withSession sid $ \session -> forested [
frameLayout { nodeId, nodeType: GT.NodeFrameCalc, session }
]
RouteFrameCode sid nodeId -> withSession sid $ \session -> forested [
frameLayout { nodeId, nodeType: GT.NodeFrameNotebook, session }
]
RouteFrameWrite sid nodeId -> withSession sid $ \session -> forested [
frameLayout { nodeId, nodeType: GT.NodeFrameWrite, session }
]
Team sid nodeId -> withSession sid $ \session -> forested [
corpusLayout { nodeId, session }
]
Texts sid nodeId -> withSession sid $
\session -> Texts.textsWithForest {
forestProps: {
appReload
, asyncTasksRef
, backend
, currentRoute: fst route
, frontends
, handed
, sessions: fst sessions
, showLogin: snd showLogin
, treeReloadRef
}
, textsProps: {
frontends
, nodeId
, session
, sessionUpdate
}
} []
----------------------------------------------------------------------------------------
-- | TODO refact UserPage and ContactPage
UserPage sid nodeId -> withSession sid $ \session -> forested [
userLayout {
appReload
, asyncTasksRef
, frontends
, nodeId
, session
, treeReloadRef
}
]
ContactPage sid aId nodeId -> withSession sid $ \session -> forested [
contactLayout {
annuaireId: aId
, appReload
, asyncTasksRef
, frontends
, nodeId
, session
, treeReloadRef
}
]