generated from EasyWebApp/WebCell-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[optimize] async load pages
- Loading branch information
Showing
9 changed files
with
369 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3b4a716
There was a problem hiding this comment.
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