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 {
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";
class App extends Component {
constructor() {
super();
this.state = {
boardList: [],
isLoaded: false,
nightMode: false
};
this.toggleTheme = this.toggleTheme.bind(this);
}
componentDidMount() {
fetch("https://bienvenidoainternet.org/cgi/api/boards")
.then(response => {
return response.json();
})
.then(resource => {
this.setState({ boardList: resource["boards"], isLoaded: true });
});
let _nightMode = localStorage.getItem("nightMode");
if (_nightMode === null) {
localStorage.setItem("nightMode", false);
} else {
this.setState({ nightMode: JSON.parse(_nightMode) });
}
}
componentDidUpdate() {
if (this.state.nightMode) {
document.body.style.backgroundColor = "#313233";
} else {
document.body.style.backgroundColor = "#FFFFFF";
}
}
toggleTheme() {
this.setState({ nightMode: !this.state.nightMode }, () => {
localStorage.setItem("nightMode", this.state.nightMode);
});
}
render() {
const { boardList, nightMode, isLoaded } = this.state;
if (!isLoaded) {
return (
Cargando ...
);
}
return (
Bievenido a Internet 2010-2019
bai-client
{" + "}
weabot
);
}
}
render(, document.getElementById("root"));