From d074381bd0f86e1aff171c1c8019a08132c5aa05 Mon Sep 17 00:00:00 2001 From: ItsNotGoodName Date: Sun, 12 Mar 2023 12:24:01 -0700 Subject: [PATCH] feat: toggle dropdown on unfocus and click --- http/http.go | 5 ++- web/.gitignore | 24 ++++++++++- web/src/App.tsx | 104 ++++++++++++++++++++++++++++++----------------- web/src/utils.ts | 48 +++++++++++++++------- 4 files changed, 127 insertions(+), 54 deletions(-) diff --git a/http/http.go b/http/http.go index 0110436..a391b2a 100644 --- a/http/http.go +++ b/http/http.go @@ -33,7 +33,10 @@ func Start(a API, port int, fs fs.FS) { e.HideBanner = true e.HidePort = true - e.Use(middleware.Logger()) + e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Format: "[${time_rfc3339}] ${status} ${method} ${path} (${remote_ip}) ${latency_human}\n", + Output: e.Logger.Output(), + })) e.Use(middleware.Recover()) e.Use(middleware.CORS()) diff --git a/web/.gitignore b/web/.gitignore index 76add87..a547bf3 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -1,2 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + node_modules -dist \ No newline at end of file +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/web/src/App.tsx b/web/src/App.tsx index 48512dd..151c8f2 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -20,7 +20,6 @@ import { createEffect, on, Show, - type ParentComponent, type JSX, splitProps, batch, @@ -36,7 +35,7 @@ import { useRefreshRadioVolume, useRefreshRadioSubscription, } from "./store"; -import { clickOutside, type ClassProps, mergeClass } from "./utils"; +import { type ClassProps, mergeClass, useDropdown, IOS } from "./utils"; import { useWS } from "./ws"; import { DaisyButton, @@ -46,9 +45,6 @@ import { DaisyDropdownButton, } from "./Daisy"; -// Prevent TypeScript from removing clickOutside directive -false && clickOutside; - const DiscoverButton: Component< { discovering: boolean; classButton?: string } & ClassProps > = (props) => { @@ -186,17 +182,20 @@ const RadioPlayerTitleDropdown: Component< ), }, ]; + const { showDropdown, toggleDropdown } = useDropdown(); return (
<> @@ -209,7 +208,7 @@ const RadioPlayerTitleDropdown: Component<
@@ -232,15 +231,24 @@ const RadioTypeDropdown: Component< { key: "Model Number", value: props.state.model_number }, ]; + const { showDropdown, toggleDropdown } = useDropdown(); + return ( -
- +
+
@@ -441,12 +449,19 @@ const RadioAudioSourceDropdown: Component< }); }; + const { showDropdown, toggleDropdown } = useDropdown(); + return ( -
+
@@ -543,10 +558,10 @@ const App: Component = () => { loading={loading()} />
-
+
-
+
@@ -570,33 +585,46 @@ const App: Component = () => {
-
-
- - +
+
+
+ + +
+ + +
- - - - - +
+ + + + +
diff --git a/web/src/utils.ts b/web/src/utils.ts index 4e12880..7d4f879 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -5,7 +5,6 @@ import { createEffect, on, type Signal, - onCleanup, } from "solid-js"; export function createStaleSignal(value: T): Signal { @@ -51,21 +50,42 @@ export function mergeClass(first: string, second?: string) { return first; } -export function clickOutside(el: HTMLInputElement) { - const onClick = (e: MouseEvent) => { - !el.contains(e.target as Node) && el.blur(); +export function useDropdown() { + const [show, setShow] = createSignal(false); + const toggleShow = ( + e: Event & { + currentTarget: HTMLElement; + target: Element; + } + ) => { + if (e.type == "focusout") { + setShow(false); + return; + } + + if (!show()) { + setShow(true); + } else { + setShow(false); + e.currentTarget.blur(); + } }; - document.body.addEventListener("click", onClick); - onCleanup(() => document.body.removeEventListener("click", onClick)); + return { showDropdown: show, toggleDropdown: toggleShow }; } -declare module "solid-js" { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace JSX { - interface Directives { - // use:clickOutside - clickOutside: string; - } - } +// https://stackoverflow.com/a/9039885 +export function IOS() { + return ( + [ + "iPad Simulator", + "iPhone Simulator", + "iPod Simulator", + "iPad", + "iPhone", + "iPod", + ].includes(navigator.platform) || + // iPad on iOS 13 detection + (navigator.userAgent.includes("Mac") && "ontouchend" in document) + ); }