From 32b30314553a1748dfa2edee63b8f39816238399 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 24 Nov 2021 13:43:59 +1100 Subject: [PATCH] Re-organize frontend modules 1. "Components" refers to React components. "Types" and "HttpError" are not React components and should thus be moved out. 2. Only components use JSX syntax, other files can/should have a regular .ts extension. 3. If a file only exports one thing, make it a default export. --- taker-frontend/src/App.tsx | 4 ++-- taker-frontend/src/{components/HttpError.tsx => HttpError.ts} | 2 +- taker-frontend/src/components/ErrorToast.tsx | 2 +- taker-frontend/src/components/History.tsx | 2 +- taker-frontend/src/components/NavBar.tsx | 2 +- taker-frontend/src/components/Timestamp.tsx | 2 +- taker-frontend/src/components/Trade.tsx | 2 +- taker-frontend/src/components/Wallet.tsx | 2 +- taker-frontend/src/{components/Types.tsx => types.ts} | 0 9 files changed, 9 insertions(+), 9 deletions(-) rename taker-frontend/src/{components/HttpError.tsx => HttpError.ts} (91%) rename taker-frontend/src/{components/Types.tsx => types.ts} (100%) diff --git a/taker-frontend/src/App.tsx b/taker-frontend/src/App.tsx index a23ee18..9ae10e3 100644 --- a/taker-frontend/src/App.tsx +++ b/taker-frontend/src/App.tsx @@ -20,6 +20,7 @@ import Footer from "./components/Footer"; import History from "./components/History"; import Nav from "./components/NavBar"; import Trade from "./components/Trade"; +import { Wallet, WalletInfoBar } from "./components/Wallet"; import { BXBTData, Cfd, @@ -31,8 +32,7 @@ import { Order, StateGroupKey, WalletInfo, -} from "./components/Types"; -import { Wallet, WalletInfoBar } from "./components/Wallet"; +} from "./types"; import useLatestEvent from "./useLatestEvent"; import usePostRequest from "./usePostRequest"; diff --git a/taker-frontend/src/components/HttpError.tsx b/taker-frontend/src/HttpError.ts similarity index 91% rename from taker-frontend/src/components/HttpError.tsx rename to taker-frontend/src/HttpError.ts index b80ece6..72dc763 100644 --- a/taker-frontend/src/components/HttpError.tsx +++ b/taker-frontend/src/HttpError.ts @@ -1,6 +1,6 @@ // A wrapper to parse RFC 7807 // Pass result of `await response.json()` into the constructor. -export class HttpError extends Error { +export default class HttpError extends Error { title: string; detail?: string; diff --git a/taker-frontend/src/components/ErrorToast.tsx b/taker-frontend/src/components/ErrorToast.tsx index 48fd9f7..3b34437 100644 --- a/taker-frontend/src/components/ErrorToast.tsx +++ b/taker-frontend/src/components/ErrorToast.tsx @@ -1,4 +1,4 @@ -import { HttpError } from "./HttpError"; +import HttpError from "../HttpError"; // A generic way of creating an error toast // TODO: Don't use any (`toast: typeof useToast` did not work :( ) diff --git a/taker-frontend/src/components/History.tsx b/taker-frontend/src/components/History.tsx index 3a72a2a..1389870 100644 --- a/taker-frontend/src/components/History.tsx +++ b/taker-frontend/src/components/History.tsx @@ -28,8 +28,8 @@ import { VStack, } from "@chakra-ui/react"; import * as React from "react"; +import { Cfd, StateGroupKey, StateKey, Tx, TxLabel } from "../types"; import usePostRequest from "../usePostRequest"; -import { Cfd, StateGroupKey, StateKey, Tx, TxLabel } from "./Types"; interface HistoryProps { cfds: Cfd[]; diff --git a/taker-frontend/src/components/NavBar.tsx b/taker-frontend/src/components/NavBar.tsx index 32a46a0..99e87f1 100644 --- a/taker-frontend/src/components/NavBar.tsx +++ b/taker-frontend/src/components/NavBar.tsx @@ -17,7 +17,7 @@ import * as React from "react"; import { useNavigate } from "react-router-dom"; import logoBlack from "../images/logo_nav_bar_black.svg"; import logoWhite from "../images/logo_nav_bar_white.svg"; -import { WalletInfo } from "./Types"; +import { WalletInfo } from "../types"; interface NavProps { walletInfo: WalletInfo | null; diff --git a/taker-frontend/src/components/Timestamp.tsx b/taker-frontend/src/components/Timestamp.tsx index cf46e31..1fc2caa 100644 --- a/taker-frontend/src/components/Timestamp.tsx +++ b/taker-frontend/src/components/Timestamp.tsx @@ -1,6 +1,6 @@ import { Text } from "@chakra-ui/react"; import React from "react"; -import { unixTimestampToDate } from "./Types"; +import { unixTimestampToDate } from "../types"; interface Props { timestamp: number; diff --git a/taker-frontend/src/components/Trade.tsx b/taker-frontend/src/components/Trade.tsx index b762883..fa85f0e 100644 --- a/taker-frontend/src/components/Trade.tsx +++ b/taker-frontend/src/components/Trade.tsx @@ -45,7 +45,7 @@ import { } from "@chakra-ui/react"; import { motion } from "framer-motion"; import * as React from "react"; -import { CfdOrderRequestPayload } from "./Types"; +import { CfdOrderRequestPayload } from "../types"; const MotionBox = motion(Box); diff --git a/taker-frontend/src/components/Wallet.tsx b/taker-frontend/src/components/Wallet.tsx index 57c5f1b..da8c934 100644 --- a/taker-frontend/src/components/Wallet.tsx +++ b/taker-frontend/src/components/Wallet.tsx @@ -26,9 +26,9 @@ import { import * as React from "react"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; +import { WalletInfo, WithdrawRequest } from "../types"; import usePostRequest from "../usePostRequest"; import Timestamp from "./Timestamp"; -import { WalletInfo, WithdrawRequest } from "./Types"; interface WalletProps { walletInfo: WalletInfo | null; diff --git a/taker-frontend/src/components/Types.tsx b/taker-frontend/src/types.ts similarity index 100% rename from taker-frontend/src/components/Types.tsx rename to taker-frontend/src/types.ts