import React, { Component } from "react";
import { render } from "react-dom";
import { Router, Link } from "@reach/router";
import "fomantic-ui-css/semantic.min.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() {
let boardsInfo = localStorage.getItem("boardsInfo");
let shouldUpdate = false;
if (boardsInfo !== null) {
shouldUpdate = Date.now() / 1000 - JSON.parse(boardsInfo).time > 10080;
}
if (boardsInfo === null || shouldUpdate) {
fetch("https://bienvenidoainternet.org/cgi/api/boardsExtra")
.then(response => {
return response.json();
})
.then(resource => {
localStorage.setItem("boardsInfo", JSON.stringify(resource));
this.setState({
boardList: resource["boards"],
isLoaded: true
});
});
} else {
this.setState({
boardList: JSON.parse(boardsInfo)["boards"],
isLoaded: true
});
}
let lsSettings = localStorage.getItem("settings");
let settings = JSON.parse(lsSettings);
const defaultSettings = {
homeSound: "msn",
threadSound: "msn",
nightMode: false,
notifyOnHome: true,
notifyOnThread: true,
autoUpdateThreads: true,
showAvatars: true,
postPassword: this.genPassword(),
embedYoutube: true,
colorifyIDs: true,
browserId: false
};
if (lsSettings === null) {
localStorage.setItem("settings", JSON.stringify(defaultSettings));
settings = defaultSettings;
} else {
Object.keys(defaultSettings).forEach(key => {
if (settings[key] === undefined) {
settings[key] = defaultSettings[key];
}
});
localStorage.setItem("settings", JSON.stringify(settings));
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 (
Cargando ...
);
}
return (
Bievenido a Internet 2010-2019
bai-client
{" + "}
weabot
);
}
}
render(, document.getElementById("root"));