Skip to content

Commit

Permalink
[add] Downloader component & page
Browse files Browse the repository at this point in the history
[optimize] async load pages
  • Loading branch information
TechQuery committed Jun 15, 2024
1 parent cf4478c commit 3b4a716
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 146 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"url": "https://github.com/EasyWebApp/WebCell-dashboard/issues"
},
"dependencies": {
"boot-cell": "^2.0.0-beta.26",
"boot-cell": "^2.0.0-beta.27",
"browser-unhandled-rejection": "^1.0.2",
"cell-router": "^3.0.0-rc.7",
"classnames": "^2.5.1",
"dom-renderer": "^2.1.7",
"dom-renderer": "^2.1.8",
"echarts-jsx": "^1.2.0",
"koajax": "^1.1.2",
"mobx": "^6.12.4",
"mobx-restful": "1.0.0-rc.5",
"web-cell": "^3.0.0-rc.16",
"web-utility": "^4.4.0"
},
Expand Down Expand Up @@ -65,7 +66,7 @@
"prepare": "husky",
"test": "lint-staged",
"clean": "rm -rf .parcel-cache/ dist/",
"start": "npm run clean && parcel src/index.html --open",
"start": "npm run clean && parcel src/index.html",
"pack": "npm run clean && parcel build src/index.html --public-url .",
"build": "npm run pack && workbox generateSW"
}
Expand Down
371 changes: 234 additions & 137 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions src/component/Downloader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { FC, observer } from 'web-cell';
import {
Button,
Card,
CardBody,
CardFooter,
CardTitle,
Icon,
ProgressBar
} from 'boot-cell';
import { DownloadTask } from 'mobx-restful';

import { downloader } from '../model';

export const DTCard: FC<{ task: DownloadTask }> = observer(({ task }) => (
<Card>
<CardBody>
<CardTitle>{task.name}</CardTitle>
<ProgressBar
striped={task.percent < 100}
animated={task.executing}
now={task.percent}
label
/>
</CardBody>
<CardFooter className="d-flex justify-content-between align-items-center">
<small>
{task.loadedSize.toShortString()} /{' '}
{task.totalSize.toShortString()}
</small>
<div className="d-flex gap-3">
{task.percent < 100 &&
(task.executing ? (
<Button
size="sm"
variant="warning"
onClick={() => task.pause()}
>
<Icon name="pause" />
</Button>
) : (
<Button
size="sm"
variant="success"
onClick={() => task.start()}
>
<Icon name="play" />
</Button>
))}
<Button
size="sm"
variant="danger"
disabled={task.executing}
onClick={() => downloader.destroyTask(task.name)}
>
<Icon name="trash" />
</Button>
</div>
</CardFooter>
</Card>
));

export const Downloader: FC = observer(() => (
<ol className="list-unstyled d-flex flex-column gap-3">
{downloader.tasks.map(task => (
<li key={task.id}>
<DTCard task={task} />
</li>
))}
</ol>
));
4 changes: 4 additions & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Downloader } from 'mobx-restful';

import { ContentModel } from './Content';

export * from './Content';
Expand All @@ -6,3 +8,5 @@ export const content = new ContentModel({
owner: 'EasyWebApp',
repo: 'WebCell-dashboard'
});

export const downloader = new Downloader();
2 changes: 1 addition & 1 deletion src/page/DashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import menu from './menu.json';

@component({ tagName: 'dash-board' })
@observer
export class DashBoard extends HTMLElement {
export default class DashBoard extends HTMLElement {
connectedCallback() {
content.getPaths();
}
Expand Down
46 changes: 46 additions & 0 deletions src/page/Downloader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Button, FloatingLabel, FormControl } from 'boot-cell';
import { formToJSON } from 'web-utility';

import { Downloader } from '../component/Downloader';
import { PageFrame } from '../component/PageFrame';
import { downloader } from '../model';
import menu from './menu.json';

const addTask = async (event: SubmitEvent) => {
event.preventDefault();

const form = event.currentTarget as HTMLFormElement;
const { path } = formToJSON(form);

await downloader
.createTask(path as string)
.start({ chunkSize: 1024 ** 2 / 2 });

form.reset();
};

export default () => (
<PageFrame menu={menu}>
<h1 className="my-4">Downloader</h1>

<form
className="d-flex align-items-center gap-3 mb-3"
onSubmit={addTask}
>
<FloatingLabel className="flex-fill" label="URL">
<FormControl
placeholder="URL"
type="url"
name="path"
required
/>
</FloatingLabel>

<Button type="submit" variant="primary">
+
</Button>
</form>

<Downloader />
</PageFrame>
);
8 changes: 6 additions & 2 deletions src/page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { createRouter } from 'cell-router';
import { FC } from 'web-cell';
import { FC, lazy } from 'web-cell';

import { DashBoard } from './DashBoard';
import { SignInPage } from './SignIn';

const DashBoard = lazy(() => import('./DashBoard')),
DownloaderPage = lazy(() => import('./Downloader'));

const { Route } = createRouter();

export const PageFrame: FC = () => (
<div>
<Route path="" component={SignInPage} />
<Route path="admin" component={DashBoard} />
<Route path="admin/dashboard" component={DashBoard} />
<Route path="admin/downloader" component={DownloaderPage} />
</div>
);
4 changes: 2 additions & 2 deletions src/page/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"icon": "house"
},
{
"title": "Orders",
"href": "admin/order",
"title": "Downloader",
"href": "admin/downloader",
"icon": "file-earmark"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true,
Expand Down

1 comment on commit 3b4a716

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for web-cell-dashboard ready!

✅ Preview
https://web-cell-dashboard-oa75ti2pa-techquerys-projects.vercel.app

Built with commit 3b4a716.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.