mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
event like support
This commit is contained in:
parent
cf6bf7f031
commit
eba4a6e3f5
7 changed files with 138 additions and 66 deletions
8
app.rb
8
app.rb
|
@ -857,6 +857,14 @@ post '/api/:name' do
|
||||||
api_not_found
|
api_not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
|
post '/event/:event_id/toggle_like' do |event_id|
|
||||||
|
require_login
|
||||||
|
content_type :json
|
||||||
|
event = Event[id: event_id]
|
||||||
|
liked_response = event.toggle_site_like(current_site) ? 'liked' : 'unliked'
|
||||||
|
{result: liked_response, event_like_count: event.likes_dataset.count}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
def require_admin
|
def require_admin
|
||||||
redirect '/' unless signed_in? && current_site.is_admin
|
redirect '/' unless signed_in? && current_site.is_admin
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,26 @@ class Event < Sequel::Model
|
||||||
one_to_one :site_change
|
one_to_one :site_change
|
||||||
many_to_one :profile_comment
|
many_to_one :profile_comment
|
||||||
one_to_many :likes
|
one_to_many :likes
|
||||||
|
|
||||||
|
def site_likes?(site)
|
||||||
|
likes_dataset.filter(actioning_site_id: site.id).count > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def site_like(site)
|
||||||
|
add_like actioning_site_id: site.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def site_unlike(site)
|
||||||
|
likes_dataset.filter(actioning_site_id: site.id).delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def toggle_site_like(site)
|
||||||
|
if site_likes? site
|
||||||
|
site_unlike site
|
||||||
|
false
|
||||||
|
else
|
||||||
|
site_like site
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
27
public/assets/scripts/news/like.js
Normal file
27
public/assets/scripts/news/like.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
var Like = function(eventId, csrfToken) {
|
||||||
|
this.eventId = eventId
|
||||||
|
this.csrfToken = csrfToken
|
||||||
|
this.link = $('#event_'+this.eventId+'_actions a#like')
|
||||||
|
}
|
||||||
|
|
||||||
|
Like.prototype.toggleLike = function() {
|
||||||
|
console.log('herp?')
|
||||||
|
var self = this
|
||||||
|
$.post('/event/'+this.eventId+'/toggle_like', {csrf_token: this.csrfToken}, function(res) {
|
||||||
|
console.log(res)
|
||||||
|
|
||||||
|
console.log(self.link.text('butts'))
|
||||||
|
|
||||||
|
if(res.result == 'liked')
|
||||||
|
self.link.text('Unlike ('+res.event_like_count+')')
|
||||||
|
|
||||||
|
if(res.result == 'unliked') {
|
||||||
|
var linkText = 'Like'
|
||||||
|
|
||||||
|
if(res.event_like_count > 0)
|
||||||
|
linkText += ' ('+res.event_like_count+')'
|
||||||
|
|
||||||
|
self.link.text(linkText)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
<script src="/assets/scripts/news/like.js"></script>
|
||||||
<% events.each do |event| %>
|
<% events.each do |event| %>
|
||||||
<% if event.profile_comment_id %>
|
<% if event.profile_comment_id %>
|
||||||
<%== erb :'_news_profile_comment', layout: false, locals: {profile_comment: event.profile_comment} %>
|
<%== erb :'_news_profile_comment', layout: false, locals: {profile_comment: event.profile_comment} %>
|
||||||
|
|
11
views/_news_actions.erb
Normal file
11
views/_news_actions.erb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<div id="event_<%= event.id %>_actions" class="actions">
|
||||||
|
<% if current_site %>
|
||||||
|
<a href="#" id="like" onclick="new Like(<%= event.id %>, '<%= csrf_token %>').toggleLike(); return false"><%= event.site_likes?(current_site) ? 'Unlike' : 'Like' %><%= event.likes_dataset.count > 0 ? " (#{event.likes_dataset.count})" : '' %></a>
|
||||||
|
<% else %>
|
||||||
|
<% event_like_count = event.likes_dataset.count %>
|
||||||
|
<% if event_like_count > 0 %>
|
||||||
|
<%= event_like_count %> <%= event_like_count == 1 ? 'like' : 'likes' %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<a href="">Reply</a>
|
||||||
|
</div>
|
|
@ -5,4 +5,6 @@
|
||||||
<span class="date"><%= profile_comment.created_at.ago %></span>
|
<span class="date"><%= profile_comment.created_at.ago %></span>
|
||||||
<div class="comment"><%= profile_comment.message %></div>
|
<div class="comment"><%= profile_comment.message %></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%== erb :'_news_actions', layout: false, locals: {event: profile_comment.event} %>
|
||||||
</div>
|
</div>
|
133
views/home.erb
133
views/home.erb
|
@ -21,77 +21,78 @@
|
||||||
<p>You aren't following any websites yet! Once you do, updates will show up here and you can like and comment on them. Here are some website suggestions based on your tags, or <a href="/browse">check out all the sites on Neocities!</a></p>
|
<p>You aren't following any websites yet! Once you do, updates will show up here and you can like and comment on them. Here are some website suggestions based on your tags, or <a href="/browse">check out all the sites on Neocities!</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="site-suggestion">
|
<div class="site-suggestion">
|
||||||
<div class="site-portrait">
|
<div class="site-portrait">
|
||||||
<a href="http://dragonquest.neocities.org">
|
<a href="http://dragonquest.neocities.org">
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
<span class="caption">dragonquest</span>
|
<span class="caption">dragonquest</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
<a class="tag" href="http://neocities.org">Anime</a>
|
<a class="tag" href="http://neocities.org">Anime</a>
|
||||||
<a class="tag" href="http://neocities.org">Art</a>
|
<a class="tag" href="http://neocities.org">Art</a>
|
||||||
<a class="tag" href="http://neocities.org">Cooking</a>
|
<a class="tag" href="http://neocities.org">Cooking</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="site-suggestion">
|
||||||
|
<div class="site-portrait">
|
||||||
|
<a href="http://dragonquest.neocities.org">
|
||||||
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
|
<span class="caption">dragonquest</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
|
<a class="tag" href="http://neocities.org">Anime</a>
|
||||||
|
<a class="tag" href="http://neocities.org">Art</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="site-suggestion">
|
||||||
|
<div class="site-portrait">
|
||||||
|
<a href="http://dragonquest.neocities.org">
|
||||||
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
|
<span class="caption">dragonquest</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
|
<a class="tag" href="http://neocities.org">Anime</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="site-suggestion">
|
||||||
|
<div class="site-portrait">
|
||||||
|
<a href="http://dragonquest.neocities.org">
|
||||||
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
|
<span class="caption">dragonquest</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="site-suggestion">
|
||||||
|
<div class="site-portrait">
|
||||||
|
<a href="http://dragonquest.neocities.org">
|
||||||
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
|
<span class="caption">dragonquest</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
|
<a class="tag" href="http://neocities.org">Anime</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="site-suggestion">
|
||||||
|
<div class="site-portrait">
|
||||||
|
<a href="http://dragonquest.neocities.org">
|
||||||
|
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||||
|
<span class="caption">dragonquest</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a class="tag" href="http://neocities.org">Games</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="site-suggestion">
|
|
||||||
<div class="site-portrait">
|
|
||||||
<a href="http://dragonquest.neocities.org">
|
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
|
||||||
<span class="caption">dragonquest</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
|
||||||
<a class="tag" href="http://neocities.org">Anime</a>
|
|
||||||
<a class="tag" href="http://neocities.org">Art</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="site-suggestion">
|
|
||||||
<div class="site-portrait">
|
|
||||||
<a href="http://dragonquest.neocities.org">
|
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
|
||||||
<span class="caption">dragonquest</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
|
||||||
<a class="tag" href="http://neocities.org">Anime</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="site-suggestion">
|
|
||||||
<div class="site-portrait">
|
|
||||||
<a href="http://dragonquest.neocities.org">
|
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
|
||||||
<span class="caption">dragonquest</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="site-suggestion">
|
|
||||||
<div class="site-portrait">
|
|
||||||
<a href="http://dragonquest.neocities.org">
|
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
|
||||||
<span class="caption">dragonquest</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
|
||||||
<a class="tag" href="http://neocities.org">Anime</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="site-suggestion">
|
|
||||||
<div class="site-portrait">
|
|
||||||
<a href="http://dragonquest.neocities.org">
|
|
||||||
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
|
|
||||||
<span class="caption">dragonquest</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<a class="tag" href="http://neocities.org">Games</a>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col col-33">
|
<div class="col col-33">
|
||||||
<p class="site-url"><a href="http://<%= site.username %>.neocities.org" target="_blank">http://<%= site.username %>.neocities.org</a></p>
|
<p class="site-url"><a href="//<%= site.username %>.neocities.org" target="_blank"><%= site.username %>.neocities.org</a></p>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="col col-50">
|
<div class="col col-50">
|
||||||
<% if site.updated_at %>
|
<% if site.updated_at %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue