Add Stimulus controller for announcements

This commit is contained in:
Andreas Nedbal 2022-11-23 21:00:49 +01:00
parent 13bd043722
commit 3b1f15ebb9
2 changed files with 21 additions and 2 deletions

View File

@ -0,0 +1,19 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static values = {
id: Number
};
declare readonly idValue: number;
connect(): void {
if (!window.localStorage.getItem(`announcement${this.idValue}`)) {
this.element.classList.remove('d-none');
}
}
close(): void {
window.localStorage.setItem(`announcement${this.idValue}`, 'true');
}
}

View File

@ -1,8 +1,8 @@
.announcement__container
- @active_announcements.each do |announcement|
.alert.announcement.alert-info.alert-dismissable.d-none{ data: { 'announcement-id': announcement.id } }
.alert.announcement.alert-info.alert-dismissable.d-none{ data: { controller: 'announcement', "announcement-id-value": announcement.id } }
.container
%button.close{ type: :button, data: { dismiss: :alert } }
%button.close{ type: :button, data: { dismiss: :alert, action: "click->announcement#close" } }
%span{ aria: { hidden: true } } ×
%p
= announcement.content