Skip to content

Commit

Permalink
add like WIP b00tc4mp#167
Browse files Browse the repository at this point in the history
  • Loading branch information
annagonzalez9 committed Oct 14, 2024
1 parent 3ec9f43 commit 70d947a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion staff/anna-gonzalez/unsocial/compo/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ function Button(text, type) {
this.container.type = type
}

Button.extends(Compo)
Button.extends(Compo)

Button.prototype.getText = function () {
return this.container.textContent
};

Button.prototype.setText = function (text) {
this.container.textContent = text
};
16 changes: 15 additions & 1 deletion staff/anna-gonzalez/unsocial/view/PostItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function PostItem(username, image, text, date) {
function PostItem(username, image, text, date, emoji) {
Compo.call(this, document.createElement('article'))
this.container.style.display = 'flex'
this.container.style.flexDirection = 'column'
this.container.style.justifyContent = 'center'
this.container.style.textAlign = 'center'
this.container.style.alignItems = 'center'

var userTitle = new Heading(username, 4)
userTitle.container.style.textDecoration = 'underline'
Expand All @@ -15,6 +20,15 @@ function PostItem(username, image, text, date) {

var time = new Time(date)
this.add(time)

var like = new Button(emoji || 'πŸ‘Ž')
this.add(like)
like.container.style.marginTop = '20px'

like.addBehaviour('click', function (event) {
var currentEmoji = like.getText();
like.setText(currentEmoji === 'πŸ‘' ? 'πŸ‘Ž' : 'πŸ‘')
})
}

PostItem.extends(Compo)
2 changes: 1 addition & 1 deletion staff/anna-gonzalez/unsocial/view/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function PostList() {
var posts = getPosts().toReversed()

posts.forEach(function (post) {
var postItem = new PostItem(post.username, post.image, post.text, post.date)
var postItem = new PostItem(post.username, post.image, post.text, post.date, post.emoji)

this.add(postItem)
}.bind(this))
Expand Down

0 comments on commit 70d947a

Please sign in to comment.