You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// In a real application, this would fetch posts from a server
34
+
constdummyPosts=[
35
+
{id: 1,author: 'John Doe',content: 'This is a short post, like a tweet!',likes: 5,comments: [],timestamp: newDate().toISOString()},
36
+
{id: 2,author: 'Jane Smith',content: 'This is a longer post that would be more like a blog entry. It contains more detailed information and might span multiple paragraphs.',likes: 10,comments: [],timestamp: newDate().toISOString()}
37
+
];
38
+
awaitthis.setState({posts: dummyPosts});
39
+
}
40
+
41
+
createPost(content){
42
+
constnewPost={
43
+
id: this.state.posts.length+1,
44
+
author: this.state.user,
45
+
content,
46
+
likes: 0,
47
+
comments: [],
48
+
timestamp: newDate().toISOString()
49
+
};
50
+
this.setState({
51
+
posts: [newPost, ...this.state.posts],
52
+
newPostContent: ''
53
+
});
54
+
}
55
+
56
+
likePost(postId){
57
+
constupdatedPosts=this.state.posts.map(post=>
58
+
post.id===postId ? { ...post,likes: post.likes+1} : post
59
+
);
60
+
this.setState({posts: updatedPosts});
61
+
}
62
+
63
+
addComment(postId,comment){
64
+
constupdatedPosts=this.state.posts.map(post=>
65
+
post.id===postId ? { ...post,comments: [...post.comments,{author: this.state.user,content: comment}]} : post
66
+
);
67
+
this.setState({posts: updatedPosts});
68
+
}
69
+
70
+
evolvePost(postId,newContent){
71
+
constupdatedPosts=this.state.posts.map(post=>
72
+
post.id===postId ? { ...post,content: newContent,evolutions: [...(post.evolutions||[]),{content: post.content,timestamp: newDate().toISOString()}]} : post
73
+
);
74
+
this.setState({posts: updatedPosts});
75
+
}
76
+
77
+
render(){
78
+
return`
79
+
<div class="blog-container">
80
+
<div class="new-post">
81
+
<textarea bind="{{newPostContent}}" placeholder="What's on your mind?"></textarea>
0 commit comments