Created
October 13, 2020 09:36
-
-
Save dayanamdr/2ac0880aa4d5f969658a6ffede3479bb to your computer and use it in GitHub Desktop.
Code Feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CodeFeed() { | |
let params = new URLSearchParams(window.location.search); | |
const [codeFeed, setCodeFeed] = useState([]); | |
const [id, setId] = useState(params.get('user_id')); | |
function onChangeId() { | |
setId(params.get('user_id')); | |
} | |
const contentStyle = {textAlign: 'center'}; | |
const listStyle = { | |
width: '40%', | |
border: '1px solid #bfbfbf', | |
backgroundColor: '#ffffff' | |
}; | |
const pageStyle = {alignItems: 'center'}; | |
useEffect(() => { | |
fetch(`/api/code/feed?user_id=${id}`) | |
.then(response => response.json()) | |
.then(data => { | |
if (data.success === 1) { | |
setCodeFeed(data.feed); | |
} | |
}) | |
}, [id]); | |
return ( | |
<Layout style={pageStyle}> | |
<Layout style={listStyle}> | |
<List | |
itemLayout="horizontal" | |
dataSource={codeFeed} | |
renderItem={item => ( | |
<List.Item> | |
<List.Item.Meta style={contentStyle} | |
title=<Link to={`/code/${item.id}/view`}>{item.id}</Link> | |
description={item.date_posted} | |
/> | |
</List.Item> | |
)} | |
/> | |
</Layout> | |
</Layout> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment