Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def new
def edit
respond_to do |format|
format.html
format.js
end
end

Expand All @@ -33,9 +34,11 @@ def create
if @comment.save
format.html { redirect_back fallback_location: root_path, notice: "Comment was successfully created." }
format.json { render :show, status: :created, location: @comment }
format.js
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
format.js
end
end
end
Expand All @@ -46,9 +49,11 @@ def update
if @comment.update(comment_params)
format.html { redirect_to root_url, notice: "Comment was successfully updated." }
format.json { render :show, status: :ok, location: @comment }
format.js
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
format.js
end
end
end
Expand All @@ -59,23 +64,28 @@ def destroy
respond_to do |format|
format.html { redirect_back fallback_location: root_url, notice: "Comment was successfully destroyed." }
format.json { head :no_content }

format.js do
render template: "comments/destroy"
end
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end

def ensure_current_user_is_owner
if current_user != @comment.author
redirect_back fallback_location: root_url, alert: "You're not authorized for that."
end
end
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end

# Only allow a list of trusted parameters through.
def comment_params
params.require(:comment).permit(:author_id, :photo_id, :body)
def ensure_current_user_is_owner
if current_user != @comment.author
redirect_back fallback_location: root_url, alert: "You're not authorized for that."
end
end

# Only allow a list of trusted parameters through.
def comment_params
params.require(:comment).permit(:author_id, :photo_id, :body)
end
end
7 changes: 7 additions & 0 deletions app/controllers/follow_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def index

# GET /follow_requests/1 or /follow_requests/1.json
def show
format.js
end

# GET /follow_requests/new
Expand All @@ -17,6 +18,7 @@ def new

# GET /follow_requests/1/edit
def edit
format.js
end

# POST /follow_requests or /follow_requests.json
Expand All @@ -28,9 +30,11 @@ def create
if @follow_request.save
format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully created." }
format.json { render :show, status: :created, location: @follow_request }
format.js
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
format.js
end
end
end
Expand All @@ -41,9 +45,11 @@ def update
if @follow_request.update(follow_request_params)
format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully updated." }
format.json { render :show, status: :ok, location: @follow_request }
format.js
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
format.js
end
end
end
Expand All @@ -54,6 +60,7 @@ def destroy
respond_to do |format|
format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully destroyed." }
format.json { head :no_content }
format.js
end
end

Expand Down
27 changes: 19 additions & 8 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def index

# GET /likes/1 or /likes/1.json
def show
format.js
end

# GET /likes/new
Expand All @@ -17,6 +18,10 @@ def new

# GET /likes/1/edit
def edit
respond_to do |format|
format.html
format.js
end
end

# POST /likes or /likes.json
Expand All @@ -27,6 +32,7 @@ def create
if @like.save
format.html { redirect_back fallback_location: root_url, notice: "Like was successfully created." }
format.json { render :show, status: :created, location: @like }
format.js
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
Expand All @@ -40,9 +46,11 @@ def update
if @like.update(like_params)
format.html { redirect_to @like, notice: "Like was successfully updated." }
format.json { render :show, status: :ok, location: @like }
format.js
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
format.js
end
end
end
Expand All @@ -53,17 +61,20 @@ def destroy
respond_to do |format|
format.html { redirect_back fallback_location: root_url, notice: "Like was successfully destroyed." }
format.json { head :no_content }

format.js
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_like
@like = Like.find(params[:id])
end

# Only allow a list of trusted parameters through.
def like_params
params.require(:like).permit(:fan_id, :photo_id)
end
# Use callbacks to share common setup or constraints between actions.
def set_like
@like = Like.find(params[:id])
end

# Only allow a list of trusted parameters through.
def like_params
params.require(:like).permit(:fan_id, :photo_id)
end
end
10 changes: 7 additions & 3 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<li class="list-group-item">
<li id="<%= dom_id(comment) %>" class="list-group-item">
<div class="d-flex">
<div class="flex-shrink-0">
<%= image_tag comment.author.avatar_image, class: "rounded-circle mr-2", width: 36 %>
Expand All @@ -11,11 +11,15 @@
</div>
<div>
<% if current_user == comment.author %>
<%= link_to edit_comment_path(comment), class: "btn btn-link btn-sm text-muted" do %>
<%= link_to edit_comment_path(comment), class: "btn btn-link btn-sm text-muted", remote: true do %>
<i class="fas fa-edit fa-fw"></i>
<% end %>

<%= link_to comment, data: { turbo_method: :delete }, class: "btn btn-link btn-sm text-muted" do %>
<%= link_to comment,
method: :delete,
class: "btn btn-link btn-sm text-muted",
remote: true do %>

