From 8d7891a25bbf94d5c678b71379519453ed846e55 Mon Sep 17 00:00:00 2001 From: Renard Date: Mon, 23 Sep 2019 22:14:00 -0300 Subject: Lista de hilos --- src/ThreadList.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/ThreadList.js (limited to 'src/ThreadList.js') diff --git a/src/ThreadList.js b/src/ThreadList.js new file mode 100644 index 0000000..c5eb990 --- /dev/null +++ b/src/ThreadList.js @@ -0,0 +1,84 @@ +import React, { Component } from "react"; +import { Header, Loader, List, Card, Image, Icon } from "semantic-ui-react"; +import { Link } from "@reach/router"; +import Moment from "react-moment"; +import "moment/locale/es"; + +class ThreadList extends Component { + constructor(props) { + super(props); + this.state = { isLoading: true, threadList: [] }; + } + + componentDidMount() { + const { dir } = this.props; + fetch( + `https://bienvenidoainternet.org/cgi/api/list?dir=${dir}&replies=0&limit=30&nohtml=1` + ) + .then(response => { + return response.json(); + }) + .then(resource => { + this.setState({ threadList: resource.threads, isLoading: false }); + }); + } + + render() { + const { dir, boardList } = this.props; + const { threadList, isLoading } = this.state; + + const currentBoard = boardList.find(board => { + return board.dir === dir; + }); + + if (isLoading) { + return ( + + Cargando lista de hilos ... + + ); + } + + const stripHtml = RegExp( + /()|()|()|(<\/?(\s|\S)*?>)/g + ); + + return ( + + {threadList.map((thread, index) => { + return ( + + {currentBoard.allow_images === 1 ? ( + + ) : null} + + + {thread.subject} + + + + + + + + {thread.message.replace(stripHtml, "").substring(0, 200) + + " ..."} + + + + + {thread.total_replies} Respuestas + + + ); + })} + + ); + } +} + +export default ThreadList; -- cgit v1.2.1-18-gbd029