Commit d8717503 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/594-dev-ngrams-patch-fixes' into dev

parents f824c0e3 058fa2fe
Pipeline #4608 failed with stage
in 0 seconds
......@@ -35,7 +35,6 @@ initialState
initialState {loaded: {ngramsTable: Versioned {version}}} =
{ ngramsLocalPatch: mempty
, ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsSelection : mempty
, ngramsVersion: version
}
......
......@@ -93,7 +93,6 @@ initialState =
{ ngramsLocalPatch: mempty
, ngramsSelection: mempty
, ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsVersion: 0
}
......@@ -824,6 +823,12 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
-- onNgramsClickRef <- R.useRef Nothing
-- onSaveRef <- R.useRef Nothing
state <- T.useBox initialState
-- https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/594
-- Refreshing view when state.ngramsVersion changes.
ngramsVersion <- T.useFocused (_.ngramsVersion) (\a b -> b { ngramsVersion = a}) state
ngramsVersion' <- T.useLive T.unequal ngramsVersion
-- ngramsLocalPatch <- T.useFocused (_.ngramsLocalPatch) (\a b -> b { ngramsLocalPatch = a }) state
-- nodeId <- T.useFocused (_.nodeId) (\a b -> b { nodeId = a }) path
......@@ -841,11 +846,11 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
case cacheState' of
NT.CacheOn -> pure $ R.fragment
[ loadedNgramsTableHeader { searchQuery, params }
, mainNgramsTableCacheOn (Record.merge props { state })
, mainNgramsTableCacheOn (Record.merge props { key: show ngramsVersion', state })
]
NT.CacheOff -> pure $ R.fragment
[loadedNgramsTableHeader { searchQuery, params}
, mainNgramsTableCacheOff (Record.merge props { state })
[ loadedNgramsTableHeader { searchQuery, params }
, mainNgramsTableCacheOff (Record.merge props { key: show ngramsVersion', state })
]
......@@ -1015,6 +1020,7 @@ ngramsTreeEditRealCpt = here.component "ngramsTreeEditReal" cpt where
type MainNgramsTableCacheProps =
( state :: T.Box State
, key :: String
| MainNgramsTableProps )
mainNgramsTableCacheOn :: R2.Leaf MainNgramsTableCacheProps
......
......@@ -50,11 +50,12 @@ syncResetButtonsCpt = here.component "syncResetButtons" cpt
synchronizeClick _ = delay unit $ \_ -> do
T.write_ true synchronizing
performAction $ Synchronize { afterSync: newAfterSync }
performAction ResetPatches
newAfterSync x = do
afterSync x
liftEffect $ T.write_ false synchronizing
liftEffect $ do
T.write_ false synchronizing
performAction ResetPatches
pure $
......
......@@ -340,7 +340,6 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
tbl :: NgramsTable
tbl = applyNgramsPatches { ngramsLocalPatch
, ngramsStagePatch: mempty
, ngramsValidPatch: mempty
, ngramsVersion: 0 } ngramsTable
getNgramsChildren' :: NgramsTerm -> Array NgramsTerm
getNgramsChildren' n = A.fromFoldable $ ngramsChildren n
......
......@@ -362,8 +362,8 @@ applyNgramsTablePatch (NgramsTablePatch ngramsPatches) (NgramsTable m) =
applyPatchMap applyNgramsPatch ngramsPatches m.ngrams_repo_elements }
applyNgramsPatches :: forall s. CoreState s -> NgramsTable -> NgramsTable
applyNgramsPatches {ngramsLocalPatch, ngramsStagePatch, ngramsValidPatch} =
applyNgramsTablePatch (ngramsLocalPatch <> ngramsStagePatch <> ngramsValidPatch)
applyNgramsPatches { ngramsLocalPatch, ngramsStagePatch } =
applyNgramsTablePatch ( ngramsLocalPatch <> ngramsStagePatch )
-- First the valid patch, then the stage patch, and finally the local patch.
{-
......@@ -436,8 +436,7 @@ syncPatches props state callback = do
s {
ngramsLocalPatch = fromNgramsPatches mempty
, ngramsStagePatch = fromNgramsPatches mempty
, ngramsValidPatch = fromNgramsPatches newPatch <> ngramsLocalPatch <> s.ngramsValidPatch
-- First the already valid patch, then the local patch, then the newly received newPatch.
-- First the local patch, then the newly received newPatch.
, ngramsVersion = newVersion
}) state
here.log2 "[syncPatches] ngramsVersion" newVersion
......@@ -448,7 +447,6 @@ syncPatchesAsync :: forall p s. CoreParams p -> R.State (CoreState s) -> (Unit -
syncPatchesAsync props@{ listIds, tabType }
({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStagePatch
, ngramsValidPatch
, ngramsVersion
} /\ setState) callback = do
when (isEmptyNgramsTablePatch ngramsStagePatch) $ do
......@@ -462,8 +460,7 @@ syncPatchesAsync props@{ listIds, tabType }
s {
ngramsLocalPatch = fromNgramsPatches mempty
, ngramsStagePatch = fromNgramsPatches mempty
, ngramsValidPatch = fromNgramsPatches newPatch <> ngramsLocalPatch <> s.ngramsValidPatch
-- First the already valid patch, then the local patch, then the newly received newPatch.
-- First the local patch, then the newly received newPatch.
, ngramsVersion = newVersion
}
here.log2 "[syncPatches] ngramsVersion" newVersion
......
......@@ -507,8 +507,6 @@ type CoreState s =
, ngramsStagePatch :: NgramsTablePatch
-- ^ These patches are staged (scheduled for synchronization).
-- Requests are being performed at the moment.
, ngramsValidPatch :: NgramsTablePatch
-- ^ These patches have been synchronized with the server.
, ngramsVersion :: Version
| s
}
......
//import crypto from 'crypto';
import { subtle } from '../../src/external-deps/crypto.js';
async function getSHA256Hash(input) {
const textAsBuffer = new TextEncoder().encode(input);
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", textAsBuffer);
const hashBuffer = await subtle.digest("SHA-256", textAsBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hash = hashArray
.map((item) => item.toString(16).padStart(2, "0"))
......
module Gargantext.Utils.Crypto where
import Control.Promise (Promise, toAffE)
import Data.Array as Array
import Data.Set (Set)
import Data.Set as Set
import Data.Array as Array
import Data.String (joinWith)
import Effect (Effect)
import Effect.Aff (Aff)
......@@ -39,7 +40,7 @@ instance IsHashable (Array String) where
hash = hash <<< concat
where
concat :: Array Hash -> String
concat = Array.foldl (<>) ""
concat = joinWith "" <<< Array.sort
instance IsHashable (Set String) where
......
// https://siteultra.com/blog/using-subtle-in-a-javascript-module-from-both-the-browser-and-nodejs
let subtle = undefined;
if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) {
subtle = window.crypto.subtle;
} else {
// Import 'crypto' module in Node.js environment
subtle = require('crypto').subtle;
}
exports.subtle = subtle;
......@@ -124,7 +124,7 @@ spec =
it "Hash List with backend works" do
let list = ["a","b"]
let hashed = "ab19ec537f09499b26f0f62eed7aefad46ab9f498e06a7328ce8e8ef90da6d86"
let hashed = "fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603"
-- ^ hash from backend with text above
h <- Crypto.hash list
h`shouldEqual` hashed
......
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