Table notifications

This commit is contained in:
Trevor Vallender 2024-06-14 08:39:38 +01:00
parent 2002651e8a
commit c5435ac412
7 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,7 @@
--secondary-text-color: #777; --secondary-text-color: #777;
--inset-bg-color: #eee; --inset-bg-color: #eee;
--notification-bg-color: #eee;
--border-radius: .5em; --border-radius: .5em;

View File

@ -0,0 +1,13 @@
#table-notifications {
position: fixed;
width: 60em;
max-width: 80%;
top: 1em; left: 0;
transform: translate(calc(50vw - 50%));
li {
background-color: var(--notification-bg-color);
list-style-type: none;
padding: .5em;
border-radius: var(--border-radius);
}
}

View File

@ -0,0 +1,9 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
setTimeout(() => {
this.element.remove()
}, 5000)
}
}

View File

@ -9,6 +9,8 @@ class DiceRoll < ApplicationRecord
after_create_commit do after_create_commit do
broadcast_append_to table, target: "events" broadcast_append_to table, target: "events"
broadcast_append_to table, target: "table-notifications",
partial: "shared/notification", locals: { object: self }
end end
def display_text def display_text

View File

@ -14,6 +14,7 @@
<body> <body>
<header> <header>
<%= yield(:header_content) if content_for?(:header_content) %>
<h1><%= link_to t("site_name"), root_path %></h1> <h1><%= link_to t("site_name"), root_path %></h1>
<nav> <nav>
<ul> <ul>

View File

@ -1,3 +1,7 @@
<%= content_for :header_content do %>
<ul id="table-notifications"></ul>
<% end %>
<% content_for :submenu do %> <% content_for :submenu do %>
<%= turbo_stream_from @table %> <%= turbo_stream_from @table %>
<h2><%= @table.name %></h2> <h2><%= @table.name %></h2>

View File

@ -0,0 +1,3 @@
<div data-controller="notifications">
<%= render object %>
</div>