πŸ“¦ chaokunyang / amanda

πŸ“„ FileService.js Β· 47 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47import React, { Component } from 'react';
import Axios from 'axios'
import './FileService.css'
import Accept from './Accept'

class FileService extends Component {

    constructor(props) {
        super(props);
        this.state = { fileUrls: [] }
        this.getFileList = this.getFileList.bind(this);
    }

    componentDidMount() {
        this.getFileList();
    }

    getFileList() {
        Axios.get('/api/files')
            .then(response => {
                this.setState({fileUrls: response.data})
            })
            .catch(error => {
                console.log(error);
            });
    }

    render() {
        const fileList = this.state.fileUrls.map(fileUrl =>
            <li key={fileUrl}>
                <a href={fileUrl}>{fileUrl}</a>
            </li>
        );
        return (
            <div>
                <h2>ζ–‡δ»ΆζœεŠ‘</h2>
                <Accept getFileList={this.getFileList}/>
                <ul>
                    {fileList}
                </ul>
            </div>
        )
    }

}

export default FileService