diff --git a/src/Gargantext/Components/DocsTable.purs b/src/Gargantext/Components/DocsTable.purs index 130294b5007294b3ff7c96cc23b198c7bac9a32a..21846463ec32325b5b56bc47c5f9512d9626efa3 100644 --- a/src/Gargantext/Components/DocsTable.purs +++ b/src/Gargantext/Components/DocsTable.purs @@ -30,6 +30,7 @@ import Reactix.DOM.HTML as H import Gargantext.Components.Table as T import Gargantext.Components.Loader (loader) import Gargantext.Ends (Frontends, url) +import Gargantext.Hooks.Loader (useLoaderWithCache) import Gargantext.Utils.Reactix as R2 import Gargantext.Routes as Routes import Gargantext.Routes (SessionRoute(NodeAPI)) @@ -372,11 +373,13 @@ pageLayout props = R.createElement pageLayoutCpt props [] pageLayoutCpt :: R.Memo PageLayoutProps pageLayoutCpt = R.memo' $ R.staticComponent "G.C.DocsTable.pageLayout" cpt where cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ = - loader path (loadPage session) paint + --loader path (loadPage session) paint + useLoader path keyFunc (loadPage session) paint where path = {nodeId, listId, corpusId, tabType, query, params: fst params} paint (Tuple count docs) = page params (newProps count) docs newProps count = props { totalRecords = count } + keyFunc { corpusId, listId, nodeId, tabType } = "docs-table-" <> (show corpusId) <> "-" <> (show listId) <> "-" <> (show nodeId) <> "-" <> (show tabType) type PageProps = ( params :: R.State T.Params diff --git a/src/Gargantext/Components/Loader.purs b/src/Gargantext/Components/Loader.purs index 195c49b4377676fe04249b7dda4c81044b8e3dd7..798fcb1f572a40577996906409c4f1d1878d4839 100644 --- a/src/Gargantext/Components/Loader.purs +++ b/src/Gargantext/Components/Loader.purs @@ -6,6 +6,7 @@ import Data.Tuple.Nested ((/\)) import Effect.Aff (Aff) import Effect.Class (liftEffect) import Reactix as R + import Gargantext.Utils.Reactix as R2 import Gargantext.Components.LoadingSpinner (loadingSpinner) diff --git a/src/Gargantext/Components/NgramsTable.purs b/src/Gargantext/Components/NgramsTable.purs index 2e2b5394a4665456ccde3cf66c46855504f623ff..d88d486f2847813c12be12e2decc8aa2babca5e8 100644 --- a/src/Gargantext/Components/NgramsTable.purs +++ b/src/Gargantext/Components/NgramsTable.purs @@ -33,6 +33,7 @@ import Gargantext.Components.LoadingSpinner (loadingSpinner) import Gargantext.Components.NgramsTable.Components as NTC import Gargantext.Components.NgramsTable.Core (Action(..), CoreState, Dispatch, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Versioned(..), VersionedNgramsTable, _NgramsElement, _NgramsTable, _children, _list, _ngrams, _occurrences, _root, addNewNgram, applyNgramsPatches, applyPatchSet, commitPatchR, convOrderBy, filterTermSize, fromNgramsPatches, initialPageParams, loadNgramsTableAll, ngramsTermText, normNgram, patchSetFromMap, replace, rootsOf, singletonNgramsTablePatch, syncPatchesR) import Gargantext.Components.Table as T +import Gargantext.Hooks.Loader (useLoaderWithCache) import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), read) import Gargantext.Sessions (Session) import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes) @@ -500,6 +501,8 @@ mainNgramsTableCpt = R.hooksComponent "G.C.NT.mainNgramsTable" cpt mainNgramsTablePaint {path, tabNgramType, versioned, withAutoUpdate} Nothing -> loadingSpinner {} + keyFunc { listIds, nodeId, tabType } = "ngrams-table-" <> (show tabType) <> "-" <> (show nodeId) <> "-" <> (show listIds) + type MainNgramsTablePaintProps = ( path :: PageParams diff --git a/src/Gargantext/Types.purs b/src/Gargantext/Types.purs index d218d809ca3446dc18fc27309c07e9162c2ad325..923e610341bf21f890cbd572f9f54d6102e969ee 100644 --- a/src/Gargantext/Types.purs +++ b/src/Gargantext/Types.purs @@ -287,9 +287,10 @@ type ListId = Int data ScoreType = Occurrences derive instance genericScoreType :: Generic ScoreType _ - instance showScoreType :: Show ScoreType where show = genericShow +instance eqScoreType :: Eq ScoreType where + eq = genericEq type SearchQuery = String @@ -425,6 +426,39 @@ data TabSubType a = TabDocs | TabNgramType a | TabTrash | TabMoreLikeFav | TabMo derive instance eqTabSubType :: Eq a => Eq (TabSubType a) derive instance ordTabSubType :: Ord a => Ord (TabSubType a) +{- instance encodeTabSubType a :: EncodeJson a => EncodeJson (TabSubType a) where + encodeJson TabDocs = + "type" := "TabDocs" + ~> "data" := Nothing + ~> jsonEmptyObject + encodeJson (TabNgramType a) = + "type" := "TabNgramType" + ~> "data" := encodeJson a + ~> jsonEmptyObject + encodeJson TabTrash = + "type" := "TabTrash" + ~> "data" := Nothing + ~> jsonEmptyObject + encodeJson TabMoreLikeFav = + "type" := "TabMoreLikeFav" + ~> "data" := Nothing + ~> jsonEmptyObject + encodeJson TabMoreLikeTrash = + "type" := "TabMoreLikeTrash" + ~> "data" := Nothing + ~> jsonEmptyObject +instance decodeTabSubType a :: DecodeJson a => DecodeJson (TabSubType a) where + decodeJson j = do + obj <- decodeJson j + typ <- obj .: "type" + dat <- obj .: "data" + case typ of + "TabDocs" -> TabDocs + "TabNgramType" -> TabNgramType dat + "TabTrash" -> TabTrash + "TabMoreLikeFav" -> TabMoreLikeFav + "TabMoreLikeTrash" -> TabMoreLikeTrash + _ -> Left ("Unknown type '" <> typ <> "'") -} instance showTabSubType :: Show a => Show (TabSubType a) where show TabDocs = "Docs" @@ -438,13 +472,34 @@ data TabType | TabPairing (TabSubType PTabNgramType) | TabDocument (TabSubType CTabNgramType) +derive instance genericTabType :: Generic TabType _ derive instance eqTabType :: Eq TabType derive instance ordTabType :: Ord TabType - -derive instance genericTabType :: Generic TabType _ - instance showTabType :: Show TabType where show = genericShow +{- instance encodeTabType :: EncodeJson TabType where + encodeJson (TabCorpus d) = + "type" := "TabCorpus" + ~> "data" := encodeJson d + ~> jsonEmptyObject + encodeJson (TabDocument d) = + "type" := "TabDocument" + ~> "data" := encodeJson d + ~> jsonEmptyObject + encodeJson (TabPairing d) = + "type" := "TabPairing" + ~> "data" := encodeJson d + ~> jsonEmptyObject +instance decodeTabType :: DecodeJson TabType where + decodeJson j = do + obj <- decodeJson j + typ <- obj .: "type" + dat <- obj .: "data" + case typ of + "TabCorpus" -> TabCorpus dat + "TabDocument" -> TabDocument dat + "TabPairing" -> TabPairing dat + _ -> Left ("Unknown type '" <> typ <> "'") -} type TableResult a = {count :: Int, docs :: Array a} type AffTableResult a = Aff (TableResult a)