Skip to content

Commit d30563d

Browse files
committed
refactored css around hearts and added comment hearting
1 parent 618ff49 commit d30563d

File tree

9 files changed

+116
-66
lines changed

9 files changed

+116
-66
lines changed

app/assets/javascripts/components/Heart.es6.jsx

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
class Heart extends React.Component {
22
render() {
33
let classes = {
4-
root: 'heart left ml1 mr2',
5-
icon: 'highlight center',
6-
count: 'diminish center font-tiny'
4+
root: 'heart no-hover',
5+
icon: 'highlight',
6+
count: 'diminish font-tiny',
7+
inline: ''
78
}
89
if (this.props.layout === 'inline') {
910
classes = {
10-
root: 'heart left ml1 mr2 flat',
11-
icon: 'highlight mr1',
12-
count: 'diminish inline'
11+
root: 'heart no-hover font-x-lg',
12+
icon: 'highlight',
13+
count: 'ml1 diminish bold',
14+
inline: 'inline'
15+
}
16+
}
17+
if (this.props.layout === 'simple') {
18+
classes = {
19+
root: 'heart pointer',
20+
icon: 'highlight',
21+
count: 'ml1',
22+
inline: 'inline'
1323
}
1424
}
1525
return (
16-
<div>
26+
<div className='inline'>
1727
<a className={classes.root} onClick={() => this.props.onClick()}>
18-
{this.renderHeartState(classes.icon)}
19-
<div className={classes.count}>
20-
{this.numberToHuman(this.props.count)}
21-
</div>
28+
<center className={classes.inline}>
29+
{this.renderHeartState(classes.icon)}
30+
</center>
31+
{this.renderHeartCount(classes)}
2232
</a>
2333
</div>
2434
)
2535
}
2636

37+
renderHeartCount(classes){
38+
if(this.props.layout != 'simple')
39+
{
40+
return <div className={classes.count}>
41+
<center className={classes.inline}>
42+
{this.numberToHuman(this.props.count)}
43+
</center>
44+
</div>
45+
}
46+
}
47+
2748
renderHeartState(classes) {
2849
if (!this.props.hearted) {
29-
return <div className={classes + ' pointer'}>
30-
<i className="fa fa-heart-o" />
31-
</div>
50+
if(this.props.layout === 'simple')
51+
{
52+
return <span>Like?</span>
53+
}
54+
else
55+
{
56+
return <div className={classes + ' pointer'}>
57+
<i className={classes + ' pointer fa fa-heart-o'} />
58+
</div>
59+
}
3260
}
61+
3362
return <div className={classes + ' hearted default-cursor'}>
3463
<i className="fa fa-heart" />
3564
</div>

app/assets/javascripts/components/Heartable.es6.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ProtipHeart extends React.Component {
1+
class Heartable extends React.Component {
22
constructor(props) {
33
super(props)
44
this.state = {
@@ -8,8 +8,7 @@ class ProtipHeart extends React.Component {
88
}
99

1010
componentDidMount() {
11-
const userLikes = JSON.parse($('#signed-in-user-liked-payload').html()) || []
12-
console.log(userLikes)
11+
const userLikes = getUserLikes()
1312
if (userLikes.indexOf(this.props.id) > -1) {
1413
this.setState({hearted: true})
1514
}
@@ -41,7 +40,13 @@ class ProtipHeart extends React.Component {
4140
}
4241
}
4342

44-
ProtipHeart.propTypes = {
43+
Heartable.propTypes = {
4544
initialCount: React.PropTypes.number,
46-
protipId: React.PropTypes.string,
45+
protipId: React.PropTypes.string
46+
}
47+
48+
var _userLikes
49+
function getUserLikes() {
50+
_userLikes = _userLikes || JSON.parse($('#current-users-liked-as-json').html())
51+
return _userLikes
4752
}

app/assets/stylesheets/application.scss

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ $font-x-lg: 18px;
1717

1818
$highlight-color: $red;
1919
.highlight {
20-
display: inline;
2120
color: $highlight-color !important;
2221
a {
2322
color: $highlight-color !important;
@@ -47,11 +46,15 @@ $highlight-color: $red;
4746
font-size: $font-lg;
4847
}
4948

49+
.font-x-lg {
50+
font-size: $font-x-lg;
51+
}
52+
5053
.active {
5154
border-bottom: solid 3px $blue;
5255
}
5356

54-
$h3: 18px;
57+
$h3: $font-x-lg;
5558

5659
h1, h3 {
5760
a{
@@ -110,6 +113,10 @@ $placeholder: darken($silver, 20%);
110113
}
111114
}
112115

116+
.mt-third {
117+
margin-top: .33rem;
118+
}
119+
113120
.default-cursor{
114121
cursor: default !important;
115122
}
@@ -118,26 +125,6 @@ $placeholder: darken($silver, 20%);
118125
cursor: pointer;
119126
}
120127

121-
a.heart {
122-
padding-top: 4px;
123-
font-size: $font-sm;
124-
color: red;
125-
text-decoration: none;
126-
127-
i {
128-
font-size: $font-sm;
129-
}
130-
131-
&.flat {
132-
padding-top: 0px;
133-
font-size: $font-lg;
134-
font-weight: bold;
135-
i {
136-
font-size: $font-lg;
137-
}
138-
}
139-
}
140-
141128
a.no-hover {
142129
&:hover{
143130
text-decoration: none;
@@ -187,3 +174,8 @@ header {
187174
.focus-pb3:focus {
188175
padding-bottom: $space-3;
189176
}
177+
178+
//neutralize rails-react wrappers affect on layout
179+
div[data-react-class], div[data-reactid] {
180+
display: inline;
181+
}

app/helpers/users_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
module UsersHelper
22

3+
def current_user_liked_list
4+
# what it was on protip
5+
#signed-in-user-liked-payload.hide=current_user.likes?(@protip) && [dom_id(@protip)]
6+
if signed_in?
7+
current_user.liked
8+
else
9+
empty_json_array_so_font_end_continues = '[]'
10+
end
11+
end
12+
313
def finishing_signup?
414
params[:finish_signup] == true
515
end

app/views/comments/_comment.html.haml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
&middot;
1111
%a{:href => comment_path(comment), 'data-method'=>'delete', 'data-confirm' => 'Are you sure you want to delete your comment?'}=icon('trash')
1212
&middot;
13-
%a{:href => comment_likes_path(comment), 'data-remote'=>"true", 'data-method'=>'post'} Like?
13+
= react_component 'Heartable',
14+
id: dom_id(comment),
15+
href: comment_likes_path(comment),
16+
initialCount: comment.likes_count,
17+
layout: 'simple'

app/views/protips/_protip.html.haml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
.protip.card.clearfix.p1.mb2.likeable{id: dom_id(protip)}
2-
= react_component 'ProtipHeart',
3-
id: dom_id(protip),
4-
href: protip_likes_path(protip),
5-
initialCount: protip.likes_count
1+
.protip.card.clearfix.py1.mb2.likeable{id: dom_id(protip)}
2+
.left.col.col-1
3+
.mt-third
4+
= react_component 'Heartable',
5+
id: dom_id(protip),
6+
href: protip_likes_path(protip),
7+
initialCount: protip.likes_count
68

79
.overflow-hidden
810
%h3.mt0.mb0

app/views/protips/index.html.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
-content_for :title do
22
Coderwall : A community space for developers.
33

4-
-if signed_in?
5-
#signed-in-user-liked-payload.hide=current_user.liked
4+
#current-users-liked-as-json.hide=current_user_liked_list
65

76
.continer
87
-if protips_view_breadcrumbs.present?

app/views/protips/show.html.haml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
=content_for :title do
22
==#{@protip.title} : #{@protip.public_id}
33

4-
-if signed_in?
5-
#signed-in-user-liked-payload.hide=current_user.likes?(@protip) && [dom_id(@protip)]
4+
#current-users-liked-as-json.hide=current_user_liked_list
65
-# .hide
76
-# - meta description: protip_summary
87
-# - meta og: { description: protip_summary }
@@ -27,13 +26,12 @@
2726
.md-col.md-col-2.md-show &nbsp;
2827
.sm-col.sm-col.sm-col-12.md-col-8
2928
.clearfix.mt0.mb1
30-
.left.mt1
31-
= react_component 'ProtipHeart',
32-
id: dom_id(@protip),
33-
href: protip_likes_path(@protip),
34-
initialCount: @protip.likes_count,
35-
layout: 'inline'
36-
.right.pt0.mt0
29+
.left.mt-third= react_component 'Heartable',
30+
id: dom_id(@protip),
31+
href: protip_likes_path(@protip),
32+
initialCount: @protip.likes_count,
33+
layout: 'inline'
34+
.right
3735
.diminish.inline.mr1
3836
=icon("eye")
3937
=number_to_human(@protip.views_count, precision: 4)

lib/tasks/db.rake

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@ namespace :db do
66
'db:port:comments',
77
'db:port:teams',
88
'db:port:likes',
9+
'db:fix_counters',
910
'cache:score:recalculate']
1011

11-
namespace :port do
12-
13-
task :clean => :environment do
14-
Like.delete_all
15-
Comment.delete_all
16-
Protip.delete_all
17-
Badge.delete_all
18-
User.delete_all
12+
task :fix_counters => :environment do
13+
Comment.find_each do |comment|
14+
puts comment.id
15+
Comment.reset_counters(comment.id, :likes)
1916
end
17+
Protip.find_each do |protip|
18+
puts protip.id
19+
Protip.reset_counters(protip.id, :likes)
20+
end
21+
end
2022

23+
task :clean => :environment do
24+
Like.delete_all
25+
Comment.delete_all
26+
Protip.delete_all
27+
Badge.delete_all
28+
User.delete_all
29+
end
30+
31+
namespace :port do
2132
task :connect => :environment do
2233
if hide_sql_out = Rails.env.development?
2334
ActiveRecord::Base.logger.level = Logger::INFO

0 commit comments

Comments
 (0)