File indexing completed on 2025-01-26 05:27:59

0001 import React, { Component } from 'react';
0002 import TimeAgo from 'react-timeago';
0003 
0004 let decodeHTML = function (html) {
0005         var txt = document.createElement('textarea');
0006         txt.innerHTML = html;
0007         return txt.value;
0008 };
0009 
0010 class RssNewsContainer extends Component {
0011   constructor(props){
0012         super(props);
0013         this.state = {};
0014   }
0015 
0016   componentDidMount() {
0017     const self = this;    
0018     $.getJSON(`/json/news`, function (res) {
0019       for (var i in res.posts) {
0020         res.posts[i].title = decodeHTML(res.posts[i].title);        
0021       }      
0022       self.setState({items:res.posts});
0023     });
0024   }
0025 
0026   render(){
0027     let feedItemsContainer;
0028     if (this.state.items){
0029 
0030       const feedItems = this.state.items.slice(0,5).map((fi,index) => (
0031         <li key={index}>
0032           <a className="title" href={fi.url}>
0033             <span>{fi.title}</span>
0034           </a>
0035           <span className="info-row">
0036             <span className="date">
0037             <TimeAgo date={fi.date} /></span>
0038             <span className="comment-counter">{fi.comment_count} comments</span>
0039           </span>
0040         </li>
0041       ));
0042 
0043       feedItemsContainer = <ul>{feedItems}</ul>;
0044     }
0045     return (
0046       <div id="rss-new-container" className="panelContainer">
0047         <div className="title"><a href="https://blog.opendesktop.org/">News</a></div>
0048         {feedItemsContainer}
0049       </div>
0050     )
0051   }
0052 }
0053 
0054 export default RssNewsContainer;