Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FileInput component #343

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1c6caff
Create FileInput.js
fung-csf Aug 1, 2021
1fa3116
Update index.ts
fung-csf Aug 1, 2021
cec3965
Update FileInput.js
fung-csf Aug 24, 2021
fd76bb6
Update Dependencies
fung-csf Aug 24, 2021
633b862
Update index.ts
fung-csf Aug 24, 2021
686e508
Add files via upload
jytan9898u Aug 24, 2021
7e64a03
Update FileInput.js
fung-csf Aug 24, 2021
32060c8
Update react-component-ci.yml
fung-csf Aug 27, 2021
c81cb81
Update index.ts
fung-csf Aug 27, 2021
7482723
Update react-component-ci.yml
fung-csf Aug 27, 2021
b8d1faf
Update react-component-ci.yml
fung-csf Aug 27, 2021
8062d66
Update index.ts
fung-csf Aug 27, 2021
e959f30
Update react-component-ci.yml
fung-csf Aug 27, 2021
5f5ce80
Delete FileInput.js
fung-csf Aug 28, 2021
f74741f
Create FileInput.tsx
fung-csf Aug 28, 2021
6dce9c2
Update index.ts
fung-csf Aug 28, 2021
c407423
Update FileInput.tsx
fung-csf Aug 28, 2021
6396368
Update FileInput.tsx
fung-csf Aug 28, 2021
9cc9cb4
Update FileInput.tsx
fung-csf Aug 28, 2021
cdd11eb
Update index.ts
fung-csf Aug 28, 2021
77a354b
Rename UploadAlt.js to UploadAlt.tsx
jytan9898u Aug 28, 2021
9fb3465
Update UploadAlt.tsx
jytan9898u Aug 28, 2021
7f5080d
Merge pull request #1 from jytan9898u/tanjingyu
jytan9898u Aug 28, 2021
8bafddb
Merge pull request #3 from fung-csf/ChowSengFung
fung-csf Aug 28, 2021
77ccbb1
Update .eslintrc.js
fung-csf Aug 28, 2021
3f26eae
Update .eslintrc.js
fung-csf Aug 28, 2021
bc17a1a
Update .eslintrc.js
fung-csf Aug 28, 2021
40c0a90
Update .eslintrc.js
fung-csf Aug 28, 2021
3c9a782
Update .eslintrc.js
fung-csf Aug 28, 2021
8b21853
Merge branch 'fung-csf:master' into master
jytan9898u Aug 28, 2021
4931035
Update index.ts
jytan9898u Aug 28, 2021
e4c6a2a
Update UploadAlt.tsx
jytan9898u Aug 28, 2021
9340863
Merge pull request #5 from jytan9898u/TanJingYu
fung-csf Aug 28, 2021
2c8efa1
Update UploadAlt
jackisgood13 Aug 28, 2021
1a58698
Merge pull request #8 from jackisgood13/jackisgood13
fung-csf Aug 28, 2021
f6872e7
Added confirmation box
eshan25 Aug 28, 2021
3cde813
Merge pull request #9 from eshan25/eshan
fung-csf Aug 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ module.exports = {
"import/no-named-as-default": 0,
"import/no-extraneous-dependencies": 0,
"no-underscore-dangle": 0,
"@typescript-eslint/no-shadow": 0,
"no-shadow": 0,
},

};
6 changes: 4 additions & 2 deletions .github/workflows/react-component-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master,ChowSengFung ]
paths-ignore:
- './src/FileInput.js'
pull_request:
branches: [ master ]
branches: [ master,ChowSengFung ]

jobs:
setup:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@umijs/fabric": "^2.0.0",
"antd": "^4.16.13",
"axios": "^0.20.0",
"co-busboy": "^1.3.0",
"coveralls": "^3.0.3",
Expand Down
47 changes: 47 additions & 0 deletions src/FileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from "react";

function FileInput({ value, FileContent, ...rest }) {
const [filePresent, setFilePresent] = useState(false);
const [Files, setFiles] = useState([]);

function noop(filePresent) {
setFilePresent(true);
}

return (
<div>
<label
className="wrapper"
style={{
width: "50px",
background: "#fff",
padding: "30px",

boxShadow:
"0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)"
}}
>
Click to here to select file for upload...
<input
{...rest}
style={{ display: "none" }}
type="file"
onChange={(e) => {
setFiles([...e.target.files]);
FileContent(e.target.files);

setFilePresent(true);
}}
/>
</label>

{Boolean(filePresent) && (
<div style={{ marginTop: "40px", marginBottom: "10px" }}>
Selected files: {Files.map((f) => f.name).join(", ")}
</div>
)}
</div>
);
}

export default FileInput;
83 changes: 83 additions & 0 deletions src/UploadAlt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { useState, useEffect } from "react";
import "antd/dist/antd.css";
import axios from "axios";
import { Card, Button, Modal } from "antd";
import FileInput from './FileInput'


function UploadAlt() {

const [fileData, setfileData] = useState();
const [isModalVisible, setIsModalVisible] = useState(false);
const [fileDataContent, setfileDataContent] = useState(" ");

function fileContent(file) {
setfileData(file[0]);
// console.log(file[0]);
}

const showModal = () => {
setIsModalVisible(true);
};

const handleCancel = () => {
setIsModalVisible(false);
};

const handleSubmit = (e) => {
const fr = new FileReader();
fr.onload = function (e) {
// e.target.result should contain the text
const text = e.target.result;
setfileDataContent(text);
console.log(fileDataContent);
};

fr.readAsText(fileData);
axios({
method: "post",
url: "",
// database table with the columns Name, content
data: [{ Name: fileData.name, content: fileDataContent }]
})
.then(function (response) {
// handle success
console.log(response.data);
})
.catch(function (error) {
// handle error
console.log(error);
});
};

return (
<div>
<Card
style={{
paddingTop: "40px",
width: 386,
paddingBottom: "20px",
marginBottom: "20px"
}}>
<FileInput fileContent={fileContent} />
<Button type="primary" onClick={showModal} style={{marginTop: "50px"}}>
Upload
</Button>
<Modal
title="Confirmation"
visible={isModalVisible}
onOk={handleSubmit}
onCancel={handleCancel}>
style={{
overflow: 'auto',
borderRadius: '10px',
backgroundColor: '#1890ff',
}}
<p>Are you sure to upload the following file?</p>
{fileData && <p>File: {fileData.name}</p>}
</Modal>
</Card>
</div>
);
}
export default UploadAlt;
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Upload from './Upload';
import { UploadProps } from './interface';
import FileInput from './FileInput';
import UploadAlt from './UploadAlt';

export { UploadProps };
export { UploadProps,FileInput, UploadAlt };

export default Upload;