Commit 0590abe5 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams table] change to page 1 when searching

parent 7e393a3e
......@@ -23,24 +23,23 @@ import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Aff (Aff)
import Reactix (Component, Element, Ref, State, createElement, fragment, hooksComponentWithModule, unsafeEventValue, useEffect', useState') as R
import Reactix (Component, Element, Ref, State, createElement, fragment, hooksComponentWithModule, unsafeEventValue, useState') as R
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, otherwise, pure, read, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||))
import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Components.Table.Types (ColumnName(..), Rows, TableContainerProps) as T
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core (Action(..), CoreAction(..), CoreState, Dispatch, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Version, Versioned(..), VersionedNgramsTable, VersionedWithCountNgramsTable, _NgramsElement, _NgramsRepoElement, _NgramsTable, _children, _list, _ngrams, _ngrams_repo_elements, _ngrams_scores, _occurrences, _root, addNewNgramA, applyNgramsPatches, applyPatchSet, chartsAfterSync, commitPatch, convOrderBy, coreDispatch, filterTermSize, fromNgramsPatches, ngramsRepoElementToNgramsElement, ngramsTermText, normNgram, patchSetFromMap, replace, rootsOf, singletonNgramsTablePatch, syncResetButtons, toVersioned)
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table (filterRows, table) as T
import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
......@@ -48,7 +47,7 @@ import Gargantext.Utils (queryMatchesLabel, toggleSet, sortWith)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Seq (mapMaybe) as Seq
import Gargantext.Utils.Seq as Seq
thisModule :: String
thisModule = "Gargantext.Components.NgramsTable"
......@@ -314,7 +313,7 @@ loadedNgramsTable = R.createElement loadedNgramsTableCpt
, syncResetButton: [ syncResetButton ]
, tabNgramType
}
, params: params /\ setParams -- TODO-LENS
, params: paramsS -- TODO-LENS
, rows: filteredConvertedRows
, syncResetButton: [ syncResetButton ]
, totalRecords
......@@ -411,13 +410,16 @@ loadedNgramsTable = R.createElement loadedNgramsTableCpt
wrapColElts _ (T.ColumnName "Score") = (_ <> [H.text ("(" <> show scoreType <> ")")])
wrapColElts _ _ = identity
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
paramsS = params /\ setParams
search :: R.Element
search = NTC.searchInput { key: "search-input"
, onSearch: setSearchQuery
, searchQuery: searchQuery }
setSearchQuery :: String -> Effect Unit
setSearchQuery x = setPath $ _ { searchQuery = x }
setSearchQuery x = do
setPath $ _ { searchQuery = x }
T.changePage 1 paramsS
type MkDispatchProps = (
filteredRows :: PreConversionRows
......
module Gargantext.Components.Table where
import Prelude
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Sequence as Seq
import Data.Tuple (fst, snd)
import Effect.Aff (Aff, launchAff_)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Gargantext.Sessions (Session, get)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Table.Types
import Gargantext.Prelude
import Gargantext.Components.Table.Types (ColumnName, OrderBy, OrderByDirection(..), Params, Props, TableContainerProps, columnName)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Search
import Gargantext.Components.Search (SearchType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix (effectLink)
thisModule :: String
thisModule = "Gargantext.Components.Table"
type Page = Int
type State =
{ page :: Int
{ page :: Page
, pageSize :: PageSizes
, orderBy :: OrderBy
, searchType :: SearchType
......@@ -223,8 +221,12 @@ textDescription currPage pageSize totalRecords =
end = if end' > totalRecords then totalRecords else end'
msg = "Showing " <> show start <> " to " <> show end <> " of " <> show totalRecords
changePage :: Page -> R.State Params -> Effect Unit
changePage page (_ /\ setParams) =
setParams $ \p -> stateParams $ (paramsState p) { page = page }
pagination :: R.State Params -> Int -> R.Element
pagination (params /\ setParams) tp =
pagination p@(params /\ setParams) tp =
H.span {} $
[ H.text " ", prev, first, ldots]
<>
......@@ -237,7 +239,6 @@ pagination (params /\ setParams) tp =
[ rdots, last, next ]
where
{page} = paramsState params
changePage page = setParams $ \p -> stateParams $ (paramsState p) { page = page }
prev = if page == 1 then
H.text " Prev. "
else
......@@ -269,7 +270,7 @@ pagination (params /\ setParams) tp =
changePageLink i s =
H.span {}
[ H.text " "
, effectLink (changePage i) s
, effectLink (changePage i p) s
, H.text " "
]
......
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