Refactor variable names

This commit is contained in:
Leonardo Murça 2022-11-18 13:58:10 -03:00
parent 6dc87e3354
commit 9b8b0e71e9

View file

@ -5,16 +5,16 @@
import { filterFileRequirements } from "../utils/filterFileRequirements"; import { filterFileRequirements } from "../utils/filterFileRequirements";
let files; let acceptedFiles;
let filesRendered = false; let rejectedFiles;
let filesRejected; let isAcceptedFilesRendered = false;
const fileRequirements = { const fileRequirements = {
supportedFormats: [".pes"], supportedFormats: [".pes"],
maxSize: 700000, maxSize: 700000,
}; };
const onSubmit = () => { const onSubmit = () => {
filesRendered = true; isAcceptedFilesRendered = true;
}; };
const onDrop = (evt) => { const onDrop = (evt) => {
@ -22,16 +22,16 @@
}; };
const onChange = (evt) => { const onChange = (evt) => {
files = null; acceptedFiles = null;
filesRendered = false; isAcceptedFilesRendered = false;
const changedFiles = evt.dataTransfer const changedFiles = evt.dataTransfer
? evt.dataTransfer.files ? evt.dataTransfer.files
: evt.target.files; : evt.target.files;
const results = filterFileRequirements(changedFiles, fileRequirements); const results = filterFileRequirements(changedFiles, fileRequirements);
files = results.accepted; acceptedFiles = results.accepted;
filesRejected = results.rejected; rejectedFiles = results.rejected;
}; };
const onClick = () => { const onClick = () => {
@ -58,7 +58,7 @@
</p> </p>
<Dropzone <Dropzone
{files} files={acceptedFiles}
supportedFormats={fileRequirements.supportedFormats} supportedFormats={fileRequirements.supportedFormats}
{onKeydown} {onKeydown}
{onClick} {onClick}
@ -69,11 +69,11 @@
<input type="submit" value="Render files" /> <input type="submit" value="Render files" />
</form> </form>
{#if filesRendered} {#if isAcceptedFilesRendered}
<CardList {files} /> <CardList files={acceptedFiles} />
{:else} {:else}
<FileList title="Rejected Files" files={filesRejected} isError /> <FileList title="Rejected Files" files={rejectedFiles} isError />
<FileList title="Selected Files" {files} /> <FileList title="Selected Files" files={rejectedFiles} />
{/if} {/if}
<style> <style>