diff --git a/app/javascript/retrospring/controllers/announcement_controller.ts b/app/javascript/retrospring/controllers/announcement_controller.ts new file mode 100644 index 00000000..ee062b23 --- /dev/null +++ b/app/javascript/retrospring/controllers/announcement_controller.ts @@ -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'); + } +} diff --git a/app/views/shared/_announcements.html.haml b/app/views/shared/_announcements.html.haml index 96fcca85..ab0d70ac 100644 --- a/app/views/shared/_announcements.html.haml +++ b/app/views/shared/_announcements.html.haml @@ -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