Commit b89c20ae authored by Nicolas Pouillard's avatar Nicolas Pouillard

Refactor: use directly Seq instead of Array here

parent 2d81fdd5
......@@ -9,6 +9,7 @@ import Data.Array (concat, filter)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Sequence (Seq)
import Data.Sequence as Seq
import Data.Set (Set)
import Data.Set as Set
......@@ -182,7 +183,7 @@ type PagePath = { nodeId :: Int
initialPagePath :: {session :: Session, nodeId :: Int, listId :: Int, query :: SearchQuery} -> PagePath
initialPagePath {session, nodeId, listId, query} = {session, nodeId, listId, query, params: T.initialParams}
loadPage :: PagePath -> Aff (Array DocumentsView)
loadPage :: PagePath -> Aff (Seq DocumentsView)
loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do
let
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
......@@ -198,16 +199,13 @@ loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searc
--SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
SearchResult {result} <- post session p query
-- $ SearchQuery {query: concat query, expected: SearchDoc}
pure $ case result of
SearchResultDoc {docs} -> docs2view docs
SearchResultContact {contacts} -> contacts2view contacts
errMessage -> err2view errMessage
pure case result of
SearchResultDoc {docs} -> doc2view <$> Seq.fromFoldable docs
SearchResultContact {contacts} -> contact2view <$> Seq.fromFoldable contacts
errMessage -> pure $ err2view errMessage
docs2view :: Array Document -> Array DocumentsView
docs2view docs = map toView docs
where
toView :: Document -> DocumentsView
toView ( Document { id
doc2view :: Document -> DocumentsView
doc2view ( Document { id
, created: date
, hyperdata: HyperdataRowDocument { authors
, title
......@@ -232,10 +230,9 @@ docs2view docs = map toView docs
, publication_month: fromMaybe 1 publication_month
, publication_day : fromMaybe 1 publication_day
}
contacts2view contacts = map toView contacts
where
toView :: Contact -> DocumentsView
toView (Contact { c_id
contact2view :: Contact -> DocumentsView
contact2view (Contact { c_id
, c_created: date
, c_hyperdata: HyperdataRowContact { firstname
, lastname
......@@ -258,7 +255,7 @@ contacts2view contacts = map toView contacts
}
err2view message =
[DocumentsView { id: 1
DocumentsView { id: 1
, date: "2020-01-01"
, title : "SearchNoResult"
, source: "Source"
......@@ -271,7 +268,6 @@ err2view message =
, publication_month: 10
, publication_day: 1
}
]
......@@ -285,7 +281,7 @@ type PageLayoutProps =
, path :: R.State PagePath
)
type PageProps = ( documents :: Array DocumentsView | PageLayoutProps )
type PageProps = ( documents :: Seq DocumentsView | PageLayoutProps )
-- | Loads and renders a page
pageLayout :: Record PageLayoutProps -> R.Element
......@@ -323,7 +319,7 @@ pageCpt = R.hooksComponentWithModule thisModule "page" cpt
documentUrl id =
url frontends $ Routes.CorpusDocument (sessionId session) nodeId listId id
comma = H.span {} [ H.text ", " ]
rows = Seq.fromFoldable $ row <$> filter (not <<< isDeleted) documents
rows = row <$> Seq.filter (not <<< isDeleted) documents
row dv@(DocumentsView {id, score, title, source, authors, pairs, delete, category}) =
{ row:
T.makeRow [
......
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