-
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.
- Loading branch information
Showing
13 changed files
with
160 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.container, .textContainer { | ||
width: var(--sizes-100); | ||
height: var(--sizes-100); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
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,40 @@ | ||
import React from "react"; | ||
import { | ||
DropEvent, | ||
useDropzone, | ||
FileRejection, | ||
DropzoneOptions, | ||
DropzoneState, | ||
} from "react-dropzone"; | ||
import styles from "./DropZone.module.css"; | ||
import clsx from "clsx"; | ||
|
||
export type OnUpload = <T extends File>( | ||
acceptedFiles: T[], | ||
fileRejections: FileRejection[], | ||
event: DropEvent | ||
) => void; | ||
|
||
type Props = { | ||
children: (state: DropzoneState) => string | React.ReactElement; | ||
options?: DropzoneOptions; | ||
className?: string; | ||
}; | ||
|
||
export const DropZone: React.VFC<Props> = ({ | ||
options, | ||
children, | ||
className, | ||
}) => { | ||
const dropZoneState = useDropzone({ | ||
...options, | ||
}); | ||
const { getRootProps, getInputProps } = dropZoneState; | ||
|
||
return ( | ||
<div {...getRootProps()} className={clsx(styles.container, className)}> | ||
<input {...getInputProps()} /> | ||
<div className={styles.textContainer}>{children(dropZoneState)}</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./DropZone"; |
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,8 +1,32 @@ | ||
.container, .textContainer { | ||
.container { | ||
width: var(--sizes-100); | ||
height: var(--sizes-100); | ||
height: 150px; | ||
cursor: copy; | ||
padding: var(--spacings-s); | ||
border: var(--borders-strong); | ||
display: flex; | ||
align-items: center; | ||
font-weight: var(--font-weights-bold); | ||
border-radius: var(--radii-s); | ||
justify-content: center; | ||
border-color: var(--colors-gray-lightest); | ||
transition: var(--transitions-fast); | ||
} | ||
|
||
.container.loading { | ||
cursor: unset; | ||
} | ||
|
||
.container.loading:hover { | ||
box-shadow: unset; | ||
} | ||
|
||
.container:hover { | ||
box-shadow: var(--shadows-medium); | ||
} | ||
|
||
@media screen and (max-width: 768px) { | ||
.container { | ||
padding: var(--spacings-s); | ||
} | ||
} |
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,40 +1,79 @@ | ||
import React from "react"; | ||
import { | ||
DropEvent, | ||
useDropzone, | ||
FileRejection, | ||
DropzoneOptions, | ||
DropzoneState, | ||
} from "react-dropzone"; | ||
import styles from "./FileUploader.module.css"; | ||
import React, { useCallback } from "react"; | ||
import Loader from "react-spinners/PacmanLoader"; | ||
import clsx from "clsx"; | ||
|
||
export type OnUpload = <T extends File>( | ||
acceptedFiles: T[], | ||
fileRejections: FileRejection[], | ||
event: DropEvent | ||
) => void; | ||
import { ProjectInfo } from "../../types/projects"; | ||
import { acceptedFileConfigs } from "../../utils/config"; | ||
import { DropZone, OnUpload } from "./DropZone"; | ||
import styles from "./FileUploader.module.css"; | ||
|
||
type Props = { | ||
children: (state: DropzoneState) => string | React.ReactElement; | ||
options?: DropzoneOptions; | ||
className?: string; | ||
onUpload: (fundingLinks?: ProjectInfo[]) => void; | ||
isLoading?: boolean; | ||
setIsLoading: (isLoading: boolean) => void; | ||
}; | ||
|
||
function getAcceptedFileExtensions() { | ||
return acceptedFileConfigs.map(({ extension }) => extension); | ||
} | ||
|
||
export const FileUploader: React.VFC<Props> = ({ | ||
options, | ||
children, | ||
className, | ||
onUpload, | ||
isLoading, | ||
setIsLoading, | ||
}) => { | ||
const dropZoneState = useDropzone({ | ||
...options, | ||
}); | ||
const { getRootProps, getInputProps } = dropZoneState; | ||
const onDrop: OnUpload = useCallback( | ||
async (acceptedFiles) => { | ||
setIsLoading(true); | ||
try { | ||
const formData = new FormData(); | ||
|
||
acceptedFiles.forEach((file) => { | ||
formData.append("file", file); | ||
}); | ||
|
||
const response = await fetch("/api/get-grouped-funding-links", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
|
||
const groupedFundingLinks = await response.json(); | ||
|
||
onUpload(groupedFundingLinks || []); | ||
} catch (e) { | ||
onUpload([]); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, | ||
[onUpload, setIsLoading] | ||
); | ||
|
||
const renderText = useCallback( | ||
({ isDragActive }) => { | ||
if (isLoading) { | ||
return <Loader size={24} color="var(--colors-gray-light)" />; | ||
} | ||
|
||
if (isDragActive) { | ||
return "Drop your package.json here ..."; | ||
} | ||
|
||
return "Drag 'n' drop your package.json, or click to select it from your computer"; | ||
}, | ||
[isLoading] | ||
); | ||
|
||
return ( | ||
<div {...getRootProps()} className={clsx(styles.container, className)}> | ||
<input {...getInputProps()} /> | ||
<div className={styles.textContainer}>{children(dropZoneState)}</div> | ||
</div> | ||
<DropZone | ||
className={clsx(styles.container, isLoading && styles.loading)} | ||
options={{ | ||
onDrop, | ||
accept: getAcceptedFileExtensions(), | ||
multiple: false, | ||
disabled: isLoading, | ||
}} | ||
> | ||
{renderText} | ||
</DropZone> | ||
); | ||
}; |
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
32 changes: 0 additions & 32 deletions
32
components/PackageJsonUploader/PackageJsonUploader.module.css
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export type DependenciesFileConfig = { | ||
name: string; | ||
name: RegExp; | ||
extension: string; | ||
mimetype: string; | ||
platform: string; | ||
}; |
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