-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Move Dashboard project solutions to Hotwire.
Because: * We are replacing our React components with Hotwire. This commit: * Adds a title slot to project submission items - we display the lesson title when on the dashboard and the solutions users name when on a lesson page. * Adds a users project submissions controller - when updating a solution from the dashboard we need to use a user specific endpoint to ensure the correct solution item is returned. * Automatically like your own project when it is created - We need to disable liking your own submissions, at least for now: * The likes endpoint needs to return a full item component at the moment to allow sorting to work. This conflicts with needing different item titles on the dashboard and lesson pages. We'll be able to enable again soon ™️. The next phase of this project is to add a sorting feature to the solutions list, we'll be able to update just the like counter when that is built. * The compromise is to automatically like your project so nobody ever has to see their project sitting at 0 - kind of like how Reddit handles new posts. * A few performance improvements by preloading lesson and user solutions when fetching solutions.
- Loading branch information
1 parent
12dd249
commit 8979109
Showing
25 changed files
with
242 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
module ProjectSubmissions | ||
class LikeComponent < ApplicationComponent | ||
def initialize(project_submission) | ||
def initialize(project_submission:, current_users_submission: false) | ||
@project_submission = project_submission | ||
@current_users_submission = current_users_submission | ||
end | ||
|
||
private | ||
|
||
attr_reader :project_submission | ||
attr_reader :project_submission, :current_users_submission | ||
|
||
def http_action | ||
project_submission.liked? ? :delete : :post | ||
end | ||
|
||
def bg_color_class | ||
project_submission.liked? ? 'text-teal-700' : 'text-gray-400' | ||
return 'text-teal-700' if current_users_submission || project_submission.liked? | ||
|
||
'text-gray-400' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% if url.present? %> | ||
<%= link_to title, url, class: 'truncate max-w-xs lgs:max-w-lg font-medium text-lg break-words hover:text-gray-800', data: { turbo_frame: '_top' } %> | ||
<% else %> | ||
<p class="truncate max-w-xs lgs:max-w-lg font-medium text-lg break-words"><%= title %></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ProjectSubmissions | ||
class TitleComponent < ApplicationComponent | ||
def initialize(title:, url: nil) | ||
@title = title | ||
@url = url | ||
end | ||
|
||
private | ||
|
||
attr_reader :title, :url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Users | ||
class ProjectSubmissionsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def edit | ||
@project_submission = current_user.project_submissions.find(params[:id]) | ||
end | ||
|
||
def update | ||
@project_submission = current_user.project_submissions.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @project_submission.update(project_submission_params) | ||
format.turbo_stream | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def project_submission_params | ||
params.require(:project_submission).permit(:repo_url, :live_preview_url, :is_public) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
app/views/lessons/v2_project_submissions/create.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render ModalComponent.new(title: 'Update your project') do %> | ||
<%= render 'lessons/v2_project_submissions/form', project_submission: @project_submission, url: lesson_v2_project_submission_path(@lesson, @project_submission) %> | ||
<%= render 'project_submissions/form', project_submission: @project_submission, url: lesson_v2_project_submission_path(@lesson, @project_submission) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render ModalComponent.new(title: 'Submit your project') do %> | ||
<%= render 'lessons/v2_project_submissions/form', project_submission: @project_submission, url: lesson_v2_project_submissions_path(@lesson) %> | ||
<%= render 'project_submissions/form', project_submission: @project_submission, url: lesson_v2_project_submissions_path(@lesson) %> | ||
<% end %> |
4 changes: 3 additions & 1 deletion
4
app/views/lessons/v2_project_submissions/update.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<%= turbo_stream.replace @project_submission do %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user:) %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user:) do |component| %> | ||
<%= component.with_title(title: current_user.username, url: dashboard_path) %> | ||
<% end %> | ||
<% end %> |
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
app/views/project_submissions/v2_likes/create.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<%= turbo_stream.replace @project_submission do %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user:) %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user:) do |component| %> | ||
<%= component.with_title(title: @project_submission.user.username) %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
<div class="mb-12"> | ||
<h2 class="text-gray-700 text-2xl font-medium text-center mb-4 dark:text-gray-300">Project Submissions</h2> | ||
|
||
<% if project_submissions.any? %> | ||
<%= react_component( | ||
'project-submissions/user-project-submissions', | ||
{ | ||
userId: current_user&.id, | ||
submissions: project_submissions.map { |submission| ProjectSubmissionSerializer.as_json(submission, current_user) }, | ||
} | ||
) %> | ||
<% if project_submissions.any? %> | ||
<% if Feature.enabled?(:v2_project_submissions, current_user) %> | ||
<div data-test-id="user-submissions-list"> | ||
<% project_submissions.each do |project_submission| %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission:, current_user:, edit_path: edit_users_project_submission_path(project_submission)) do |component| %> | ||
<%= component.with_title(title: project_submission.lesson.display_title, url: lesson_path(project_submission.lesson)) %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% else %> | ||
<h3 class="text-gray-500 text-center text-lg dark:text-gray-400">No submissions yet</h3> | ||
<%= react_component( | ||
'project-submissions/user-project-submissions', | ||
{ | ||
userId: current_user&.id, | ||
submissions: project_submissions.map { |submission| ProjectSubmissionSerializer.as_json(submission, current_user) }, | ||
} | ||
) %> | ||
<% end %> | ||
<% else %> | ||
<h3 class="text-gray-500 text-center text-lg dark:text-gray-400">No submissions yet</h3> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= render ModalComponent.new(title: 'Update your project') do %> | ||
<%= render 'project_submissions/form', project_submission: @project_submission, url: users_project_submission_path(@project_submission) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= turbo_stream.replace @project_submission do %> | ||
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user:, edit_path: edit_users_project_submission_path(@project_submission)) do |component| %> | ||
<%= component.with_title(title: @project_submission.lesson.display_title, url: lesson_path(@project_submission.lesson)) %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
spec/system/v2_user_project_submissions/delete_submission_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Deleting a Project Submission on the Dashboard' do | ||
let(:user) { create(:user) } | ||
let(:lesson) { create(:lesson, :project) } | ||
|
||
before do | ||
Flipper.enable(:v2_project_submissions) | ||
|
||
create(:project_submission, user:, lesson:) | ||
sign_in(user) | ||
visit dashboard_path | ||
end | ||
|
||
after do | ||
Flipper.disable(:v2_project_submissions) | ||
end | ||
|
||
it 'successfully deletes a submission' do | ||
sleep 0.1 # it will not open the dropdown without this | ||
within(:test_id, 'user-submissions-list') do | ||
expect(page).to have_content(lesson.title) | ||
end | ||
|
||
find(:test_id, 'submission-action-menu-btn').click | ||
|
||
page.accept_confirm do | ||
find(:test_id, 'delete-submission').click | ||
end | ||
|
||
within(:test_id, 'user-submissions-list') do | ||
expect(page).not_to have_content(lesson.title) | ||
end | ||
end | ||
end |
Oops, something went wrong.