Add Stimulus controller for announcements
This commit is contained in:
parent
13bd043722
commit
3b1f15ebb9
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
.announcement__container
|
.announcement__container
|
||||||
- @active_announcements.each do |announcement|
|
- @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
|
.container
|
||||||
%button.close{ type: :button, data: { dismiss: :alert } }
|
%button.close{ type: :button, data: { dismiss: :alert, action: "click->announcement#close" } }
|
||||||
%span{ aria: { hidden: true } } ×
|
%span{ aria: { hidden: true } } ×
|
||||||
%p
|
%p
|
||||||
= announcement.content
|
= announcement.content
|
||||||
|
|
Loading…
Reference in New Issue