diff options
28 files changed, 751 insertions, 607 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c5c9a1e --- /dev/null +++ b/.pre-commit-config.yaml | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | repos: | ||
| 2 | - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| 3 | rev: v2.3.0 | ||
| 4 | hooks: | ||
| 5 | - id: check-yaml | ||
| 6 | - id: end-of-file-fixer | ||
| 7 | - id: trailing-whitespace | ||
| 8 | - repo: https://github.com/psf/black | ||
| 9 | rev: 21.12b0 | ||
| 10 | hooks: | ||
| 11 | - id: black | ||
| 12 | types_or: | ||
| 13 | - python | ||
| 14 | - repo: https://github.com/asottile/reorder_python_imports | ||
| 15 | rev: v2.7.1 | ||
| 16 | hooks: | ||
| 17 | - id: reorder-python-imports | ||
| 18 | types_or: | ||
| 19 | - python | ||
| 20 | - repo: https://github.com/pre-commit/mirrors-prettier | ||
| 21 | rev: 'v2.5.1' | ||
| 22 | hooks: | ||
| 23 | - id: prettier | ||
| 24 | types_or: | ||
| 25 | - ts | ||
| 26 | - tsx | ||
| 27 | - css | ||
| 28 | - scss | ||
diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..46e2c6d --- /dev/null +++ b/.prettierignore | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | ttun/ | ||
| 2 | ttun.egg-info/ | ||
| 3 | .github/ | ||
| 4 | dist/ | ||
| 5 | node_modules/ | ||
diff --git a/build_requirements.txt b/dev_requirements.txt index 03befb7..d5ce409 100644 --- a/build_requirements.txt +++ b/dev_requirements.txt | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | setuptools | 1 | setuptools |
| 2 | build | 2 | build |
| 3 | setuptools-git-versioning | 3 | setuptools-git-versioning |
| 4 | pre-commit | ||
diff --git a/requirements.txt b/requirements.txt index 04b1cf3..97a6769 100644 --- a/requirements.txt +++ b/requirements.txt | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | -r build_requirements.txt | 1 | -r dev_requirements.txt |
| 2 | websockets ~= 10.0 | 2 | websockets ~= 10.0 |
| 3 | aiohttp ~= 3.8 | 3 | aiohttp ~= 3.8 |
| 4 | appdirs ~= 1.4 | 4 | appdirs ~= 1.4 |
diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index e08c84f..1d231ae 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx | |||
| @@ -1,81 +1,88 @@ | |||
| 1 | import * as React from "react"; | 1 | import * as React from "react"; |
| 2 | import {ReactElement, useContext, useEffect, useMemo, useState} from "react"; | 2 | import { ReactElement, useContext, useEffect, useMemo, useState } from "react"; |
| 3 | import useRequests, { | 3 | import useRequests, { |
| 4 | ReadyState, | 4 | ReadyState, |
| 5 | RequestResponse | 5 | RequestResponse, |
| 6 | } from "../../hooks/useRequests"; | 6 | } from "../../hooks/useRequests"; |
| 7 | 7 | ||
| 8 | import styles from './App.module.scss'; | 8 | import styles from "./App.module.scss"; |
| 9 | import RequestDetails from "../RequestDetails/RequestDetails"; | 9 | import RequestDetails from "../RequestDetails/RequestDetails"; |
| 10 | import {getHost} from "../../utils"; | 10 | import { getHost } from "../../utils"; |
| 11 | import {Container, ListGroup, Nav, Navbar, NavDropdown} from "react-bootstrap"; | 11 | import { |
| 12 | Container, | ||
| 13 | ListGroup, | ||
| 14 | Nav, | ||
| 15 | Navbar, | ||
| 16 | NavDropdown, | ||
| 17 | } from "react-bootstrap"; | ||
| 12 | import classNames from "classnames"; | 18 | import classNames from "classnames"; |
| 13 | import {Sliders} from "../Icons/Sliders"; | 19 | import { Sliders } from "../Icons/Sliders"; |
| 14 | import {Sun} from "../Icons/Sun"; | 20 | import { Sun } from "../Icons/Sun"; |
| 15 | import {Moon} from "../Icons/Moon"; | 21 | import { Moon } from "../Icons/Moon"; |
| 16 | import Trash from "../Icons/Trash"; | 22 | import Trash from "../Icons/Trash"; |
| 17 | import {DarkModeContext} from "../../contexts/DarkMode"; | 23 | import { DarkModeContext } from "../../contexts/DarkMode"; |
| 18 | import RequestList from "../RequestList/RequestList"; | 24 | import RequestList from "../RequestList/RequestList"; |
| 19 | 25 | ||
| 20 | interface Config { | 26 | interface Config { |
| 21 | url: string | 27 | url: string; |
| 22 | } | 28 | } |
| 23 | 29 | ||
| 24 | interface SettingsMenu { | 30 | interface SettingsMenu { |
| 25 | icon: ReactElement, | 31 | icon: ReactElement; |
| 26 | label: string, | 32 | label: string; |
| 27 | onClick: () => void, | 33 | onClick: () => void; |
| 28 | } | 34 | } |
| 29 | 35 | ||
| 30 | type ReadyStateMap = { | 36 | type ReadyStateMap = { |
| 31 | [ReadyState.CONNECTING]: string, | 37 | [ReadyState.CONNECTING]: string; |
| 32 | [ReadyState.OPEN]: string, | 38 | [ReadyState.OPEN]: string; |
| 33 | [ReadyState.CLOSING]: string, | 39 | [ReadyState.CLOSING]: string; |
| 34 | [ReadyState.CLOSED]: string, | 40 | [ReadyState.CLOSED]: string; |
| 35 | } | 41 | }; |
| 36 | 42 | ||
| 37 | const statusIconMap: ReadyStateMap = { | 43 | const statusIconMap: ReadyStateMap = { |
| 38 | [ReadyState.CONNECTING]: '🔴', | 44 | [ReadyState.CONNECTING]: "🔴", |
| 39 | [ReadyState.OPEN]: '🟢', | 45 | [ReadyState.OPEN]: "🟢", |
| 40 | [ReadyState.CLOSING]: '🔴', | 46 | [ReadyState.CLOSING]: "🔴", |
| 41 | [ReadyState.CLOSED]: '🔴', | 47 | [ReadyState.CLOSED]: "🔴", |
| 42 | } | 48 | }; |
| 43 | 49 | ||
| 44 | const statusTextMap: ReadyStateMap = { | 50 | const statusTextMap: ReadyStateMap = { |
| 45 | [ReadyState.CONNECTING]: 'Connecting...', | 51 | [ReadyState.CONNECTING]: "Connecting...", |
| 46 | [ReadyState.OPEN]: 'Connected', | 52 | [ReadyState.OPEN]: "Connected", |
| 47 | [ReadyState.CLOSING]: 'Closing...', | 53 | [ReadyState.CLOSING]: "Closing...", |
| 48 | [ReadyState.CLOSED]: 'Closed', | 54 | [ReadyState.CLOSED]: "Closed", |
| 49 | } | 55 | }; |
| 50 | 56 | ||
| 51 | export default function App() { | 57 | export default function App() { |
| 52 | const { darkMode, toggle } = useContext(DarkModeContext); | 58 | const { darkMode, toggle } = useContext(DarkModeContext); |
| 53 | const [config, setConfig]= useState<Config | null>(null) | 59 | const [config, setConfig] = useState<Config | null>(null); |
| 54 | 60 | ||
| 55 | const { calls, readyState, clear } = useRequests({ | 61 | const { calls, readyState, clear } = useRequests({ |
| 56 | onConnect: async () => { | 62 | onConnect: async () => { |
| 57 | const response = await fetch(`http://${getHost()}/config/`) | 63 | const response = await fetch(`http://${getHost()}/config/`); |
| 58 | const config = await response.json() | 64 | const config = await response.json(); |
| 59 | setConfig(config) | 65 | setConfig(config); |
| 60 | } | 66 | }, |
| 61 | }); | 67 | }); |
| 62 | 68 | ||
| 63 | useEffect(() => { | 69 | useEffect(() => { |
| 64 | const url = new URL(config?.url ?? 'https://loading...'); | 70 | const url = new URL(config?.url ?? "https://loading..."); |
| 65 | document.title = `${statusIconMap[readyState]} ${url.host} | TTUN`; | 71 | document.title = `${statusIconMap[readyState]} ${url.host} | TTUN`; |
| 66 | }, [readyState, config?.url]) | 72 | }, [readyState, config?.url]); |
| 67 | 73 | ||
| 68 | const [selectedRequestIndex, setSelectedRequestIndex] = useState<number | null>(null); | 74 | const [selectedRequestIndex, setSelectedRequestIndex] = useState< |
| 69 | const selectedRequest = useMemo<RequestResponse | null>(() => ( | 75 | number | null |
| 70 | selectedRequestIndex === null | 76 | >(null); |
| 71 | ? null | 77 | const selectedRequest = useMemo<RequestResponse | null>( |
| 72 | : calls[selectedRequestIndex] | 78 | () => (selectedRequestIndex === null ? null : calls[selectedRequestIndex]), |
| 73 | ), [selectedRequestIndex, calls]); | 79 | [selectedRequestIndex, calls] |
| 80 | ); | ||
| 74 | 81 | ||
| 75 | const settingsMenu: (SettingsMenu | null)[] = [ | 82 | const settingsMenu: (SettingsMenu | null)[] = [ |
| 76 | { | 83 | { |
| 77 | onClick: toggle, | 84 | onClick: toggle, |
| 78 | icon: darkMode ? <Sun />: <Moon />, | 85 | icon: darkMode ? <Sun /> : <Moon />, |
| 79 | label: darkMode ? "Light mode" : "Dark mode", | 86 | label: darkMode ? "Light mode" : "Dark mode", |
| 80 | }, | 87 | }, |
| 81 | null, | 88 | null, |
| @@ -85,40 +92,32 @@ export default function App() { | |||
| 85 | clear(); | 92 | clear(); |
| 86 | }, | 93 | }, |
| 87 | icon: <Trash />, | 94 | icon: <Trash />, |
| 88 | label: "Clear" | 95 | label: "Clear", |
| 89 | } | 96 | }, |
| 90 | ]; | ||
