File indexing completed on 2025-05-04 05:31:00
0001 import React ,{useState,useEffect} from 'react' 0002 import TimeAgo from 'react-timeago' 0003 const ForumUserPosts = (props) => { 0004 const [posts, setPosts] = useState([]); 0005 const [user, setUser] = useState({'username':''}); 0006 const [forumUrl, setForumUrl] = useState(window.config.forumUrl); 0007 const [baseUrl, setBaseUrl] = useState(window.config.baseUrl); 0008 useEffect(() => { 0009 loadData(); 0010 },[]); 0011 0012 const loadData = () => { 0013 fetch(`/json/forumposts?username=${props.username}`, { 0014 mode: 'cors', 0015 credentials: 'include' 0016 }) 0017 .then(response => response.json()) 0018 .then(data => { 0019 let items = data; 0020 if ( items && typeof(items.posts) != "undefined") 0021 { 0022 let posts = Object.keys(items.posts).map(function (i) { 0023 return items.posts[i]; 0024 }); 0025 posts.sort(function(a, b) { 0026 return a.created_at < b.created_at; 0027 }); 0028 setPosts(posts); 0029 } 0030 0031 if (items && typeof(items.user) != "undefined") 0032 { 0033 setUser(items.user.user); 0034 } 0035 }); 0036 0037 } 0038 0039 return ( 0040 <div className="sub-system-container"> 0041 <div className="header">Forum : <a href={forumUrl+'/u/'+user.username}>{user.username} </a> 0042 { 0043 user.avatar_template && 0044 <> 0045 <img src={forumUrl+user.avatar_template.replace('{size}','50')}></img> 0046 </> 0047 } 0048 0049 </div> 0050 0051 <div> 0052 <ul>{ 0053 posts.slice(0, 5).map((p,index) => 0054 <li key={index}> 0055 <div className="title"> 0056 <a href={forumUrl+'/p/'+p.post_id}>{p.excerpt.replace(/(<([^>]+)>)/ig,"")} </a> <TimeAgo date={p.created_at} /> 0057 </div> 0058 </li> 0059 ) 0060 } 0061 </ul> 0062 </div> 0063 </div> 0064 ) 0065 } 0066 0067 export default ForumUserPosts;