aboutsummaryrefslogtreecommitdiff
path: root/src/Home.js
blob: bda02e684178b3f7d8628d3de61a0851c8543cec (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { Component } from "react";
import { List, Header, Segment, Icon, Loader } from "semantic-ui-react";
import Moment from "react-moment";
import "moment/locale/es";

import { Link } from "@reach/router";

class Home extends Component {
    constructor() {
        super();
        this.state = {
            lastAgeThreads: [],
            newThreadsList: [],
            latestNews: [],
            isLoaded: false
        }
    }

    componentDidMount() {
        fetch("https://bienvenidoainternet.org/cgi/api/lastage?limit=10")
            .then((response) => { return response.json() })
            .then((resource) => {
                this.setState({
                    lastAgeThreads: resource["threads"]
                })
            });

        fetch("https://bienvenidoainternet.org/cgi/api/newThreads?limit=10")
            .then((response) => { return response.json() })
            .then((resource) => {
                this.setState({
                    newThreadsList: resource["threads"],
                });
            });

        fetch("https://bienvenidoainternet.org/cgi/api/blotter")
            .then((response) => { return response.json() })
            .then((resource) => {
                this.setState({
                    latestNews: resource["news"],
                    isLoaded: true
                });
            });
    }

    render() {
        if (!this.state.isLoaded) {
            return (
                <Loader active centered="true" >
                    Cargando ...
                </Loader>
            )
        }

        const { newThreadsList, lastAgeThreads, latestNews } = this.state;

        return (
            <Segment.Group>
                <Segment.Group horizontal>

                    <Segment>
                        <Header as="h4">Hilos activos</Header>
                        <List divided>
                            {lastAgeThreads.map(thread =>
                                <List.Item key={thread.id}>
                                    <List.Icon name='comment alternate outline' size='large' verticalAlign='middle' />
                                    <List.Content>
                                        <List.Header as={Link} to={`${thread.dir}/read/${thread.id}`}>{thread.content}</List.Header>
                                        <List.Description as='a'><Icon name="folder open outline" /> {thread.board_fulln} ― <Icon name="clock" /><Moment fromNow unix locale="es" date={thread.last} /></List.Description>
                                    </List.Content>
                                </List.Item>
                            )}
                        </List>
                    </Segment>

                    <Segment>
                        <Header as="h4">Nuevos hilos</Header>
                        <List divided>
                            {newThreadsList.map(thread =>
                                <List.Item key={thread.id}>
                                    <List.Icon name='comment alternate outline' size='large' verticalAlign='middle' />
                                    <List.Content>
                                        <List.Header as={Link} to={`${thread.dir}/read/${thread.id}`}>{thread.content}</List.Header>
                                        <List.Description as='a'><Icon name="folder open outline" /> {thread.board_fulln} ― <Icon name="clock" /><Moment fromNow unix locale="es" date={thread.timestamp} /></List.Description>
                                    </List.Content>
                                </List.Item>
                            )}
                        </List>
                    </Segment>

                </Segment.Group>
                <Segment>
                    <Header as="h4">Blotter</Header>
                    <List divided>
                        {latestNews.map(n =>
                            <List.Item key={n.timestamp}>
                                <List.Content>
                                    <div dangerouslySetInnerHTML={{ __html: n.message }} />
                                    <span className="ui tiny"><Icon name="clock" /><Moment fromNow unix locale="es" date={n.timestamp} /></span>

                                </List.Content>
                            </List.Item>
                        )}
                    </List>
                </Segment>

            </Segment.Group>
        );
    }
}

export default Home;