From 6b6f80466ee07f591203c28a724ce4e7128af85d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 9 Dec 2022 12:07:01 -0300 Subject: remove unused --- packages/demobank-ui/src/.babelrc | 3 - .../demobank-ui/src/components/AsyncButton.tsx | 60 ---- packages/demobank-ui/src/components/FileButton.tsx | 71 ----- .../demobank-ui/src/components/Notifications.tsx | 74 ----- .../src/components/fields/DateInput.tsx | 102 ------ .../src/components/fields/EmailInput.tsx | 69 ---- .../src/components/fields/FileInput.tsx | 102 ------ .../src/components/fields/ImageInput.tsx | 86 ----- .../src/components/fields/NumberInput.tsx | 68 ---- .../src/components/fields/TextInput.tsx | 80 ----- .../src/components/menu/NavigationBar.tsx | 51 --- .../demobank-ui/src/components/menu/SideBar.tsx | 74 ----- packages/demobank-ui/src/components/menu/index.tsx | 135 -------- .../src/components/picker/DatePicker.tsx | 347 --------------------- .../components/picker/DurationPicker.stories.tsx | 55 ---- .../src/components/picker/DurationPicker.tsx | 210 ------------- packages/demobank-ui/src/index.tsx | 4 +- .../demobank-ui/src/pages/home/QrCodeSection.tsx | 2 +- packages/demobank-ui/src/style/index.css | 0 19 files changed, 3 insertions(+), 1590 deletions(-) delete mode 100644 packages/demobank-ui/src/.babelrc delete mode 100644 packages/demobank-ui/src/components/AsyncButton.tsx delete mode 100644 packages/demobank-ui/src/components/FileButton.tsx delete mode 100644 packages/demobank-ui/src/components/Notifications.tsx delete mode 100644 packages/demobank-ui/src/components/fields/DateInput.tsx delete mode 100644 packages/demobank-ui/src/components/fields/EmailInput.tsx delete mode 100644 packages/demobank-ui/src/components/fields/FileInput.tsx delete mode 100644 packages/demobank-ui/src/components/fields/ImageInput.tsx delete mode 100644 packages/demobank-ui/src/components/fields/NumberInput.tsx delete mode 100644 packages/demobank-ui/src/components/fields/TextInput.tsx delete mode 100644 packages/demobank-ui/src/components/menu/NavigationBar.tsx delete mode 100644 packages/demobank-ui/src/components/menu/SideBar.tsx delete mode 100644 packages/demobank-ui/src/components/menu/index.tsx delete mode 100644 packages/demobank-ui/src/components/picker/DatePicker.tsx delete mode 100644 packages/demobank-ui/src/components/picker/DurationPicker.stories.tsx delete mode 100644 packages/demobank-ui/src/components/picker/DurationPicker.tsx delete mode 100644 packages/demobank-ui/src/style/index.css (limited to 'packages/demobank-ui/src') diff --git a/packages/demobank-ui/src/.babelrc b/packages/demobank-ui/src/.babelrc deleted file mode 100644 index 05f4dcc81..000000000 --- a/packages/demobank-ui/src/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["preact-cli/babel"] -} diff --git a/packages/demobank-ui/src/components/AsyncButton.tsx b/packages/demobank-ui/src/components/AsyncButton.tsx deleted file mode 100644 index 0e1391109..000000000 --- a/packages/demobank-ui/src/components/AsyncButton.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { ComponentChildren, h, VNode } from "preact"; -import { useLayoutEffect, useRef } from "preact/hooks"; -import { useAsync } from "../hooks/async.js"; - -type Props = { - children: ComponentChildren; - disabled?: boolean; - onClick?: () => Promise; - grabFocus?: boolean; - [rest: string]: any; -}; - -export function AsyncButton({ - onClick, - grabFocus, - disabled, - children, - ...rest -}: Props): VNode { - const { isLoading, request } = useAsync(onClick); - - const buttonRef = useRef(null); - useLayoutEffect(() => { - if (grabFocus) buttonRef.current?.focus(); - }, [grabFocus]); - - // if (isSlow) { - // return ; - // } - if (isLoading) return ; - - return ( - - - - ); -} diff --git a/packages/demobank-ui/src/components/FileButton.tsx b/packages/demobank-ui/src/components/FileButton.tsx deleted file mode 100644 index d7ed52f5d..000000000 --- a/packages/demobank-ui/src/components/FileButton.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { h, VNode } from "preact"; -import { useRef, useState } from "preact/hooks"; - -const MAX_IMAGE_UPLOAD_SIZE = 1024 * 1024; - -export interface FileTypeContent { - content: string; - type: string; - name: string; -} - -interface Props { - label: string; - onChange: (v: FileTypeContent | undefined) => void; -} -export function FileButton(props: Props): VNode { - const fileInputRef = useRef(null); - const [sizeError, setSizeError] = useState(false); - return ( -
- - { - const f: FileList | null = e.currentTarget.files; - if (!f || f.length != 1) return props.onChange(undefined); - - if (f[0].size > MAX_IMAGE_UPLOAD_SIZE) { - setSizeError(true); - return props.onChange(undefined); - } - setSizeError(false); - return f[0].arrayBuffer().then((b) => { - const content = new Uint8Array(b).reduce( - (data, byte) => data + String.fromCharCode(byte), - "", - ); - return props.onChange({ - content, - name: f[0].name, - type: f[0].type, - }); - }); - }} - /> - {sizeError && ( -

File should be smaller than 1 MB

- )} -
- ); -} diff --git a/packages/demobank-ui/src/components/Notifications.tsx b/packages/demobank-ui/src/components/Notifications.tsx deleted file mode 100644 index 6dd3a2d50..000000000 --- a/packages/demobank-ui/src/components/Notifications.tsx +++ /dev/null @@ -1,74 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode } from "preact"; - -export interface Notification { - message: string; - description?: string | VNode; - type: MessageType; -} - -export type MessageType = "INFO" | "WARN" | "ERROR" | "SUCCESS"; - -interface Props { - notifications: Notification[]; - removeNotification?: (n: Notification) => void; -} - -function messageStyle(type: MessageType): string { - switch (type) { - case "INFO": - return "message is-info"; - case "WARN": - return "message is-warning"; - case "ERROR": - return "message is-danger"; - case "SUCCESS": - return "message is-success"; - default: - return "message"; - } -} - -export function Notifications({ - notifications, - removeNotification, -}: Props): VNode { - return ( -
- {notifications.map((n, i) => ( -
-
-

{n.message}

- {removeNotification && ( -
- {n.description &&
{n.description}
} -
- ))} -
- ); -} diff --git a/packages/demobank-ui/src/components/fields/DateInput.tsx b/packages/demobank-ui/src/components/fields/DateInput.tsx deleted file mode 100644 index 0eeb1b2fd..000000000 --- a/packages/demobank-ui/src/components/fields/DateInput.tsx +++ /dev/null @@ -1,102 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { format, subYears } from "date-fns"; -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; -import { DatePicker } from "../picker/DatePicker.js"; - -export interface DateInputProps { - label: string; - grabFocus?: boolean; - tooltip?: string; - error?: string; - years?: Array; - onConfirm?: () => void; - bind: [string, (x: string) => void]; -} - -export function DateInput(props: DateInputProps): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (props.grabFocus) inputRef.current?.focus(); - }, [props.grabFocus]); - const [opened, setOpened] = useState(false); - - const value = props.bind[0] || ""; - const [dirty, setDirty] = useState(false); - const showError = dirty && props.error; - - const calendar = subYears(new Date(), 30); - - return ( -
- -
-
-

- { - if (e.key === "Enter" && props.onConfirm) props.onConfirm(); - }} - onInput={(e) => { - const text = e.currentTarget.value; - setDirty(true); - props.bind[1](text); - }} - ref={inputRef} - /> -

