diff --git a/app/components/project_submissions/item_component.html.erb b/app/components/project_submissions/item_component.html.erb index 1ffcd1991c..0b01406c24 100644 --- a/app/components/project_submissions/item_component.html.erb +++ b/app/components/project_submissions/item_component.html.erb @@ -1,9 +1,9 @@
<%= project_submission.user.username %>
+<%= title %>
+<% end %> diff --git a/app/components/project_submissions/title_component.rb b/app/components/project_submissions/title_component.rb new file mode 100644 index 0000000000..6b0e534c42 --- /dev/null +++ b/app/components/project_submissions/title_component.rb @@ -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 diff --git a/app/controllers/lessons/v2_project_submissions_controller.rb b/app/controllers/lessons/v2_project_submissions_controller.rb index 6366bdd9a2..8503164ace 100644 --- a/app/controllers/lessons/v2_project_submissions_controller.rb +++ b/app/controllers/lessons/v2_project_submissions_controller.rb @@ -21,6 +21,8 @@ def create 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 diff --git a/app/controllers/users/project_submissions_controller.rb b/app/controllers/users/project_submissions_controller.rb new file mode 100644 index 0000000000..c3fa948e96 --- /dev/null +++ b/app/controllers/users/project_submissions_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b2ce9e4a93..9d7d298f75 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,5 +3,6 @@ class UsersController < ApplicationController def show @courses = current_user.path.courses + @project_submissions = current_user.project_submissions.includes(:lesson).order(created_at: :desc) end end diff --git a/app/queries/lesson_project_submissions_query.rb b/app/queries/lesson_project_submissions_query.rb index c4332c5cae..cf485c81d0 100644 --- a/app/queries/lesson_project_submissions_query.rb +++ b/app/queries/lesson_project_submissions_query.rb @@ -14,6 +14,7 @@ def current_user_submission def public_submissions lesson.project_submissions .only_public + .includes(:user) .not_removed_by_admin .where.not(user: current_user) .order(cached_votes_total: :desc, created_at: :desc) diff --git a/app/views/lessons/v2_project_submissions/create.turbo_stream.erb b/app/views/lessons/v2_project_submissions/create.turbo_stream.erb index 2b98e48237..0cf9a9e4ec 100644 --- a/app/views/lessons/v2_project_submissions/create.turbo_stream.erb +++ b/app/views/lessons/v2_project_submissions/create.turbo_stream.erb @@ -1,5 +1,7 @@ <%= turbo_stream.prepend 'submissions-list' 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 %> <%= turbo_stream.remove 'project-solutions-blank-state' %> diff --git a/app/views/lessons/v2_project_submissions/edit.html.erb b/app/views/lessons/v2_project_submissions/edit.html.erb index b89db18b18..bc0e27434f 100644 --- a/app/views/lessons/v2_project_submissions/edit.html.erb +++ b/app/views/lessons/v2_project_submissions/edit.html.erb @@ -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 %> diff --git a/app/views/lessons/v2_project_submissions/index.html.erb b/app/views/lessons/v2_project_submissions/index.html.erb index 246b55e940..0da0624a21 100644 --- a/app/views/lessons/v2_project_submissions/index.html.erb +++ b/app/views/lessons/v2_project_submissions/index.html.erb @@ -29,8 +29,15 @@ <%= turbo_frame_tag 'submissions-list', data: { test_id: 'submissions-list', controller: 'sort' } do %> <% if @lesson.project_submissions.any? %> - <%= render ProjectSubmissions::ItemComponent.new(project_submission: @current_user_submission, current_user:) %> - <%= render ProjectSubmissions::ItemComponent.with_collection(@project_submissions, current_user:) %> + <%= render ProjectSubmissions::ItemComponent.new(project_submission: @current_user_submission, current_user:) do |component| %> + <%= component.with_title(title: current_user.username, url: dashboard_path) %> + <% end %> + + <% @project_submissions.each do |project_submission| %> + <%= render ProjectSubmissions::ItemComponent.new(project_submission:, current_user:) do |component| %> + <%= component.with_title(title: project_submission.user.username) %> + <% end %> + <% end %> <% else %> <% render 'lessons/v2_project_submissions/blank_state' %> <% end %> diff --git a/app/views/lessons/v2_project_submissions/new.html.erb b/app/views/lessons/v2_project_submissions/new.html.erb index b78d1eecdb..1c872830c2 100644 --- a/app/views/lessons/v2_project_submissions/new.html.erb +++ b/app/views/lessons/v2_project_submissions/new.html.erb @@ -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 %> diff --git a/app/views/lessons/v2_project_submissions/update.turbo_stream.erb b/app/views/lessons/v2_project_submissions/update.turbo_stream.erb index 9ade4fddfe..d8d8aafc88 100644 --- a/app/views/lessons/v2_project_submissions/update.turbo_stream.erb +++ b/app/views/lessons/v2_project_submissions/update.turbo_stream.erb @@ -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 %> diff --git a/app/views/lessons/v2_project_submissions/_form.html.erb b/app/views/project_submissions/_form.html.erb similarity index 100% rename from app/views/lessons/v2_project_submissions/_form.html.erb rename to app/views/project_submissions/_form.html.erb diff --git a/app/views/project_submissions/v2_likes/create.turbo_stream.erb b/app/views/project_submissions/v2_likes/create.turbo_stream.erb index 134c5bc5ad..47744d9209 100644 --- a/app/views/project_submissions/v2_likes/create.turbo_stream.erb +++ b/app/views/project_submissions/v2_likes/create.turbo_stream.erb @@ -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 %> diff --git a/app/views/users/_project_submissions.html.erb b/app/views/users/_project_submissions.html.erb index a293844e70..5d95d33f21 100644 --- a/app/views/users/_project_submissions.html.erb +++ b/app/views/users/_project_submissions.html.erb @@ -1,15 +1,25 @@