Highlight errors
This commit is contained in:
@@ -54,4 +54,8 @@
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
.has-error .terminal__input {
|
||||
border: 2px solid red;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ class CommandsController < ApplicationController
|
||||
@commands = Current.user.commands.order(created_at: :desc).limit(20)
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
command = parse_command(params[:command])
|
||||
|
||||
if command
|
||||
if command&.valid?
|
||||
result = command.execute
|
||||
|
||||
case result
|
||||
@@ -16,7 +20,7 @@ class CommandsController < ApplicationController
|
||||
redirect_back_or_to root_path
|
||||
end
|
||||
else
|
||||
raise "Pending to handle invalid commands"
|
||||
render turbo_stream: turbo_stream.replace("commands_form", partial: "commands/form", locals: { error: true })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +28,6 @@ class CommandsController < ApplicationController
|
||||
def parse_command(string)
|
||||
Command::Parser.new(parsing_context).parse(string).tap do |command|
|
||||
Current.user.commands << command
|
||||
command.validate!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<% has_error = local_assigns.fetch(:error, false) %>
|
||||
|
||||
<%= form_tag commands_path,
|
||||
id: "commands_form",
|
||||
class: [ "flex align-center gap-half", { "has-error" => has_error } ],
|
||||
data: { controller: "form", action: "turbo:submit-end->form#reset" } do %>
|
||||
<label class="terminal__label txt-nowrap" for="fizzy_do">Fizzy do ></label>
|
||||
|
||||
<%= text_field_tag "command", has_error ? params[:command] : nil,
|
||||
autocomplete: "off",
|
||||
autocorrect: "off",
|
||||
autocapitalize: "off",
|
||||
class: "terminal__input input fill-transparent unpad",
|
||||
data: {
|
||||
commands_target: "input",
|
||||
action: "keydown.up->toggle-class#add:prevent keydown.down->toggle-class#remove:prevent"
|
||||
},
|
||||
placeholder: "Search or type commands…" %>
|
||||
<% end %>
|
||||
|
||||
@@ -3,22 +3,6 @@
|
||||
toggle_class_toggle_class: "terminal--open" } do %>
|
||||
<%= turbo_frame_tag :recent_commands, src: commands_path, refresh: "morph" %>
|
||||
|
||||
<%= form_tag commands_path,
|
||||
class: "flex align-center gap-half",
|
||||
data: { controller: "form", action: "turbo:submit-end->form#reset" } do %>
|
||||
<label class="terminal__label txt-nowrap" for="fizzy_do">Fizzy do ></label>
|
||||
|
||||
<%= text_field_tag "command", nil,
|
||||
autocomplete: "off",
|
||||
autocorrect: "off",
|
||||
autocapitalize: "off",
|
||||
class: "terminal__input input fill-transparent unpad",
|
||||
data: {
|
||||
turbo_permanent: true,
|
||||
commands_target: "input",
|
||||
action: "keydown.up->toggle-class#add:prevent keydown.down->toggle-class#remove:prevent"
|
||||
},
|
||||
placeholder: "Search or type commands…" %>
|
||||
<% end %>
|
||||
<%= render "commands/form" %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user