-

- { - setOpened(true); - }} - > - - - - -

-
-
-

Using the format yyyy-mm-dd

- {showError &&

{props.error}

} - setOpened(false)} - dateReceiver={(d) => { - setDirty(true); - const v = format(d, "yyyy-MM-dd"); - props.bind[1](v); - }} - /> -
- ); -} diff --git a/packages/demobank-ui/src/components/fields/EmailInput.tsx b/packages/demobank-ui/src/components/fields/EmailInput.tsx deleted file mode 100644 index 9f6624aa5..000000000 --- a/packages/demobank-ui/src/components/fields/EmailInput.tsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; - -export interface TextInputProps { - label: string; - grabFocus?: boolean; - error?: string; - placeholder?: string; - tooltip?: string; - onConfirm?: () => void; - bind: [string, (x: string) => void]; -} - -export function EmailInput(props: TextInputProps): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (props.grabFocus) inputRef.current?.focus(); - }, [props.grabFocus]); - const value = props.bind[0]; - const [dirty, setDirty] = useState(false); - const showError = dirty && props.error; - return ( -
- -
- { - if (e.key === "Enter" && props.onConfirm) props.onConfirm(); - }} - onInput={(e) => { - setDirty(true); - props.bind[1]((e.target as HTMLInputElement).value); - }} - ref={inputRef} - style={{ display: "block" }} - /> -
- {showError &&

{props.error}

} -
- ); -} diff --git a/packages/demobank-ui/src/components/fields/FileInput.tsx b/packages/demobank-ui/src/components/fields/FileInput.tsx deleted file mode 100644 index cc49a632d..000000000 --- a/packages/demobank-ui/src/components/fields/FileInput.tsx +++ /dev/null @@ -1,102 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; - -const MAX_IMAGE_UPLOAD_SIZE = 1024 * 1024; - -export interface FileTypeContent { - content: string; - type: string; - name: string; -} - -export interface FileInputProps { - label: string; - grabFocus?: boolean; - disabled?: boolean; - error?: string; - placeholder?: string; - tooltip?: string; - onChange: (v: FileTypeContent | undefined) => void; -} - -export function FileInput(props: FileInputProps): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (props.grabFocus) inputRef.current?.focus(); - }, [props.grabFocus]); - - const fileInputRef = useRef(null); - const [sizeError, setSizeError] = useState(false); - return ( -
- -
- { - const f: FileList | null = e.currentTarget.files; - if (!f || f.length != 1) return props.onChange(undefined); - - if (f[0].size > MAX_IMAGE_UPLOAD_SIZE) { - setSizeError(true); - return props.onChange(undefined); - } - setSizeError(false); - return f[0].arrayBuffer().then((b) => { - const b64 = btoa( - new Uint8Array(b).reduce( - (data, byte) => data + String.fromCharCode(byte), - "", - ), - ); - return props.onChange({ - content: `data:${f[0].type};base64,${b64}`, - name: f[0].name, - type: f[0].type, - }); - }); - }} - /> - {props.error &&

{props.error}

} - {sizeError && ( -

File should be smaller than 1 MB

- )} -
-
- ); -} diff --git a/packages/demobank-ui/src/components/fields/ImageInput.tsx b/packages/demobank-ui/src/components/fields/ImageInput.tsx deleted file mode 100644 index 15b25f1c2..000000000 --- a/packages/demobank-ui/src/components/fields/ImageInput.tsx +++ /dev/null @@ -1,86 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; -import emptyImage from "../../assets/empty.png"; -import { TextInputProps } from "./TextInput.js"; - -const MAX_IMAGE_UPLOAD_SIZE = 1024 * 1024; - -export function ImageInput(props: TextInputProps): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (props.grabFocus) inputRef.current?.focus(); - }, [props.grabFocus]); - - const value = props.bind[0]; - // const [dirty, setDirty] = useState(false) - const image = useRef(null); - const [sizeError, setSizeError] = useState(false); - function onChange(v: string): void { - // setDirty(true); - props.bind[1](v); - } - return ( -
- -
- image.current?.click()} - /> - { - const f: FileList | null = e.currentTarget.files; - if (!f || f.length != 1) return onChange(emptyImage); - - if (f[0].size > MAX_IMAGE_UPLOAD_SIZE) { - setSizeError(true); - return onChange(emptyImage); - } - setSizeError(false); - return f[0].arrayBuffer().then((b) => { - const b64 = btoa( - new Uint8Array(b).reduce( - (data, byte) => data + String.fromCharCode(byte), - "", - ), - ); - return onChange(`data:${f[0].type};base64,${b64}` as any); - }); - }} - /> - {props.error &&

{props.error}

} - {sizeError && ( -

Image should be smaller than 1 MB

- )} -
-
- ); -} diff --git a/packages/demobank-ui/src/components/fields/NumberInput.tsx b/packages/demobank-ui/src/components/fields/NumberInput.tsx deleted file mode 100644 index 69af18c77..000000000 --- a/packages/demobank-ui/src/components/fields/NumberInput.tsx +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; - -export interface TextInputProps { - label: string; - grabFocus?: boolean; - error?: string; - placeholder?: string; - tooltip?: string; - onConfirm?: () => void; - bind: [string, (x: string) => void]; -} - -export function PhoneNumberInput(props: TextInputProps): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (props.grabFocus) inputRef.current?.focus(); - }, [props.grabFocus]); - const value = props.bind[0]; - const [dirty, setDirty] = useState(false); - const showError = dirty && props.error; - return ( -
- -
- { - if (e.key === "Enter" && props.onConfirm) props.onConfirm(); - }} - onInput={(e) => { - setDirty(true); - props.bind[1]((e.target as HTMLInputElement).value); - }} - ref={inputRef} - style={{ display: "block" }} - /> -
- {showError &&

{props.error}

} -
- ); -} diff --git a/packages/demobank-ui/src/components/fields/TextInput.tsx b/packages/demobank-ui/src/components/fields/TextInput.tsx deleted file mode 100644 index 5c6fe3157..000000000 --- a/packages/demobank-ui/src/components/fields/TextInput.tsx +++ /dev/null @@ -1,80 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2022 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; - -export interface TextInputProps { - inputType?: "text" | "number" | "multiline" | "password"; - label: string; - grabFocus?: boolean; - disabled?: boolean; - error?: string; - placeholder?: string; - tooltip?: string; - onConfirm?: () => void; - bind: [string, (x: string) => void]; -} - -const TextInputType = function ({ inputType, grabFocus, ...rest }: any): VNode { - const inputRef = useRef(null); - useLayoutEffect(() => { - if (grabFocus) inputRef.current?.focus(); - }, [grabFocus]); - - return inputType === "multiline" ? ( -