Commit 74638ba3 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[DocsTable] fixes to localCategories state

parent 9b659dbf
...@@ -92,7 +92,6 @@ type PageLoaderProps = ...@@ -92,7 +92,6 @@ type PageLoaderProps =
, query :: Query , query :: Query
} }
type DocumentIdsDeleted = Set Int
type LocalCategories = Map Int Category type LocalCategories = Map Int Category
type Query = String type Query = String
...@@ -165,16 +164,14 @@ docViewSpec p = R.createElement el p [] ...@@ -165,16 +164,14 @@ docViewSpec p = R.createElement el p []
where where
el = R.hooksComponent "DocView" cpt el = R.hooksComponent "DocView" cpt
cpt p _children = do cpt p _children = do
documentIdsDeleted <- R.useState' (mempty :: DocumentIdsDeleted)
localCategories <- R.useState' (mempty :: LocalCategories)
query <- R.useState' ("" :: Query) query <- R.useState' ("" :: Query)
tableParams <- R.useState' T.initialParams tableParams <- R.useState' T.initialParams
pure $ layoutDocview documentIdsDeleted localCategories query tableParams p pure $ layoutDocview query tableParams p
-- | Main layout of the Documents Tab of a Corpus -- | Main layout of the Documents Tab of a Corpus
layoutDocview :: R.State DocumentIdsDeleted -> R.State LocalCategories -> R.State Query -> R.State T.Params -> Props -> R.Element layoutDocview :: R.State Query -> R.State T.Params -> Props -> R.Element
layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories query tableParams@(params /\ _) p = R.createElement el p [] layoutDocview query tableParams@(params /\ _) p = R.createElement el p []
where where
el = R.hooksComponent "LayoutDocView" cpt el = R.hooksComponent "LayoutDocView" cpt
cpt {nodeId, tabType, listId, corpusId, totalRecords, chart, showSearch} _children = do cpt {nodeId, tabType, listId, corpusId, totalRecords, chart, showSearch} _children = do
...@@ -183,7 +180,7 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories qu ...@@ -183,7 +180,7 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories qu
[ chart [ chart
, if showSearch then searchBar query else H.div {} [] , if showSearch then searchBar query else H.div {} []
, H.div {className: "col-md-12"} , H.div {className: "col-md-12"}
[ pageLoader localCategories tableParams {nodeId, totalRecords, tabType, listId, corpusId, query: fst query} ] [ pageLoader tableParams {nodeId, totalRecords, tabType, listId, corpusId, query: fst query} ]
, H.div {className: "col-md-1 col-md-offset-11"} , H.div {className: "col-md-1 col-md-offset-11"}
[ H.button { className: "btn" [ H.button { className: "btn"
, style: {backgroundColor: "peru", color : "white", border : "white"} , style: {backgroundColor: "peru", color : "white", border : "white"}
...@@ -198,8 +195,6 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories qu ...@@ -198,8 +195,6 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories qu
onClickTrashAll nodeId = mkEffectFn1 $ \_ -> do onClickTrashAll nodeId = mkEffectFn1 $ \_ -> do
launchAff $ deleteAllDocuments nodeId launchAff $ deleteAllDocuments nodeId
-- TODO
-- setDocumentIdsDeleted $ \dids -> Set.union dids (Set.fromFoldable ids)
searchBar :: R.State Query -> R.Element searchBar :: R.State Query -> R.Element
searchBar (query /\ setQuery) = R.createElement el {} [] searchBar (query /\ setQuery) = R.createElement el {} []
...@@ -284,8 +279,8 @@ loadPage {nodeId, tabType, query, listId, corpusId, params: {limit, offset, orde ...@@ -284,8 +279,8 @@ loadPage {nodeId, tabType, query, listId, corpusId, params: {limit, offset, orde
convOrderBy _ = DateAsc -- TODO convOrderBy _ = DateAsc -- TODO
renderPage :: R.State LocalCategories -> R.State T.Params -> PageLoaderProps -> Array DocumentsView -> R.Element renderPage :: R.State T.Params -> PageLoaderProps -> Array DocumentsView -> R.Element
renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res = R.createElement el p [] renderPage (_ /\ setTableParams) p res = R.createElement el p []
where where
el = R.hooksComponent "RenderPage" cpt el = R.hooksComponent "RenderPage" cpt
...@@ -293,13 +288,14 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res = ...@@ -293,13 +288,14 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res =
gi _ = "glyphicon glyphicon-star-empty" gi _ = "glyphicon glyphicon-star-empty"
trashStyle Trash = {textDecoration: "line-through"} trashStyle Trash = {textDecoration: "line-through"}
trashStyle _ = {textDecoration: "none"} trashStyle _ = {textDecoration: "none"}
getCategory {_id, category} = maybe category identity (localCategories ^. at _id)
corpusDocument (Just corpusId) = Router.CorpusDocument corpusId corpusDocument (Just corpusId) = Router.CorpusDocument corpusId
corpusDocument _ = Router.Document corpusDocument _ = Router.Document
cpt {nodeId, corpusId, listId} _children = do cpt {nodeId, corpusId, listId} _children = do
localCategories <- R.useState' (mempty :: LocalCategories)
pure $ R2.buff $ T.tableElt pure $ R2.buff $ T.tableElt
{ rows { rows: rows localCategories
-- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, query}) -- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, query})
, setParams: \params -> setTableParams $ const params , setParams: \params -> setTableParams $ const params
, container: T.defaultContainer { title: "Documents" } , container: T.defaultContainer { title: "Documents" }
...@@ -315,19 +311,20 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res = ...@@ -315,19 +311,20 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res =
, totalRecords: 1000 -- TODO , totalRecords: 1000 -- TODO
} }
where where
rows = (\(DocumentsView r) -> getCategory (localCategories /\ _) {_id, category} = maybe category identity (localCategories ^. at _id)
let cat = getCategory r rows localCategories = (\(DocumentsView r) ->
let cat = getCategory localCategories r
isDel = Trash == cat in isDel = Trash == cat in
{ row: map R2.scuff $ [ { row: map R2.scuff $ [
H.div {} H.div {}
[ H.a { className: gi cat [ H.a { className: gi cat
, style: trashStyle cat , style: trashStyle cat
, onClick: onClick Favorite r._id cat , on: {click: onClick localCategories Favorite r._id cat}
} [] } []
] ]
, H.input { type: "checkbox" , H.input { type: "checkbox"
, checked: isDel , checked: isDel
, onClick: onClick Trash r._id cat , on: {click: onClick localCategories Trash r._id cat}
} }
-- TODO show date: Year-Month-Day only -- TODO show date: Year-Month-Day only
, H.div { style: trashStyle cat } [ H.text (show r.date) ] , H.div { style: trashStyle cat } [ H.text (show r.date) ]
...@@ -339,18 +336,18 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res = ...@@ -339,18 +336,18 @@ renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res =
] ]
, delete: true , delete: true
}) <$> res }) <$> res
onClick catType nid cat = mkEffectFn1 $ \_-> do onClick (_ /\ setLocalCategories) catType nid cat = \_-> do
let newCat = if (catType == Favorite) then (favCategory cat) else (trashCategory cat) let newCat = if (catType == Favorite) then (favCategory cat) else (trashCategory cat)
setLocalCategories $ insert nid newCat setLocalCategories $ insert nid newCat
void $ launchAff $ putCategories nodeId $ CategoryQuery {nodeIds: [nid], category: newCat} void $ launchAff $ putCategories nodeId $ CategoryQuery {nodeIds: [nid], category: newCat}
pageLoader :: R.State LocalCategories -> R.State T.Params -> PageLoaderProps -> R.Element pageLoader :: R.State T.Params -> PageLoaderProps -> R.Element
pageLoader localCategories tableParams@(pageParams /\ _) p = R.createElement el p [] pageLoader tableParams@(pageParams /\ _) p = R.createElement el p []
where where
el = R.hooksComponent "PageLoader" cpt el = R.hooksComponent "PageLoader" cpt
cpt p@{nodeId, listId, corpusId, tabType, query} _children = do cpt p@{nodeId, listId, corpusId, tabType, query} _children = do
useLoader {nodeId, listId, corpusId, tabType, query, params: pageParams} loadPage $ \{loaded} -> useLoader {nodeId, listId, corpusId, tabType, query, params: pageParams} loadPage $ \{loaded} ->
renderPage localCategories tableParams p loaded renderPage tableParams p loaded
--------------------------------------------------------- ---------------------------------------------------------
sampleData' :: DocumentsView sampleData' :: DocumentsView
......
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