Skip to content

Commit

Permalink
feat: allow to trigger compilation from dashboard (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
zamotany authored Oct 1, 2021
1 parent 94fb5d1 commit ebc787b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
36 changes: 32 additions & 4 deletions packages/dashboard/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<button
disabled={disabled}
className={cx(
'px-2 py-1 flex flex-row items-center rounded-sm hover:bg-gray-600 text-gray-300 hover:text-gray-200 border-2 border-gray-600 transition ease-in duration-100',
'px-2 py-1 rounded-sm border-2 transition ease-in duration-100 relative',
disabled
? 'cursor-not-allowed text-gray-500 border-gray-700'
: 'text-gray-300 border-gray-600 hover:text-gray-200 hover:bg-gray-600',
className
)}
onClick={onClick}
onClick={React.useCallback(() => {
!disabled && onClick?.();
}, [disabled, onClick])}
>
{children}
<div
className={cx('flex flex-row items-center', progress && 'invisible')}
>
{children}
</div>
<div
className={cx(
'absolute top-0 bottom-0 left-0 right-0 flex flex-row items-center justify-center',
!progress && 'hidden'
)}
>
<span className="material-icons animate-spin text-gray-300">
autorenew
</span>
</div>
</button>
);
}
52 changes: 52 additions & 0 deletions packages/dashboard/src/pages/Dash/CompilationTrigger.tsx
Original file line number Diff line number Diff line change
@@ -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<string>('');
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 (
<div className="flex flex-col items-start px-6 py-2">
<h2 className="text-gray-300 font-medium text-2xl uppercase mb-2">
TRIGGER COMPILATION
</h2>
<div className="bg-dark-200 p-6 rounded border-2 border-dark-100 text-gray-300 flex flex-col">
<div className="text-gray-400 text-sm">
Use to trigger a new compilation for provided platform without.
</div>
<div className="mt-3 flex flex-row">
<input
className={cx(
'mr-2 bg-transparent border-2 rounded-sm border-gray-600 px-4 py-2 text-gray-200 focus:outline-none focus:border-gray-400',
loading && 'cursor-not-allowed text-gray-500'
)}
placeholder="Platform name..."
value={platform}
onChange={React.useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setPlatform(event.target.value);
},
[]
)}
disabled={loading}
/>
<Button onClick={trigger} disabled={!platform} progress={loading}>
Send<span className="ml-1 material-icons">input</span>
</Button>
</div>
</div>
</div>
);
}
4 changes: 3 additions & 1 deletion packages/dashboard/src/pages/Dash/Dash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -11,7 +12,8 @@ export function Dash() {

return (
<PageLayout title="Dash">
<div className="flex flex-row flex-wrap">
<CompilationTrigger />
<div className="mt-8 flex flex-row flex-wrap">
{!platforms.length ? (
<Admonition type="info" className="mt-2">
There are no compilations yet. Start Re.Pack development server and
Expand Down

0 comments on commit ebc787b

Please sign in to comment.