gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: check moving back or forw


From: gnunet
Subject: [taler-wallet-core] branch master updated: check moving back or forw
Date: Thu, 14 Apr 2022 21:35:52 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new bf3e0111 check moving back or forw
bf3e0111 is described below

commit bf3e011183853452840673978689a21ea6644947
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Apr 14 16:35:00 2022 -0300

    check moving back or forw
---
 packages/anastasis-webui/src/pages/home/index.tsx | 64 ++++++++++++-----------
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/packages/anastasis-webui/src/pages/home/index.tsx 
b/packages/anastasis-webui/src/pages/home/index.tsx
index cf31d68e..7e7a0006 100644
--- a/packages/anastasis-webui/src/pages/home/index.tsx
+++ b/packages/anastasis-webui/src/pages/home/index.tsx
@@ -92,39 +92,39 @@ function ErrorBoundary(props: {
   return <div>{props.children}</div>;
 }
 
+let currentHistoryId = 0;
+
 export function AnastasisClientFrame(props: AnastasisClientFrameProps): VNode {
   const reducer = useAnastasisContext();
   if (!reducer) {
     return <p>Fatal: Reducer must be in context.</p>;
   }
-  const next = async (): Promise<void> => {
+  const doBack = async (): Promise<void> => {
+    history.back();
+
+    if (props.onBack) {
+      await props.onBack();
+    }
+  };
+  const doNext = async (): Promise<void> => {
+    try {
+      const nextId: number =
+        (history.state && typeof history.state.id === "number"
+          ? history.state.id
+          : 0) + 1;
+
+      currentHistoryId = nextId;
+
+      history.pushState({ id: nextId }, "unused", `#${nextId}`);
+    } catch (e) {
+      console.log(e);
+    }
+
     if (props.onNext) {
       await props.onNext();
     } else {
       await reducer.transition("next", {});
     }
-    reducer.currentReducerState?.reducer_type;
-
-    const stateName = !reducer.currentReducerState
-      ? "not-defined"
-      : reducer.currentReducerState.reducer_type === "backup"
-      ? `#backup-${reducer.currentReducerState.backup_state}`
-      : reducer.currentReducerState.reducer_type === "recovery"
-      ? `recovery-${reducer.currentReducerState.recovery_state}`
-      : reducer.currentReducerState.reducer_type === "error"
-      ? `error-${reducer.currentReducerState.code}`
-      : "unknown";
-
-    const id: number =
-      typeof history.state.id === "number" ? history.state.id : 1;
-
-    history.pushState(
-      {
-        id: id + 1,
-      },
-      "unused",
-      stateName,
-    );
   };
   const handleKeyPress = (
     e: h.JSX.TargetedKeyboardEvent<HTMLDivElement>,
@@ -133,9 +133,14 @@ export function AnastasisClientFrame(props: 
AnastasisClientFrameProps): VNode {
     // FIXME: By default, "next" action should be executed here
   };
 
-  const browserOnBackButton = useCallback((ev: PopStateEvent) => {
-    console.log("BACK BACK", JSON.stringify(ev.state));
-    reducer.back();
+  const browserOnBackButton = useCallback(async (ev: PopStateEvent) => {
+    //check if we are going back or forward
+    if (!ev.state || ev.state.id === 0 || ev.state.id < currentHistoryId) {
+      await reducer.back();
+    } else {
+      await reducer.transition("next", {});
+    }
+
     // reducer
     return false;
   }, []);
@@ -164,16 +169,13 @@ export function AnastasisClientFrame(props: 
AnastasisClientFrameProps): VNode {
                 justifyContent: "space-between",
               }}
             >
-              <button
-                class="button"
-                onClick={() => (props.onBack ?? reducer.back)()}
-              >
+              <button class="button" onClick={doBack}>
                 Back
               </button>
               <AsyncButton
                 class="button is-info"
                 data-tooltip={props.hideNext}
-                onClick={next}
+                onClick={doNext}
                 disabled={props.hideNext !== undefined}
               >
                 Next

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]