From ebc787bc51057d244f71d7dde3acd9878beb3d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Trys=C5=82a?= Date: Fri, 1 Oct 2021 20:45:09 +0200 Subject: [PATCH] feat: allow to trigger compilation from dashboard (#103) --- packages/dashboard/src/components/Button.tsx | 36 +++++++++++-- .../src/pages/Dash/CompilationTrigger.tsx | 52 +++++++++++++++++++ packages/dashboard/src/pages/Dash/Dash.tsx | 4 +- 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 packages/dashboard/src/pages/Dash/CompilationTrigger.tsx diff --git a/packages/dashboard/src/components/Button.tsx b/packages/dashboard/src/components/Button.tsx index 1dbf3773e..7c3fa04d3 100644 --- a/packages/dashboard/src/components/Button.tsx +++ b/packages/dashboard/src/components/Button.tsx @@ -3,20 +3,48 @@ import cx from 'classnames'; interface Props { onClick?: () => void; + disabled?: boolean; + progress?: boolean; children: React.ReactNode; className?: string; } -export function Button({ children, onClick, className }: Props) { +export function Button({ + children, + onClick, + className, + disabled, + progress, +}: Props) { return ( ); } diff --git a/packages/dashboard/src/pages/Dash/CompilationTrigger.tsx b/packages/dashboard/src/pages/Dash/CompilationTrigger.tsx new file mode 100644 index 000000000..4725a3f8e --- /dev/null +++ b/packages/dashboard/src/pages/Dash/CompilationTrigger.tsx @@ -0,0 +1,52 @@ +import * as React from 'react'; +import cx from 'classnames'; +import { Button } from '../../components/Button'; +import { DEV_SERVER_HTTP_URL } from '../../constants'; + +export function CompilationTrigger() { + const [platform, setPlatform] = React.useState(''); + const [loading, setLoading] = React.useState(false); + + const trigger = React.useCallback(async () => { + setLoading(true); + try { + await fetch(`${DEV_SERVER_HTTP_URL}/index.bundle?platform=${platform}`); + setPlatform(''); + } finally { + setLoading(false); + } + }, [platform]); + + return ( +
+

+ TRIGGER COMPILATION +

+
+
+ Use to trigger a new compilation for provided platform without. +
+
+ ) => { + setPlatform(event.target.value); + }, + [] + )} + disabled={loading} + /> + +
+
+
+ ); +} diff --git a/packages/dashboard/src/pages/Dash/Dash.tsx b/packages/dashboard/src/pages/Dash/Dash.tsx index ff0de9ace..477e45f08 100644 --- a/packages/dashboard/src/pages/Dash/Dash.tsx +++ b/packages/dashboard/src/pages/Dash/Dash.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { Admonition } from '../../components/Admonition'; import { PageLayout } from '../../components/PageLayout'; import { useDevServer } from '../../hooks/useDevServer'; +import { CompilationTrigger } from './CompilationTrigger'; import { PlatformCompilation } from './PlatformCompilation'; import { PlatformDash } from './PlatformDash'; @@ -11,7 +12,8 @@ export function Dash() { return ( -
+ +
{!platforms.length ? ( There are no compilations yet. Start Re.Pack development server and