Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Hotwire submissions add and delete flow #3925

Merged
merged 1 commit into from
Jul 10, 2023
Merged
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
4 changes: 3 additions & 1 deletion app/controllers/lessons/v2_project_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def destroy
@project_submission = current_user.project_submissions.find(params[:id])
@project_submission.destroy

render turbo_stream: turbo_stream.remove(@project_submission)
respond_to do |format|
format.turbo_stream
end
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/views/lessons/v2_project_submissions/_add_button.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= link_to new_lesson_v2_project_submission_path(@lesson), class: 'button button--primary', data: { turbo_frame: 'modal', test_id: 'add_submission_btn' } do %>
Add submission
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<%= render ProjectSubmissions::ItemComponent.new(project_submission: @project_submission, current_user: current_user) %>
<% end %>

<%= turbo_stream.remove "add-submission-button" %>
<%= turbo_stream.update "add-submission-button", "" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_stream.remove @project_submission %>

<%= turbo_stream.update "add-submission-button" do %>
<%= render "lessons/v2_project_submissions/add_button", lesson: @lesson %>
<% end %>
4 changes: 3 additions & 1 deletion app/views/lessons/v2_project_submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
</h4>
</div>
<% if @current_user_submission.nil? %>
<%= link_to 'Add solution', new_lesson_v2_project_submission_path(@lesson), id: 'add-submission-button', class: 'button button--primary', data: { turbo_frame: 'modal', test_id: 'add_submission_btn' } %>
<div id="add-submission-button">
<%= render 'lessons/v2_project_submissions/add_button', lesson: @lesson %>
</div>
<% end %>
</header>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
expect(page).to have_content(user.username)
end

expect(page).not_to have_content('Add submission')

using_session('another_user') do
sign_in(another_user)
visit lesson_path(lesson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
end
end

expect(page).to have_content('Add submission')

within(:test_id, 'submissions-list') do
expect(page).not_to have_content(user.username)
end
Expand Down