-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d38bb2
commit ac5dea6
Showing
7 changed files
with
170 additions
and
59 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
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,75 @@ | ||
import { Avatar, Box, CircularProgress, SxProps, Typography, TypographyProps } from "@mui/material"; | ||
import React from "react"; | ||
|
||
interface AvatarWithProgressProps extends React.PropsWithChildren { | ||
value: number; | ||
src?: string; | ||
sx?: SxProps<MMRLTheme>; | ||
alt?: string; | ||
progressTextVariant?: TypographyProps["variant"]; | ||
} | ||
|
||
const AvatarWithProgress = (props: AvatarWithProgressProps) => { | ||
const isActive = React.useMemo(() => props.value > 0, [props.value]); | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
position: "relative", | ||
display: "inline-flex", | ||
borderRadius: "20%", | ||
// overflow: "hidden", | ||
// @ts-ignore | ||
...props.sx["& container"], | ||
}} | ||
> | ||
<Avatar src={props.src} sx={props.sx} alt={props.alt} children={props.children} /> | ||
{isActive && ( | ||
<> | ||
<Box | ||
sx={(theme) => ({ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
backgroundColor: theme.palette.background.paper, | ||
opacity: isActive ? 0.6 : 0, | ||
zIndex: 0, | ||
// @ts-ignore | ||
borderRadius: props.sx.borderRadius, | ||
})} | ||
/> | ||
|
||
<CircularProgress | ||
sx={{ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
margin: "auto", | ||
zIndex: 1, | ||
}} | ||
variant="determinate" | ||
value={props.value} | ||
size={87} | ||
thickness={1.8} | ||
/> | ||
<Typography | ||
sx={{ | ||
position: "absolute", | ||
top: "50%", | ||
left: "50%", | ||
transform: "translate(-50%, -50%)", | ||
zIndex: 2, | ||
}} | ||
variant={props.progressTextVariant || "caption"} | ||
>{`${Math.round(props.value)}%`}</Typography> | ||
</> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export { AvatarWithProgress }; |
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,47 @@ | ||
import React from "react"; | ||
import { useStrings } from "./useStrings"; | ||
import { useConfirm } from "material-ui-confirm"; | ||
import { os } from "@Native/Os"; | ||
import { Download } from "@Native/Download"; | ||
|
||
const useDownloadModule = (): [(url?: string, dest?: string) => void, number] => { | ||
const { strings } = useStrings(); | ||
const konfirm = useConfirm(); | ||
|
||
const [progress, setProgress] = React.useState(0); | ||
|
||
const start = (url?: string, dest?: string) => { | ||
if (!url || !dest) return; | ||
|
||
const dl = new Download(url, dest); | ||
|
||
dl.onChange = (obj) => { | ||
switch (obj.type) { | ||
case "downloading": | ||
setProgress(obj.state); | ||
break; | ||
case "finished": | ||
setProgress(0); | ||
konfirm({ | ||
title: strings("download"), | ||
description: strings("file_downloaded", { path: dest }), | ||
}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
|
||
break; | ||
} | ||
}; | ||
|
||
dl.onError = (err) => { | ||
setProgress(0); | ||
os.toast(err, Toast.LENGTH_SHORT); | ||
}; | ||
|
||
dl.start(); | ||
}; | ||
|
||
return [start, progress]; | ||
}; | ||
|
||
export { useDownloadModule }; |
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