-
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.
feat: moved all shared code to Convert component (#25)
- Loading branch information
1 parent
3cae604
commit 58fefb0
Showing
4 changed files
with
86 additions
and
34 deletions.
There are no files selected for viewing
File renamed without changes.
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,57 @@ | ||
import { memo, useCallback, useState } from "react" | ||
import DraggerUpload from "../dragger-upload" | ||
import { Button, UploadFile } from "antd" | ||
import convertFiles from "../../services/converter" | ||
import { Format } from "../../model/format" | ||
import './converter.css' | ||
|
||
/** Properties of Converter */ | ||
type ConverterProps = { | ||
/** Define allowed types to be uploaded */ | ||
allowedUploadingFormats: Format[] | ||
/** Formats available to be converted at */ | ||
optionsToConvertTo: Format[] | ||
} | ||
|
||
function Converter(props: ConverterProps): JSX.Element { | ||
const [fileList, setFileList] = useState<UploadFile[]>([]) | ||
|
||
const onUploadDone = useCallback((files: UploadFile[]) => { | ||
setFileList(files) | ||
}, []) | ||
|
||
const downloadBlob = useCallback((blob: Blob) => { | ||
const url = window.URL.createObjectURL(blob); | ||
const a = document.createElement("a") | ||
document.body.appendChild(a) | ||
a.style.display = "none" | ||
a.href = url; | ||
a.target = "_blank" | ||
a.download = 'test.gif'; | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
}, []) | ||
|
||
const convert = useCallback(async () => { | ||
const blobs = await convertFiles(fileList) | ||
|
||
for (const blob of blobs) { | ||
downloadBlob(blob) | ||
} | ||
}, [downloadBlob, fileList]) | ||
|
||
return ( | ||
<div> | ||
<DraggerUpload | ||
onUploadDone={onUploadDone} /> | ||
<Button | ||
size="large" | ||
type="primary" | ||
className="button-convert" | ||
onClick={convert}>Convert</Button> | ||
</div> | ||
) | ||
} | ||
|
||
|
||
export default memo(Converter) |
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,9 @@ | ||
/** Defines a format */ | ||
export type Format = { | ||
/** Name o the format */ | ||
name: string | ||
/** Extension with a dot */ | ||
extension: string | ||
/** Mime type of this format, that allow it to be downloaded */ | ||
mimeType: string | ||
} |