feat: added navbar

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2023-02-04 14:22:05 +01:00
parent e54a3814c1
commit 1ab28933e7
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283
12 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,9 @@
class CountChannel < ApplicationCable::Channel
def subscribed
# stream_from "some_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end

View File

@ -2,3 +2,4 @@
import "@hotwired/turbo-rails" import "@hotwired/turbo-rails"
import "./controllers" import "./controllers"
import * as bootstrap from "bootstrap" import * as bootstrap from "bootstrap"
import "./channels"

View File

@ -0,0 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
import { createConsumer } from "@rails/actioncable"
export default createConsumer()

View File

@ -0,0 +1,16 @@
import consumer from "./consumer"
consumer.subscriptions.create("CountChannel", {
connected() {
// Called when the subscription is ready for use on the server
console.warn("Connected to CountChannel.");
},
disconnected() {
// Called when the subscription has been terminated by the server
},
received(data) {
// Called when there's incoming data on the websocket for this channel
}
});

View File

@ -0,0 +1,2 @@
// Import all the channels to be used by Action Cable
import "./count_channel"

View File

@ -11,7 +11,24 @@
</head> </head>
<body> <body>
<header class="p-3 text-bg-dark">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><%= link_to t("fields.home"), root_path, class: "nav-link px-2 text-secondary" %></li>
</ul>
<div class="text-end">
<% if current_user %>
<%= button_to t("fields.logout"), destroy_user_session_path, method: "delete", class: "btn btn-danger me-2" %>
<% else %>
<%= link_to t("fields.login"), new_user_session_path, class: "btn btn-outline-light me-2" %>
<% end %>
</div>
</div>
</div>
</header>
<p class="notice"><%= notice %></p> <p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p> <p class="alert"><%= alert %></p>

View File

@ -18,5 +18,9 @@ module CountAnything
# #
# config.time_zone = "Central Time (US & Canada)" # config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras") # config.eager_load_paths << Rails.root.join("extras")
I18n.available_locales = [:en, :fr]
# Set default locale to something other than :en
I18n.default_locale = :fr
end end
end end

View File

@ -0,0 +1,5 @@
en:
fields:
home: "Home"
login: "Login"
logout: "Logout"

View File

@ -0,0 +1,5 @@
fr:
fields:
home: "Accueil"
login: "Se connecter"
logout: "Se déconnecter"

View File

@ -5,6 +5,7 @@
"@hotwired/stimulus": "^3.2.1", "@hotwired/stimulus": "^3.2.1",
"@hotwired/turbo-rails": "^7.2.5", "@hotwired/turbo-rails": "^7.2.5",
"@popperjs/core": "^2.11.6", "@popperjs/core": "^2.11.6",
"@rails/actioncable": "^7.0.4-2",
"bootstrap": "^5.2.3", "bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.3", "bootstrap-icons": "^1.10.3",
"esbuild": "^0.17.5", "esbuild": "^0.17.5",

View File

@ -0,0 +1,8 @@
require "test_helper"
class CountChannelTest < ActionCable::Channel::TestCase
# test "subscribes" do
# subscribe
# assert subscription.confirmed?
# end
end

View File

@ -140,6 +140,11 @@
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-7.0.4.tgz#70a3ca56809f7aaabb80af2f9c01ae51e1a8ed41" resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-7.0.4.tgz#70a3ca56809f7aaabb80af2f9c01ae51e1a8ed41"
integrity sha512-tz4oM+Zn9CYsvtyicsa/AwzKZKL+ITHWkhiu7x+xF77clh2b4Rm+s6xnOgY/sGDWoFWZmtKsE95hxBPkgQQNnQ== integrity sha512-tz4oM+Zn9CYsvtyicsa/AwzKZKL+ITHWkhiu7x+xF77clh2b4Rm+s6xnOgY/sGDWoFWZmtKsE95hxBPkgQQNnQ==
"@rails/actioncable@^7.0.4-2":
version "7.0.4-2"
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-7.0.4-2.tgz#d69d1314c5bb1c8b51f7eeef98e1db5bab80caba"
integrity sha512-mMmDa9pJczGN+bX4nPgrmu+PHqKDpokfwSLF3Sk5h6Z996miFmPAg44F2TvG7koJQQ0YFXEVeHshRXVg5jmshQ==
anymatch@~3.1.2: anymatch@~3.1.2:
version "3.1.3" version "3.1.3"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"