Commit 80d60b84 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[searchField] fix search input focus not being lost anymore

parent dae0862b
Pipeline #1745 failed with stage
......@@ -7,7 +7,6 @@ import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Newtype (over)
import Data.Nullable (null)
import Data.Set as Set
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
......
......@@ -35,7 +35,7 @@ import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as TT
import Gargantext.Components.Table.Types as TT
import Gargantext.Config.REST (RESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader, useLoaderBox)
import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
......@@ -543,90 +543,104 @@ mainNgramsTable = R.createElement mainNgramsTableCpt
mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = here.component "mainNgramsTable" cpt
where
cpt { afterSync
, boxes
, cacheState
, defaultListId
, path
, tabNgramType
, withAutoUpdate } _ = do
cpt props@{ cacheState } _ = do
cacheState' <- T.useLive T.unequal cacheState
path' <- T.useLive T.unequal path
-- let path = initialPageParams session nodeId [defaultListId] tabType
case cacheState' of
NT.CacheOn -> do
let render versioned = mainNgramsTablePaint { afterSync
, boxes
, cacheState: cacheState'
, path
, tabNgramType
, versioned
, withAutoUpdate } []
useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint { defaultListId, path: path' }
, errorHandler
, handleResponse
, mkRequest
, path: path'
, renderer: render
}
NT.CacheOff -> do
-- path <- R.useState' path
let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync
, boxes
, cacheState: cacheState'
, path
, tabNgramType
, versionedWithCount
, withAutoUpdate } []
useLoader { errorHandler
, loader
, path: path'
, render }
errorHandler err = here.log2 "[mainNgramsTable] RESTError" err
-- NOTE With cache on
-- versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version
versionEndpoint { defaultListId, path: { nodeId, tabType, session } } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
-- NOTE With cache off
loader :: PageParams -> Aff (Either RESTError VersionedWithCountNgramsTable)
loader { listIds
, nodeId
, params: { limit, offset }
, searchQuery
, session
, tabType
, termListFilter
, termSizeFilter
} =
get session $ R.GetNgrams params (Just nodeId)
where
params = { limit
, listIds
, offset: Just offset
, orderBy: Nothing -- TODO
, searchQuery
, tabType
, termListFilter
, termSizeFilter
}
-- NOTE With cache on
mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where
url { listIds
, nodeId
, tabType
} = R.GetNgramsTableAll { listIds
, tabType } (Just nodeId)
handleResponse :: VersionedNgramsTable -> VersionedNgramsTable
handleResponse v = v
NT.CacheOn -> pure $ mainNgramsTableCacheOn props []
NT.CacheOff -> pure $ mainNgramsTableCacheOff props []
mainNgramsTableCacheOn :: R2.Component MainNgramsTableProps
mainNgramsTableCacheOn = R.createElement mainNgramsTableCacheOnCpt
mainNgramsTableCacheOnCpt :: R.Component MainNgramsTableProps
mainNgramsTableCacheOnCpt = here.component "mainNgramsTableCacheOn" cpt where
cpt { afterSync
, boxes
, defaultListId
, path
, tabNgramType
, withAutoUpdate } _ = do
-- let path = initialPageParams session nodeId [defaultListId] tabType
path' <- T.useLive T.unequal path
let render versioned = mainNgramsTablePaint { afterSync
, boxes
, cacheState: NT.CacheOn
, path
, tabNgramType
, versioned
, withAutoUpdate } []
useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint { defaultListId, path: path' }
, errorHandler
, handleResponse
, mkRequest
, path: path'
, renderer: render
}
versionEndpoint { defaultListId, path: { nodeId, tabType, session } } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
errorHandler err = here.log2 "[mainNgramsTable] RESTError" err
mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where
url { listIds
, nodeId
, tabType
} = R.GetNgramsTableAll { listIds
, tabType } (Just nodeId)
handleResponse :: VersionedNgramsTable -> VersionedNgramsTable
handleResponse v = v
mainNgramsTableCacheOff :: R2.Component MainNgramsTableProps
mainNgramsTableCacheOff = R.createElement mainNgramsTableCacheOnCpt
mainNgramsTableCacheOffCpt :: R.Component MainNgramsTableProps
mainNgramsTableCacheOffCpt = here.component "mainNgramsTableCacheOff" cpt where
cpt { afterSync
, boxes
, defaultListId
, path
, tabNgramType
, withAutoUpdate } _ = do
let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync
, boxes
, cacheState: NT.CacheOff
, path
, tabNgramType
, versionedWithCount
, withAutoUpdate } []
useLoaderBox { errorHandler
, loader
, path
, render }
errorHandler err = here.log2 "[mainNgramsTable] RESTError" err
-- NOTE With cache off
loader :: PageParams -> Aff (Either RESTError VersionedWithCountNgramsTable)
loader { listIds
, nodeId
, params: { limit, offset }
, searchQuery
, session
, tabType
, termListFilter
, termSizeFilter
} =
get session $ R.GetNgrams params (Just nodeId)
where
params = { limit
, listIds
, offset: Just offset
, orderBy: Nothing -- TODO
, searchQuery
, tabType
, termListFilter
, termSizeFilter
}
type MainNgramsTablePaintProps = (
cacheState :: NT.CacheState
......
......@@ -21,7 +21,6 @@ import Gargantext.Utils.Crypto (Hash)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Simple.JSON as JSON
import Toestand (Box)
import Toestand as T
here :: R2.Here
......@@ -48,17 +47,16 @@ useLoader { errorHandler, loader: loader', path, render } = do
useLoaderEffect { errorHandler, loader: loader', path, state: state }
pure $ loader { path, render, state } []
pure $ loader { render, state } []
type LoaderProps path st =
( path :: path
, render :: st -> R.Element
type LoaderProps st =
( render :: st -> R.Element
, state :: T.Box (Maybe st) )
loader :: forall path st. Eq path => Eq st => R2.Component (LoaderProps path st)
loader :: forall st. Eq st => R2.Component (LoaderProps st)
loader = R.createElement loaderCpt
loaderCpt :: forall path st. Eq path => Eq st => R.Component (LoaderProps path st)
loaderCpt :: forall st. Eq st => R.Component (LoaderProps st)
loaderCpt = here.component "loader" cpt
where
cpt { render, state } _ = do
......@@ -93,6 +91,44 @@ useLoaderEffect { errorHandler, loader: loader', path, state } = do
Right l' -> liftEffect $ T.write_ (Just l') state
type UseLoaderBox path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> Aff (Either RESTError state)
, path :: T.Box path
, render :: state -> R.Element
)
useLoaderBox :: forall path st. Eq path => Eq st
=> Record (UseLoaderBox path st)
-> R.Hooks R.Element
useLoaderBox { errorHandler, loader: loader', path, render } = do
state <- T.useBox Nothing
useLoaderBoxEffect { errorHandler, loader: loader', path, state: state }
pure $ loader { render, state } []
type UseLoaderBoxEffect path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> Aff (Either RESTError state)
, path :: T.Box path
, state :: T.Box (Maybe state)
)
useLoaderBoxEffect :: forall st path. Eq path => Eq st
=> Record (UseLoaderBoxEffect path st)
-> R.Hooks Unit
useLoaderBoxEffect { errorHandler, loader: loader', path, state } = do
path' <- T.useLive T.unequal path
R.useEffect' $ do
R2.affEffect "G.H.Loader.useLoaderBoxEffect" $ do
l <- loader' path'
case l of
Left err -> liftEffect $ errorHandler err
Right l' -> liftEffect $ T.write_ (Just l') state
newtype HashedResponse a = HashedResponse { hash :: Hash, value :: a }
derive instance Generic (HashedResponse a) _
derive instance Newtype (HashedResponse a) _
......
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