From 59183e9124ba1cae98b25f3be03583f7acd9972f Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Sun, 16 Feb 2025 11:03:38 +0100 Subject: [PATCH] feat: Launch button debounce + now in cluster sidebar --- apps/frontend/package.json | 1 + .../src/ui/components/LaunchButton.tsx | 49 ++++++++++++++++++ .../src/ui/components/base/Button.tsx | 2 +- apps/frontend/src/ui/pages/Home.tsx | 17 ++----- .../src/ui/pages/cluster/ClusterOverview.tsx | 16 ++---- .../src/ui/pages/cluster/ClusterRoot.tsx | 50 +++++++++++-------- pnpm-lock.yaml | 14 ++++++ 7 files changed, 101 insertions(+), 48 deletions(-) create mode 100644 apps/frontend/src/ui/components/LaunchButton.tsx diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 217363d7..f8bac6b1 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -25,6 +25,7 @@ "@solid-primitives/i18n": "^2.1.1", "@solid-primitives/map": "^0.4.13", "@solid-primitives/refs": "^1.0.8", + "@solid-primitives/scheduled": "^1.5.0", "@solidjs/router": "^0.14.7", "@t3-oss/env-core": "^0.11.0", "@tanstack/solid-query": "^5.56.2", diff --git a/apps/frontend/src/ui/components/LaunchButton.tsx b/apps/frontend/src/ui/components/LaunchButton.tsx new file mode 100644 index 00000000..f8c480b4 --- /dev/null +++ b/apps/frontend/src/ui/components/LaunchButton.tsx @@ -0,0 +1,49 @@ +import type { Cluster } from '@onelauncher/client/bindings'; +import type { ButtonProps } from './base/Button'; +import { debounce } from '@solid-primitives/scheduled'; +import { PlayIcon } from '@untitled-theme/icons-solid'; +import { useLaunchCluster } from '~ui/hooks/useCluster'; +import useProcessor from '~ui/hooks/useProcessor'; +import useSettings from '~ui/hooks/useSettings'; +import { Match, splitProps, Switch } from 'solid-js'; +import Button from './base/Button'; + +function LaunchButton(props: ButtonProps & { cluster: Cluster; iconOnly?: boolean }) { + const [split, rest] = splitProps(props, ['cluster']); + const innerLaunch = useLaunchCluster(() => split.cluster?.uuid); + // eslint-disable-next-line solid/reactivity -- a + const { running: runningProcesses } = useProcessor(split.cluster); + const { settings } = useSettings(); + + const launch = (e: MouseEvent) => { + e.stopImmediatePropagation(); + e.preventDefault(); + debounce(innerLaunch, 300)(); + }; + + return ( + + + + + diff --git a/apps/frontend/src/ui/pages/cluster/ClusterOverview.tsx b/apps/frontend/src/ui/pages/cluster/ClusterOverview.tsx index 82a0a42e..f3585fcd 100644 --- a/apps/frontend/src/ui/pages/cluster/ClusterOverview.tsx +++ b/apps/frontend/src/ui/pages/cluster/ClusterOverview.tsx @@ -2,14 +2,15 @@ import type { Cluster } from '@onelauncher/client/bindings'; import { useNavigate } from '@solidjs/router'; import * as dialog from '@tauri-apps/plugin-dialog'; import { open } from '@tauri-apps/plugin-shell'; -import { Edit02Icon, FolderIcon, ImagePlusIcon, LinkExternal01Icon, PlayIcon, Save01Icon, Share07Icon, Tool02Icon, Trash01Icon } from '@untitled-theme/icons-solid'; +import { Edit02Icon, FolderIcon, ImagePlusIcon, LinkExternal01Icon, Save01Icon, Share07Icon, Tool02Icon, Trash01Icon } from '@untitled-theme/icons-solid'; import { bridge } from '~imports'; import TextField from '~ui/components/base/TextField'; +import LaunchButton from '~ui/components/LaunchButton'; import Modal, { createModal, type ModalProps } from '~ui/components/overlay/Modal'; import ScrollableContainer from '~ui/components/ScrollableContainer'; import SettingsRow from '~ui/components/SettingsRow'; import Sidebar from '~ui/components/Sidebar'; -import useClusterContext, { useLaunchCluster } from '~ui/hooks/useCluster'; +import useClusterContext from '~ui/hooks/useCluster'; import usePreventLeave from '~ui/hooks/usePreventLeave'; import useSettings from '~ui/hooks/useSettings'; import { formatAsDuration, upperFirst } from '~utils'; @@ -264,8 +265,6 @@ interface BannerProps { } function Banner(props: BannerProps) { - const launch = useLaunchCluster(() => props.cluster.uuid); - async function launchFilePicker() { const selected = await dialog.open({ multiple: false, @@ -361,14 +360,7 @@ function Banner(props: BannerProps) { disabled={true} /> -