import React, { Component } from "react"; import { List, Header, Icon, Loader, Grid, Image } 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, autoRefresh: null }; this.lastTime = 0; this.refreshCooldown = 15; this.cooldownCounter = 0; this.lastTimeNoAge = 0; this.notificationSound = new Audio( "https://bienvenidoainternet.org/msn.ogg" ); } componentDidMount() { fetch("https://bienvenidoainternet.org/cgi/api/lastage?limit=10") .then(response => { return response.json(); }) .then(resource => { this.lastTime = resource.time; this.lastTimeNoAge = resource.time; this.setState({ lastAgeThreads: resource["threads"], autoRefresh: setInterval(() => this.updateAges(), 1000) }); }); 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 }); }); window.scrollTo(0, 0); } componentWillUnmount() { clearInterval(this.state.autoRefresh); } async updateAges() { this.cooldownCounter++; if (this.cooldownCounter < this.refreshCooldown) { return; } else { this.cooldownCounter = 0; } let apiURl = `https://bienvenidoainternet.org/cgi/api/lastage?time=${this.lastTime}&limit=10`; fetch(apiURl) .then(response => { return response.json(); }) .then(resource => { if (resource.state === "success") { if (resource.threads.length > 0) { this.setState({ lastAgeThreads: resource.threads }); this.refreshCooldown = 30; this.notificationSound.play(); } else { this.refreshCooldown += 15; this.lastTimeNoAge = resource.time; if (this.refreshCooldown > 60) { this.refreshCooldown = 60; } } } this.lastTime = resource.time; }); } render() { if (!this.state.isLoaded) { return ( Cargando ... ); } const { newThreadsList, lastAgeThreads, latestNews } = this.state; const { nightMode } = this.props; document.title = "B.a.I Home"; return ( Resistiendo desde el 2010 Ahora con 95% extra javascript! Hilos activos {lastAgeThreads.map(thread => ( this.lastTimeNoAge ? "bullhorn" : "comment alternate outline" } size="large" verticalAlign="middle" /> {thread.content} {" "} en {thread.board_fulln}{" "} ))} Nuevos hilos {newThreadsList.map(thread => ( {thread.content} {" "} en {thread.board_fulln}{" "} ))} Blotter {latestNews.map(n => ( ))} ); } } export default Home;
Resistiendo desde el 2010 Ahora con 95% extra javascript!