Skip to content

Commit 3cdce3d

Browse files
committed
save progress
1 parent fc067dc commit 3cdce3d

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

app/controllers/job_applications_controller.rb

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
class JobApplicationsController < ApplicationController
2-
before_action :set_job_application, only: [:edit, :update, :destroy]
2+
include ActionView::RecordIdentifier
3+
before_action :set_job_application, only: [:update, :destroy]
34

45
def index
56
@job_applications = filter_and_sort_job_applications
67
@job_application_count = @job_applications.count
7-
@job_applications = @job_applications.paginate(page: params[:page], per_page: 10).order(created_at: :desc)
8+
@job_applications = @job_applications.order(created_at: :desc).paginate(page: params[:page], per_page: 10)
89

910
@pagination_info = {
1011
current_page: @job_applications.current_page,
@@ -29,10 +30,6 @@ def new
2930
end
3031

3132
def edit
32-
respond_to do |format|
33-
format.html
34-
format.turbo_stream { render turbo_stream: turbo_stream.replace(dom_id(@job_application), partial: "form", locals: {job_application: @job_application, title: "Edit"}) }
35-
end
3633
end
3734

3835
def create
@@ -41,22 +38,18 @@ def create
4138
respond_to do |format|
4239
if @job_application.save
4340
format.html { redirect_to root_path, notice: "Job application was successfully created." }
44-
format.turbo_stream {
45-
flash.now[:notice] = "Job application was successfully created."
46-
render turbo_stream: [
47-
turbo_stream.prepend("job_applications", partial: "job_application", locals: {job_application: @job_application}),
48-
turbo_stream.update("job_application_count", JobApplication.count),
49-
turbo_stream.update("flash_messages", partial: "flash_messages")
50-
]
51-
}
41+
format.turbo_stream do
42+
render turbo_stream: turbo_stream.redirect_advanced(root_path)
43+
flash[:notice] = "Job application was successfully created."
44+
end
5245
else
5346
format.html { render :new, status: :unprocessable_entity }
54-
format.turbo_stream {
47+
format.turbo_stream do
5548
render turbo_stream: [
5649
turbo_stream.replace("new_job_application", partial: "form", locals: {job_application: @job_application, title: "New"}),
5750
turbo_stream.update("flash_messages", partial: "flash_messages")
5851
]
59-
}
52+
end
6053
end
6154
end
6255
end
@@ -65,21 +58,12 @@ def update
6558
respond_to do |format|
6659
if @job_application.update(job_application_params)
6760
format.html { redirect_to root_path, notice: "Job application was successfully updated." }
68-
format.turbo_stream {
69-
flash.now[:notice] = "Job application was successfully updated."
70-
render turbo_stream: [
71-
turbo_stream.replace(@job_application, partial: "job_application", locals: {job_application: @job_application}),
72-
turbo_stream.update("flash_messages", partial: "flash_messages")
73-
]
74-
}
61+
format.turbo_stream do
62+
render turbo_stream: turbo_stream.redirect_advanced(root_path)
63+
flash[:notice] = "Job application was successfully updated."
64+
end
7565
else
7666
format.html { render :edit, status: :unprocessable_entity }
77-
format.turbo_stream {
78-
render turbo_stream: [
79-
turbo_stream.replace(dom_id(@job_application), partial: "form", locals: {job_application: @job_application, title: "Edit"}),
80-
turbo_stream.update("flash_messages", partial: "flash_messages")
81-
]
82-
}
8367
end
8468
end
8569
end

app/frontend/controllers/flash_message_controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class extends Controller {
1111
this.element.classList.remove('hidden');
1212
setTimeout(() => {
1313
this.fadeOut();
14-
}, 2000); // Start fading out after 4 seconds
14+
}, 2000);
1515
}
1616

1717
fadeOut() {
@@ -20,7 +20,7 @@ export default class extends Controller {
2020
flashMessage.classList.add('fade-out');
2121
setTimeout(() => {
2222
this.element.classList.add('hidden');
23-
}, 500); // Duration of fade-out animation
23+
}, 500);
2424
}
2525
}
2626
}

app/frontend/entrypoints/application.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "~/controllers";
2-
import "@hotwired/turbo-rails";
2+
import { Turbo } from "@hotwired/turbo-rails"
33
// To see this message, add the following to the `<head>` section in your
44
// views/layouts/application.html.erb
55
//
@@ -20,7 +20,7 @@ console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify
2020

2121
Turbo.start();
2222

23-
document.addEventListener("turbo:load", function () {
23+
document.addEventListener("turbo:load", () => {
2424
console.log("turbo:load");
2525
});
2626
//
@@ -32,3 +32,9 @@ document.addEventListener("turbo:load", function () {
3232

3333
// Example: Import a stylesheet in app/frontend/index.css
3434
// import '~/index.css'
35+
36+
Turbo.StreamActions.redirect_advanced = function () {
37+
const url = this.getAttribute('url') || '/'
38+
// Turbo.visit(url, { frame: '_top', action: 'advance' })
39+
Turbo.visit(url)
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module TurboStreamActionsHelper
2+
# render turbo_stream: turbo_stream.redirect_advanced(projects_path)
3+
def redirect_advanced(url)
4+
turbo_stream_action_tag :redirect_advanced, url: url
5+
end
6+
end
7+
8+
Turbo::Streams::TagBuilder.prepend(TurboStreamActionsHelper)
Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
<div id="flash_messages">
2-
<%= render 'flash_messages' %>
3-
</div>
4-
<div class="my-2 md:my-8">
5-
<div class="mb-8 flex justify-between items-center">
6-
<h2 class="hidden md:block md:text-2xl font-semibold text-gray-700 shadow-2xl">
7-
Job Tracker
8-
</h2>
9-
<%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %>
1+
<%= turbo_frame_tag "job_applications_index" do %>
2+
<div id="flash_messages">
3+
<%= render 'flash_messages' %>
104
</div>
11-
<%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %>
12-
<div class="flex flex-wrap -mx-2 mb-4">
13-
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
14-
<%= form.label :search, "Search", class: "sr-only" %>
15-
<%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search by company or position", data: { action: "input->job-filter#submit" } %>
16-
</div>
17-
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
18-
<%= form.label :method_of_contact, "Contact Method", class: "sr-only" %>
19-
<%= form.select :method_of_contact,
5+
<div class="my-2 md:my-8">
6+
<div class="mb-8 flex justify-between items-center">
7+
<h2 class="hidden md:block md:text-2xl font-semibold text-gray-700 shadow-2xl">
8+
Job Tracker
9+
</h2>
10+
<%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %>
11+
</div>
12+
<%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %>
13+
<div class="flex flex-wrap -mx-2 mb-4">
14+
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
15+
<%= form.label :search, "Search", class: "sr-only" %>
16+
<%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search by company or position", data: { action: "input->job-filter#submit" } %>
17+
</div>
18+
<div class="w-full md:w-1/4 px-2 mb-4 md:mb-0">
19+
<%= form.label :method_of_contact, "Contact Method", class: "sr-only" %>
20+
<%= form.select :method_of_contact,
2021
options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]),
2122
{},
2223
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
2324
data: { action: "change->job-filter#submit" }
2425
%>
25-
</div>
26-
<div class="w-full md:w-1/4 px-2">
27-
<%= form.label :position_type, "Position Type", class: "sr-only" %>
28-
<%= form.select :position_type,
26+
</div>
27+
<div class="w-full md:w-1/4 px-2">
28+
<%= form.label :position_type, "Position Type", class: "sr-only" %>
29+
<%= form.select :position_type,
2930
options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [k.humanize, v] }, params[:position_type]),
3031
{},
3132
class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",
3233
data: { action: "change->job-filter#submit" }
3334
%>
35+
</div>
36+
<div class="w-full md:w-1/4 px-2 mt-4 md:mt-0">
37+
<%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %>
38+
</div>
3439
</div>
35-
<div class="w-full md:w-1/4 px-2 mt-4 md:mt-0">
36-
<%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %>
40+
<% end %>
41+
<%= turbo_frame_tag "job_applications_table" do %>
42+
<%= render partial: "job_applications_table", locals: { job_applications: @job_applications } %>
43+
<div id="pagination" class="mt-4">
44+
<%= render partial: "pagination", locals: { job_applications: @job_applications, job_application_count: @job_application_count } %>
3745
</div>
38-
</div>
39-
<% end %>
40-
<%= turbo_frame_tag "job_applications_table" do %>
41-
<%= render partial: "job_applications_table", locals: { job_applications: @job_applications } %>
42-
<div id="pagination" class="mt-4">
43-
<%= render partial: "pagination", locals: { job_applications: @job_applications, job_application_count: @job_application_count } %>
44-
</div>
45-
<% end %>
46-
<%= turbo_frame_tag "new_job_application" %>
47-
</div>
46+
<% end %>
47+
<%= turbo_frame_tag "new_job_application" %>
48+
</div>
49+
<% end %>

0 commit comments

Comments
 (0)