diff options
author | Sebastian <sebasjm@gmail.com> | 2024-06-28 13:12:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-06-28 13:12:37 -0300 |
commit | a8861c9deb9521194f513688af6115cf66e511d7 (patch) | |
tree | f73c86fddaf9654734fd95cad9532b9ce8120b6c /packages/challenger-ui/src/pages | |
parent | 5d8bdc3dd61157c6a2836f9b2651d23e557d9bc5 (diff) | |
download | wallet-core-a8861c9deb9521194f513688af6115cf66e511d7.tar.xz |
better header and footer
Diffstat (limited to 'packages/challenger-ui/src/pages')
-rw-r--r-- | packages/challenger-ui/src/pages/AnswerChallenge.tsx | 5 | ||||
-rw-r--r-- | packages/challenger-ui/src/pages/AskChallenge.tsx | 4 | ||||
-rw-r--r-- | packages/challenger-ui/src/pages/Frame.tsx | 151 |
3 files changed, 114 insertions, 46 deletions
diff --git a/packages/challenger-ui/src/pages/AnswerChallenge.tsx b/packages/challenger-ui/src/pages/AnswerChallenge.tsx index 5fe2d9743..b5b3b74b0 100644 --- a/packages/challenger-ui/src/pages/AnswerChallenge.tsx +++ b/packages/challenger-ui/src/pages/AnswerChallenge.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ import { + AbsoluteTime, ChallengerApi, HttpStatusCode, assertUnreachable, @@ -80,7 +81,9 @@ export function AnswerChallenge({ } else { accepted({ attemptsLeft: ok.body.attempts_left, - nextSend: ok.body.next_tx_time, + nextSend: AbsoluteTime.fromProtocolTimestamp( + ok.body.next_tx_time, + ), transmitted: ok.body.transmitted, }); } diff --git a/packages/challenger-ui/src/pages/AskChallenge.tsx b/packages/challenger-ui/src/pages/AskChallenge.tsx index 829cdaccc..cb0223d90 100644 --- a/packages/challenger-ui/src/pages/AskChallenge.tsx +++ b/packages/challenger-ui/src/pages/AskChallenge.tsx @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { AbsoluteTime, HttpStatusCode } from "@gnu-taler/taler-util"; import { Attention, Button, @@ -92,7 +92,7 @@ export function AskChallenge({ } else { accepted({ attemptsLeft: ok.body.attempts_left, - nextSend: ok.body.next_tx_time, + nextSend: AbsoluteTime.fromProtocolTimestamp( ok.body.next_tx_time), transmitted: ok.body.transmitted, }); } diff --git a/packages/challenger-ui/src/pages/Frame.tsx b/packages/challenger-ui/src/pages/Frame.tsx index 612eced0b..dd2a13d8c 100644 --- a/packages/challenger-ui/src/pages/Frame.tsx +++ b/packages/challenger-ui/src/pages/Frame.tsx @@ -14,56 +14,121 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { + Footer, + Header, + ToastBanner, + notifyError, + notifyException, + useTranslationContext, +} from "@gnu-taler/web-util/browser"; import { ComponentChildren, Fragment, h, VNode } from "preact"; +import { useSettingsContext } from "../context/settings.js"; +import { useEffect, useErrorBoundary } from "preact/hooks"; +import { TranslatedString } from "@gnu-taler/taler-util"; +import { + getAllBooleanPreferences, + getLabelForPreferences, + usePreferences, +} from "../context/preferences.js"; + +const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; +const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined; export function Frame({ children }: { children: ComponentChildren }): VNode { + const settings = useSettingsContext(); + const [preferences, updatePreferences] = usePreferences(); + + const [error, resetError] = useErrorBoundary(); + const { i18n } = useTranslationContext(); + useEffect(() => { + if (error) { + if (error instanceof Error) { + console.log("Internal error, please report", error); + notifyException(i18n.str`Internal error, please report.`, error); + } else { + console.log("Internal error, please report", error); + notifyError( + i18n.str`Internal error, please report.`, + String(error) as TranslatedString, + ); + } + resetError(); + } + }, [error]); + return ( - <Fragment> - <header class="bg-indigo-600 w-full mx-auto px-2 border-b border-opacity-25 border-indigo-400"> - <div class="flex flex-row h-16 items-center "> - <div class="flex px-2 justify-start"> - <div class="flex-shrink-0 bg-white rounded-lg"> - <a href="#"> - <img - class="h-8 w-auto" - src='data:image/svg+xml,<?xml version="1.0" encoding="UTF-8" standalone="no"?>%0A<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 201 90">%0A <g fill="%230042b3" fill-rule="evenodd" stroke-width=".3">%0A <path d="M86.7 1.1c15.6 0 29 9.4 36 23.2h-5.9A35.1 35.1 0 0086.7 6.5C67 6.5 51 23.6 51 44.7c0 10.4 3.8 19.7 10 26.6a31.4 31.4 0 01-4.2 3A45.2 45.2 0 0146 44.7c0-24 18.2-43.6 40.7-43.6zm35.8 64.3a40.4 40.4 0 01-39 22.8c3-1.5 6-3.5 8.6-5.7a35.6 35.6 0 0024.6-17.1z" />%0A <path d="M64.2 1.1l3.1.1c-3 1.6-5.9 3.5-8.5 5.8a37.5 37.5 0 00-30.2 37.7c0 14.3 7.3 26.7 18 33.3a29.6 29.6 0 01-8.5.2c-9-8-14.6-20-14.6-33.5 0-24 18.2-43.6 40.7-43.6zm5.4 81.4a35.6 35.6 0 0024.6-17.1h5.9a40.4 40.4 0 01-39 22.8c3-1.5 5.9-3.5 8.5-5.7zm24.8-58.2a37 37 0 00-12.6-12.8 29.6 29.6 0 018.5-.2c4 3.6 7.4 8 9.9 13z" />%0A <path d="M41.8 1.1c1 0 2 0 3.1.2-3 1.5-5.9 3.4-8.5 5.6A37.5 37.5 0 006.1 44.7c0 21.1 16 38.3 35.7 38.3 12.6 0 23.6-7 30-17.6h5.8a40.4 40.4 0 01-35.8 23C19.3 88.4 1 68.8 1 44.7c0-24 18.2-43.6 40.7-43.6zm30.1 23.2a38.1 38.1 0 00-4.5-6.1c1.3-1.2 2.7-2.2 4.3-3 2.3 2.7 4.4 5.8 6 9.1z" />%0A </g>%0A <path d="M76.1 34.4h9.2v-5H61.9v5H71v26h5.1zM92.6 52.9h13.7l3 7.4h5.3l-12.7-31.2h-4.7L84.5 60.3h5.2zm11.8-4.9h-9.9l5-12.4zM123.8 29.4h-4.6v31h20.6v-5h-16zM166.5 29.4H145v31h21.6v-5H150v-8.3h14.5v-4.9h-14.5v-8h16.4zM191.2 39.5c0 1.6-.5 2.8-1.6 3.8s-2.6 1.4-4.4 1.4h-7.4V34.3h7.4c1.9 0 3.4.4 4.4 1.3 1 .9 1.6 2.2 1.6 3.9zm6 20.8l-7.7-11.7c1-.3 1.9-.7 2.7-1.3a8.8 8.8 0 003.6-4.6c.4-1 .5-2.2.5-3.5 0-1.5-.2-2.9-.7-4.1a8.4 8.4 0 00-2.1-3.1c-1-.8-2-1.5-3.4-2-1.3-.4-2.8-.6-4.5-.6h-12.9v31h5V49.4h6.5l7 10.8z" />%0A</svg>' - alt="GNU Taler" - style="height: 1.5rem; margin: 0.5rem;" - /> - </a> - </div> - <span class="flex items-center text-white text-lg font-bold ml-4"> - Challenger - </span> + <div + class="min-h-full flex flex-col m-0 bg-slate-200" + style="min-height: 100vh;" + > + <Header + title="Challenger" + onLogout={undefined} + iconLinkURL="#" + sites={preferences.showChallangeSetup ? [ + ["New challenge","#/setup/1"] + ] :[]} + supportedLangs={["en"]} + > + <li> + <div class="text-xs font-semibold leading-6 text-gray-400"> + <i18n.Translate>Preferences</i18n.Translate> </div> - <div class="block flex-1 ml-6 "></div> - <div class="flex justify-end"></div> + <ul role="list" class="space-y-4"> + {getAllBooleanPreferences().map((set) => { + const isOn: boolean = !!preferences[set]; + return ( + <li key={set} class="pl-2"> + <div class="flex items-center justify-between"> + <span class="flex flex-grow flex-col"> + <span + class="text-sm text-black font-medium leading-6 " + id="availability-label" + > + {getLabelForPreferences(set, i18n)} + </span> + </span> + <button + type="button" + name={`${set} switch`} + data-enabled={isOn} + class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" + role="switch" + aria-checked="false" + aria-labelledby="availability-label" + aria-describedby="availability-description" + onClick={() => { + updatePreferences(set, !isOn); + }} + > + <span + aria-hidden="true" + data-enabled={isOn} + class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out" + ></span> + </button> + </div> + </li> + ); + })} + </ul> + </li> + </Header> + + <div class="fixed z-20 top-14 w-full"> + <div class="mx-auto w-4/5"> + <ToastBanner /> </div> - </header> + </div> <main class="flex-1">{children}</main> - - <footer class="bottom-4 mb-4"> - <div class="mt-8 mx-8 md:order-1 md:mt-0"> - <div> - <p class="text-xs leading-5 text-gray-400"> - Learn more about{" "} - <a - target="_blank" - rel="noreferrer noopener" - class="font-semibold text-gray-500 hover:text-gray-400" - href="https://taler.net" - > - GNU Taler - </a> - </p> - </div> - <div style="flex-grow: 1;"></div> - <p class="text-xs leading-5 text-gray-400"> - Copyright © 2014—2023 Taler Systems SA.{" "} - </p> - </div> - </footer> - </Fragment> + + <Footer + testingUrlKey="challenger-base-url" + GIT_HASH={GIT_HASH} + VERSION={VERSION} + /> + </div> ); } |