diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb
index bbd5c9c..6a085eb 100644
--- a/app/controllers/units_controller.rb
+++ b/app/controllers/units_controller.rb
@@ -20,7 +20,7 @@ class UnitsController < ApplicationController
@unit = current_user.units.new(unit_params)
if @unit.save
flash[:notice] = t(".success")
- redirect_to units_url
+ @units = current_user.units
else
render :new
end
diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb
index 50a8cec..c1a9298 100644
--- a/app/views/units/_form.html.erb
+++ b/app/views/units/_form.html.erb
@@ -1,21 +1,22 @@
-<%= fields_for unit do |form| %>
+<%= fields_for @unit do |form| %>
<%= form.text_field :symbol, form: :unit_form, required: true, autofocus: true, size: 10,
- maxlength: unit.class.columns_hash['symbol'].limit, autocomplete: "off" %>
+ maxlength: @unit.class.columns_hash['symbol'].limit, autocomplete: "off" %>
|
<%= form.text_field :name, form: :unit_form, size: 25,
- maxlength: unit.class.columns_hash['name'].limit, autocomplete: "off" %>
+ maxlength: @unit.class.columns_hash['name'].limit, autocomplete: "off" %>
|
- <% unless unit.base.nil? %>
+ <% unless @unit.base.nil? %>
<%= form.number_field :multiplier, form: :unit_form, step: "any", size: 10,
autocomplete: "off" %>
<% end %>
|
- <%= form.submit unit.persisted? ? t(:update) : t(:add), form: :unit_form %>
+ <%= form.submit @unit.persisted? ? t(:update) : t(:add), form: :unit_form,
+ onclick: 'focusAddLink(event);' %>
<%= image_link_to t(:cancel), "close-circle-outline", units_path, class: 'dangerous',
onclick: 'closeForm(event); return false;' %>
|
@@ -25,6 +26,10 @@
<%= javascript_tag do %>
function closeForm(event) {
event.target.closest("tr").replaceChildren();
+ focusAddLink(event);
+ }
+
+ function focusAddLink(event) {
var add_unit_link = document.querySelector("a#add_unit");
add_unit_link.style.visibility = "visible";
add_unit_link.focus({ focusVisible: true });
diff --git a/app/views/units/_index.html.erb b/app/views/units/_index.html.erb
new file mode 100644
index 0000000..fc0ad52
--- /dev/null
+++ b/app/views/units/_index.html.erb
@@ -0,0 +1,17 @@
+
+
+<% Unit.each_with_level(@units) do |unit, level| %>
+
+
+ <%= link_to unit.symbol, edit_unit_path(unit), class: level > 0 ? 'subunit' : '' %>
+ |
+ <%= unit.name %> |
+ <%= scientifize(unit.multiplier) unless unit.multiplier == 1 %> |
+ <% if current_user.at_least(:active) %>
+
+ <%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
+ method: :delete %>
+ |
+ <% end %>
+
+<% end %>
diff --git a/app/views/units/create.turbo_stream.erb b/app/views/units/create.turbo_stream.erb
new file mode 100644
index 0000000..8e8c344
--- /dev/null
+++ b/app/views/units/create.turbo_stream.erb
@@ -0,0 +1,3 @@
+<%= turbo_stream.update :units do %>
+ <%= render partial: 'index' %>
+<% end %>
diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb
index a4f3c0e..0a7f8a0 100644
--- a/app/views/units/index.html.erb
+++ b/app/views/units/index.html.erb
@@ -9,7 +9,7 @@
<%= turbo_frame_tag 'unit_form_frame' %>
-
+
<%= User.human_attribute_name(:symbol).capitalize %> |
@@ -20,23 +20,7 @@
<% end %>
-
-
-
- <% Unit.each_with_level(@units) do |unit, level| %>
-
-
- <%= link_to unit.symbol, edit_unit_path(unit), class: level > 0 ? 'subunit' : '' %>
- |
- <%= unit.name %> |
- <%= scientifize(unit.multiplier) unless unit.multiplier == 1 %> |
- <% if current_user.at_least(:active) %>
-
- <%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
- method: :delete %>
- |
- <% end %>
-
- <% end %>
+
+ <%= render partial: 'index' %>
diff --git a/app/views/units/new.turbo_stream.erb b/app/views/units/new.turbo_stream.erb
index 9b5cb5b..15692a3 100644
--- a/app/views/units/new.turbo_stream.erb
+++ b/app/views/units/new.turbo_stream.erb
@@ -1,5 +1,5 @@
<%= turbo_stream.update @unit do %>
- <%= render partial: 'form', locals: {unit: @unit} %>
+ <%= render partial: 'form' %>
<% end %>
<%= turbo_stream.update :unit_form_frame do %>