Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
dedae7f3
Unverified
Commit
dedae7f3
authored
Oct 11, 2018
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TABLE] step 3
parent
a709265c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
Table.purs
src/Gargantext/Components/Table.purs
+31
-7
No files found.
src/Gargantext/Components/Table.purs
View file @
dedae7f3
module Gargantext.Components.Table where
import Control.Monad.Cont.Trans (lift)
import Data.Array (filter)
import Data.Maybe (Maybe(..), maybe)
import Data.Either (Either)
import Data.Either (Either
(..)
)
import Effect (Effect)
import Effect.Aff (Aff)
import React as React
import React (ReactElement, ReactClass, Children, createElement)
import React.DOM (a, b, b', div, option, select, span, table, tbody, td, text, th, thead, tr)
import React.DOM (a, b, b', div,
div',
option, select, span, table, tbody, td, text, th, thead, tr)
import React.DOM.Props (className, href, onChange, onClick, scope, selected, value)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec, createClass)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec, createClass
', createReactSpec
)
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude
...
...
@@ -61,10 +63,12 @@ tableSpec :: Spec State Props Action
tableSpec = simpleSpec performAction render
where
performAction :: PerformAction State Props Action
performAction (ChangePageSize ps) {totalRecords} _ =
void $ modifyState $ changePageSize totalRecords ps
performAction (ChangePage p) _ _ =
performAction (ChangePageSize ps) props state = do
void $ modifyState $ changePageSize props.totalRecords ps
loadAndSetRows props state
performAction (ChangePage p) props state = do
void $ modifyState $ _ { currentPage = p }
loadAndSetRows props state
render :: Render State Props Action
render dispatch {title, colNames, totalRecords}
...
...
@@ -86,8 +90,28 @@ tableSpec = simpleSpec performAction render
]
]
loadAndSetRows {loadRows} {pageSize, currentPage} = do
let limit = pageSizes2Int pageSize
offset = limit * (currentPage - 1)
x <- lift $ loadRows {offset, limit}
case x of
Left err -> logs err
Right rows ->
void $ modifyState (_ { rows = Just rows })
tableClass :: ReactClass {children :: Children | Props'}
tableClass = createClass "Table" tableSpec initialState
tableClass =
React.component "Table"
(\this -> do
{state, render} <- spec this
pure { state, render
, componentDidMount: do
props <- React.getProps this
state' <- React.getState this
dispatcher' this $ loadAndSetRows props state'
})
where
{ spec, dispatcher' } = createReactSpec tableSpec initialState
tableElt :: Props -> ReactElement
tableElt props = createElement tableClass props []
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment