Skip to content

Commit

Permalink
Chore: Remove react version of the project submissions feature (#4020)
Browse files Browse the repository at this point in the history
Because:
* We have rolled out a Hotwire version.
* Closes: #3908 

This commit
* Remove all of the react submission components
* Rename v2 project submissions
* Remove the project submission serializer
* Remove icon.css
* Remove JS packages used only by React submissions
* A few small refactors
* Project submission form now takes a model instead of a url - one less
thing to pass to the form_with
 * All submissions logic removed from lessons controller
* Filter out discarded submissions within the only_public scope, we'll
never want discarded submissions to be public.
  • Loading branch information
KevinMulhern authored Jul 27, 2023
1 parent 0886578 commit 648ae2d
Show file tree
Hide file tree
Showing 78 changed files with 231 additions and 2,862 deletions.
6 changes: 3 additions & 3 deletions app/components/project_submissions/item_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="<%= dom_id(project_submission) %>" data-id="<%= project_submission.id %>" data-sort-target="item" data-sort-code="<%= sort_code %>">
<div data-test-id="submission-item" class="relative py-6 border-solid border-t border-gray-300 flex flex-col md:flex-row justify-between md:items-center">
<div id="<%= dom_id(project_submission) %>" data-id="<%= project_submission.id %>" data-test-id="submission-item" data-sort-target="item" data-sort-code="<%= sort_code %>">
<div class="relative py-6 border-solid border-t border-gray-300 flex flex-col md:flex-row justify-between md:items-center">

<div class="flex items-center mb-4 md:mb-0">
<%= render ProjectSubmissions::LikeComponent.new(project_submission:, current_users_submission: current_users_submission?) %>
Expand Down Expand Up @@ -35,7 +35,7 @@
Edit
<% end %>
<%= link_to lesson_v2_project_submission_path(project_submission.lesson, project_submission), class: 'text-gray-700 dark:text-gray-300 group flex items-center px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-600 hover:text-gray-900 dark:hover:text-gray-200', role: 'menuitem', tabindex: '-1', data: { turbo_method: :delete, turbo_confirm: 'Are you sure? this cannot be undone.', test_id: 'delete-submission' } do %>
<%= link_to lesson_project_submission_path(project_submission.lesson, project_submission), class: 'text-gray-700 dark:text-gray-300 group flex items-center px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-600 hover:text-gray-900 dark:hover:text-gray-200', role: 'menuitem', tabindex: '-1', data: { turbo_method: :delete, turbo_confirm: 'Are you sure? this cannot be undone.', test_id: 'delete-submission' } do %>
<%= inline_svg_tag 'icons/trash.svg', class: 'mr-3 h-4 w-4 text-gray-400 group-hover:text-gray-500 dark:group-hover:text-gray-300', aria: true, title: 'edit', desc: 'edit icon' %>
Delete
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/components/project_submissions/item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sort_code
def edit_path
return @edit_path if @edit_path.present?

edit_lesson_v2_project_submission_path(project_submission.lesson, project_submission)
edit_lesson_project_submission_path(project_submission.lesson, project_submission)
end
end
end
2 changes: 1 addition & 1 deletion app/components/project_submissions/like_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= turbo_frame_tag dom_id(project_submission, :likes) do %>
<%= button_to project_submission_v2_like_path(project_submission), method: http_action, disabled: current_users_submission, class: "mr-4 flex items-center #{'hint--top' unless current_users_submission}", data: { test_id: 'like-submission' }, aria: { label: 'Like submission' } do %>
<%= button_to project_submission_like_path(project_submission), method: http_action, disabled: current_users_submission, class: "mr-4 flex items-center #{'hint--top' unless current_users_submission}", data: { test_id: 'like-submission' }, aria: { label: 'Like submission' } do %>
<span class="mr-1 text-sm text-gray-500 dark:text-gray-300" data-test-id="like-count"><%= project_submission.cached_votes_total %></span>
<%= inline_svg_tag 'icons/heart.svg', class: "h-5 w-5 #{bg_color_class}", aria: true, title: 'heart', desc: 'heart icon' %>
<% end %>
Expand Down
78 changes: 63 additions & 15 deletions app/controllers/lessons/project_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,89 @@ module Lessons
class ProjectSubmissionsController < ApplicationController
before_action :authenticate_user!
before_action :set_lesson
before_action :check_if_project_submitable
before_action :can_add_solution

def index
@user_submission = user_submission
@current_user_submission = current_user.project_submissions.find_by(lesson: @lesson)
@pagy, @project_submissions = pagy_array(project_submissions_query, items: params.fetch(:limit, 15))
end

@pagy, @project_submissions = pagy(public_project_submissions, items: 15)
def new
@project_submission = current_user.project_submissions.new(lesson: @lesson)
end

private
def edit
@project_submission = current_user.project_submissions.find(params[:id])
end

def user_submission
submission = project_submissions_query.current_user_submission
def create
@project_submission = current_user.project_submissions.new(project_submission_params.merge(lesson: @lesson))

ProjectSubmissionSerializer.as_json(submission, current_user) if submission.present?
respond_to do |format|
if @project_submission.save
@project_submission.like!(current_user)

format.html { redirect_to lesson_path(@lesson), notice: 'Project submitted' }
format.turbo_stream
else
format.html { render :new, status: :unprocessable_entity }
end
end
end

def public_project_submissions
project_submissions_query.public_submissions
def update
@project_submission = current_user.project_submissions.find(params[:id])

respond_to do |format|
if @project_submission.update(project_submission_params)
format.html { redirect_to lesson_path(@lesson), notice: 'Project updated' }
format.turbo_stream
else
format.html { render :edit, status: :unprocessable_entity }
end
end
end

def destroy
@project_submission = current_user.project_submissions.find(params[:id])
@project_submission.destroy

respond_to do |format|
format.turbo_stream
end
end

private

def project_submissions_query
@project_submissions_query ||= ::LessonProjectSubmissionsQuery.new(lesson: @lesson, current_user:)
@project_submissions_query ||= ::LessonProjectSubmissionsQuery.new(
lesson: @lesson,
current_user:
)

ProjectSubmissions::MarkLiked.call(
user: current_user,
project_submissions: @project_submissions_query.public_submissions
)
end

def set_lesson
@lesson = Lesson.find(params[:lesson_id])
end

def check_if_project_submitable
def project_submission_params
params.require(:project_submission).permit(
:repo_url,
:live_preview_url,
:is_public,
:lesson_id
)
end

def can_add_solution
return if @lesson.accepts_submission?

redirect_to(
lesson_url(@lesson),
alert: 'This project does not accept submissions'
)
redirect_to lesson_url(@lesson), alert: 'This project does not accept submissions'
end
end
end
83 changes: 0 additions & 83 deletions app/controllers/lessons/v2_project_submissions_controller.rb

This file was deleted.

29 changes: 1 addition & 28 deletions app/controllers/lessons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,7 @@ def show
@lesson = Lesson.find(params[:id])

if user_signed_in?
mark_completed
@project_submissions = public_project_submissions
@user_submission = current_user_submission
Courses::MarkCompletedLessons.call(user: current_user, lessons: Array(@lesson))
end
end

private

def public_project_submissions
project_submissions_query.public_submissions.map do |submission|
ProjectSubmissionSerializer.as_json(submission, current_user) if submission.present?
end
end

def current_user_submission
submission = project_submissions_query.current_user_submission

ProjectSubmissionSerializer.as_json(submission, current_user) if submission.present?
end

def project_submissions_query
::LessonProjectSubmissionsQuery.new(lesson: @lesson, current_user:, limit: 10)
end

def mark_completed
Courses::MarkCompletedLessons.call(
user: current_user,
lessons: Array(@lesson)
)
end
end
6 changes: 1 addition & 5 deletions app/controllers/project_submissions/flags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def set_project_submission
end

def flag_params
if Feature.enabled?(:v2_project_submissions, current_user)
params.require(:flag).permit(:reason).merge(flagger: current_user)
else
params.permit(:reason).merge(flagger: current_user)
end
params.require(:flag).permit(:reason).merge(flagger: current_user)
end

def notify_discord_admins
Expand Down
18 changes: 12 additions & 6 deletions app/controllers/project_submissions/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ class ProjectSubmissions::LikesController < ApplicationController
before_action :authenticate_user!

def create
@project_submission = ProjectSubmission.find(params[:submission_id])
@project_submission = ProjectSubmission.find(params[:project_submission_id])
@project_submission.like!(current_user)

if params[:is_liked_by_current_user]
@project_submission.unliked_by current_user
else
@project_submission.liked_by current_user
respond_to do |format|
format.turbo_stream
end
end

def destroy
@project_submission = ProjectSubmission.find(params[:project_submission_id])
@project_submission.unlike!(current_user)

render json: ProjectSubmissionSerializer.as_json(@project_submission, current_user), status: :ok
respond_to do |format|
format.turbo_stream { render :create }
end
end
end
21 changes: 0 additions & 21 deletions app/controllers/project_submissions/v2_likes_controller.rb

This file was deleted.

43 changes: 0 additions & 43 deletions app/controllers/project_submissions_controller.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/javascript/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@import "tailwindcss/utilities";

@import './stylesheets/buttons.css';
@import './stylesheets/icons.css';
@import './stylesheets/layout.css';
@import './stylesheets/typography.css';
@import './stylesheets/buttons.css';
Expand Down

This file was deleted.

Loading

0 comments on commit 648ae2d

Please sign in to comment.