<i class="fas fa-trash fa-fw"></i>
<% end %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="list-group-item">
<%= form_with(model: comment) do |form| %>
<li id="<%= dom_id(comment.photo) %>_<%= dom_id(comment) %>_form" class="list-group-item">
<%= form_with(model: comment, local: false) do |form| %>
<% if comment.errors.any? %>
<div id="error_explanation">
<ul class="list-unstyled">
Expand Down
9 changes: 9 additions & 0 deletions app/views/comments/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var added_comment = $("<%= j(render @comment) %>");

added_comment.hide();

$("#<%= dom_id(@comment.photo) %>_new_comment_form").before(added_comment);

added_comment.slideDown();

$("#<%= dom_id(@comment.photo) %>_new_comment_form #comment_body").val("");
3 changes: 3 additions & 0 deletions app/views/comments/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$("#<%= dom_id(@comment) %>").fadeOut(500, function() {
$(this).remove();
});
1 change: 1 addition & 0 deletions app/views/comments/edit.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@comment) %>").replaceWith("<%= j(render "comments/form", comment: @comment) %>");
1 change: 1 addition & 0 deletions app/views/comments/update.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@comment.photo) %>_<%= dom_id(@comment) %>_form").replaceWith("<%= j(render @comment) %>");
4 changes: 2 additions & 2 deletions app/views/follow_requests/_follow_unfollow.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<% if follow_request %>
<% if follow_request.pending? %>
<%= link_to follow_request, data: { turbo_method: :delete }, class: "btn btn-outline-secondary" do %>
<%= link_to follow_request, method: :delete, remote: true, class: "btn btn-outline-secondary" do %>
Un-request
<% end %>
<% elsif follow_request.accepted? %>
<%= link_to follow_request, data: { turbo_method: :delete }, class: "btn btn-outline-secondary" do %>
<%= link_to follow_request, method: :delete, remote: true, class: "btn btn-outline-secondary" do %>
Un-follow
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/follow_requests/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@follow_request.id) %>_likes").replaceWith("<%= j(render 'users/show', follow_request: @follow_request.id) %>")
1 change: 1 addition & 0 deletions app/views/follow_requests/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@follow_request.id) %>_likes").replaceWith("<%= j(render 'users/show', follow_request: @follow_request.id) %>")
2 changes: 1 addition & 1 deletion app/views/likes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: like, class: "d-inline-block") do |form| %>
<%= form_with(model: like, local: false, class: "d-inline-block") do |form| %>
<%= form.hidden_field :fan_id %>

<%= form.hidden_field :photo_id %>
Expand Down
1 change: 1 addition & 0 deletions app/views/likes/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@like.photo) %>_likes").replaceWith("<%= j(render "photos/likes", photo: @like.photo) %>")
1 change: 1 addition & 0 deletions app/views/likes/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@like.photo) %>_likes").replaceWith("<%= j(render 'photos/likes', photo: @like.photo) %>")
2 changes: 1 addition & 1 deletion app/views/photos/_likes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% like = current_user.likes.find_by(photo: photo) %>

<% if like %>
<%= link_to like, class: "btn btn-link link-underline-dark link-underline link-underline-opacity-0 link-underline-opacity-100-hover", data: { turbo_method: :delete } do %>
<%= link_to like, class: "btn btn-link link-underline-dark link-underline link-underline-opacity-0 link-underline-opacity-100-hover", method: :delete, remote: true do %>
<i class="fas fa-heart fa-fw"></i>

Un-like
Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "@rails/ujs", to: "https://ga.jspm.io/npm:@rails/ujs@7.0.8/lib/assets/compiled/rails-ujs.js"
pin "@rails/ujs", to: "https://ga.jspm.io/npm:@rails/ujs@7.1.0/app/assets/javascripts/rails-ujs.esm.js"
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.7.1/dist/jquery.js"
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
get ":username/liked" => "users#liked", as: :liked
get ":username/feed" => "users#feed", as: :feed
get ":username/discover" => "users#discover", as: :discover
end


#########extra message for pull request purposes
end
45 changes: 45 additions & 0 deletions domain modeling notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Tables:

# Listings
# description
# price
# status
# title
# location
# seller_id
# image
# category_id
# buyer_id
# created_at
# updated_at
# id

# Categories
# name
# id
# created_at
# updated_at



# Users
# email
# password
# name
# created_at
# updated_at
# id



# Conversations
# id
# item_id
# seller_id
# buyer_id
# created_at
# updated_at
# seller_body
# buyer_body

# # has_many :conversation_users