aboutsummaryrefslogtreecommitdiff
path: root/src/App.js
blob: 1f4daa456edb8fd2e0e724641eb41caff524903f (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React, { Component } from "react";
import { render } from "react-dom";
import { Router, Link } from "@reach/router";
import "fomantic-ui-css/semantic.css";
import "./App.css";
import wtfpl from "./wtfpl.png";

import {
  Dropdown,
  Menu,
  Icon,
  Loader,
  Container,
  Segment
} from "semantic-ui-react";
import Home from "./Home";
import Thread from "./Thread";
import Board from "./Board";
import NotFound from "./NotFound";
import ThreadList from "./ThreadList";
import FAQ from "./FAQ";
import ChangeLogPage from "./ChangelogPage";
import SettingsModal from "./Settings";
import NewThread from "./NewThread";

class App extends Component {
  constructor() {
    super();
    this.state = {
      boardList: [],
      isLoaded: false,
      nightMode: false
    };
    this.updateTheme = this.updateTheme.bind(this);
  }

  componentDidMount() {
    fetch("https://bienvenidoainternet.org/cgi/api/boardsExtra")
      .then(response => {
        return response.json();
      })
      .then(resource => {
        let polka = {
          allow_image_replies: 1,
          allow_images: 1,
          board_type: 1,
          dir: "polka",
          maxsize: 500,
          name: "Testing field",
          postarea_desc: "",
          disable_name: 0,
          disable_subject: 0,
          allow_spoilers: 0
        };
        if (localStorage.getItem("thereisnourflevel") === null) {
          polka = {};
        }
        this.setState({
          boardList: resource["boards"].concat(polka),
          isLoaded: true
        });
      });

    let lsSettings = localStorage.getItem("settings");
    let settings = JSON.parse(lsSettings);

    if (lsSettings === null) {
      let defaultSettings = {
        homeSound: "msn",
        threadSound: "msn",
        nightMode: false,
        notifyOnHome: true,
        notifyOnThread: true,
        autoUpdateThreads: true,
        showAvatars: true,
        postPassword: this.genPassword()
      };
      localStorage.setItem("settings", JSON.stringify(defaultSettings));
      settings = defaultSettings;
    } else {
      this.setState({ nightMode: settings.nightMode });
    }
  }

  updateTheme(mode) {
    this.setState({ nightMode: mode });
  }

  genPassword() {
    let pass = "";
    for (let i = 0; i < 10; i++) {
      let x = Math.round(Math.random() * 2);
      switch (x) {
        case 0:
          pass += String.fromCharCode(48 + Math.round(Math.random() * 9));
          break;
        case 1:
          pass += String.fromCharCode(65 + Math.round(Math.random() * 25));
          break;
        case 2:
          pass += String.fromCharCode(97 + Math.round(Math.random() * 25));
          break;
      }
    }
    return pass;
  }

  componentDidUpdate() {
    if (this.state.nightMode) {
      document.body.style.backgroundColor = "#313233";
    } else {
      document.body.style.backgroundColor = "#FFFFFF";
    }
  }

  render() {
    const { boardList, nightMode, isLoaded } = this.state;

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

    return (
      <React.Fragment>
        <Menu inverted fixed="top">
          <Container>
            <Menu.Item header>B.a.I</Menu.Item>
            <Menu.Item as={Link} to="/">
              <Icon name="home" /> Home
            </Menu.Item>
            <Dropdown text="Boards" className="link item">
              <Dropdown.Menu>
                <Dropdown.Header>Bolletin Board System</Dropdown.Header>
                {boardList.map(board =>
                  board.board_type === 1 ? (
                    <Dropdown.Item
                      key={board.dir}
                      as={Link}
                      to={`/board/${board.dir}`}
                    >
                      /{board.dir}/ - {board.name}
                    </Dropdown.Item>
                  ) : null
                )}
                <Dropdown.Header>Imageboard</Dropdown.Header>
                {boardList.map(board =>
                  board.board_type === 0 ? (
                    <Dropdown.Item
                      key={board.dir}
                      as={Link}
                      to={`/board/${board.dir}`}
                    >
                      /{board.dir}/ - {board.name}
                    </Dropdown.Item>
                  ) : null
                )}
              </Dropdown.Menu>
            </Dropdown>
            <Menu.Item as={Link} to="/faq">
              <Icon name="help" /> FAQ
            </Menu.Item>
            <Menu.Menu position="right">
              <SettingsModal
                trigger={
                  <Menu.Item as="a">
                    <Icon name="configure" />
                  </Menu.Item>
                }
                handler={this.updateTheme}
              />
            </Menu.Menu>
          </Container>
        </Menu>
        <Container className="main">
          <Router>
            <Home boardList={boardList} path="/" nightMode={nightMode} />
            <Thread
              boardList={boardList}
              path="/:dir/read/:id"
              nightMode={nightMode}
            >
              <Thread path=":active" />
            </Thread>
            <Board
              boardList={boardList}
              path="/board/:dir"
              nightMode={nightMode}
            />
            <ThreadList
              boardList={boardList}
              path="/list/:dir"
              nightMode={nightMode}
            />
            <ChangeLogPage path="/changelog" nightMode={nightMode} />
            <FAQ path="/faq" nightMode={nightMode} />
            <NewThread
              path="/new/:dir"
              boardList={boardList}
              nightMode={nightMode}
            />
            <NotFound default />
          </Router>
        </Container>
        <Segment
          vertical
          textAlign="center"
          className={nightMode ? "footer night" : "footer"}
        >
          Bievenido a Internet 2010-2019
          <br />
          <Icon name="github" />
          <a href="https://github.com/Renard1911/bai-client">bai-client</a>
          {" + "}
          <a href="https://git.bienvenidoainternet.org/bai/weabot/">weabot</a>
          <br />
          <a href="http://www.wtfpl.net/about/">
            <img src={wtfpl} alt="Do what the fuck you want" />
          </a>
        </Segment>
      </React.Fragment>
    );
  }
}

render(<App />, document.getElementById("root"));