Skip to content

Commit

Permalink
Fix dialog closing and update wording
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 3, 2024
1 parent 417fb49 commit e9e97c8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/assets/builds/rosetta/application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["dialog", "title", "titleSource", "content"];
static targets = ["dialog", "content", "title", "titleSource", "turboFrame"];

open(e) {
e.preventDefault();
const link = e.currentTarget;
this.dialogTarget.showModal();
this.loadingIndicator = this.contentTarget.innerHTML;
this.contentTarget.src = link.href;
this.turboFrameTarget.src = link.href;
}

safeClose(e) {
Expand All @@ -27,7 +27,7 @@ export default class extends Controller {
}

resetContent() {
this.contentTarget.innerHTML = this.loadingIndicator;
this.turboFrameTarget.innerHTML = this.loadingIndicator;
this.setTitle("");
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/rosetta/locales_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Rosetta
class LocalesController < ApplicationController
def index
@locales = [ Locale.default ] + Locale.all
@locales = [ Locale.default_locale ] + Locale.all
end

def new
Expand Down
11 changes: 6 additions & 5 deletions app/models/rosetta/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ class Locale < ApplicationRecord

validates :name, :code, presence: true
validates :code, uniqueness: true
# TODO: make sure one cannot add the default locale twice
validates :code, format: { with: CODE_FORMAT, message: "must only contain letters separated by an optional dash" }

class << self
def available_locales
all # .published
[ Locale.default ] + all # .published
end

# The default locale is the locale in which the application is written.
# Default is english.
# TODO: Make this configurable.
def default
@default ||= new(name: "English", code: "en").as_default
def default_locale
@default_locale ||= new(name: "English", code: "en").as_default
end
end

def default_locale?
@default_locale ||= false
@default ||= false
end

def as_default
@default_locale = true
@default = true
self
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/rosetta/_dialog.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<dialog class="absolute max-w-4xl w-full mx-auto p-12 top-4 left-0 m-0 h-full bg-transparent" data-dialog-target="dialog" data-action="close->dialog#resetContent click->dialog#safeClose">
<div class="bg-white shadow ring-1 ring-black ring-opacity-5 max-w-xl mt-4 mx-auto rounded-lg overflow-hidden w-full">
<div class="bg-white shadow ring-1 ring-black ring-opacity-5 max-w-xl mt-4 mx-auto rounded-lg overflow-hidden w-full" data-dialog-target="content">
<div class="flex justify-between bg-gray-50 py-4 px-6 text-gray-900 font-semibold border-b border-gray-300">
<h4 data-dialog-target="title"></h4>

Expand All @@ -12,7 +12,7 @@
</div>

<div class="p-4">
<%= turbo_frame_tag "dialog_content", data: { dialog_target: "content" } do %>
<%= turbo_frame_tag "dialog_content", data: { dialog_target: "turboFrame" } do %>
<%= yield %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/models/rosetta/locale_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Rosetta::LocaleTest < ActiveSupport::TestCase
test "available locales" do
Rosetta::Locale.create(name: "English", code: "en")
Rosetta::Locale.create(name: "French", code: "fr")
assert_equal 2, Rosetta::Locale.available_locales.length
assert_equal 3, Rosetta::Locale.available_locales.length
assert_equal [ :en, :fr ], Rosetta::Locale.available_locales.pluck(:code).map(&:to_sym)
end

Expand Down

0 comments on commit e9e97c8

Please sign in to comment.