Port announcements functionality to TypeScript

This commit is contained in:
Karina Kwiatek 2022-01-09 17:26:38 +01:00 committed by Andreas Nedbal
parent 60d8868306
commit 3e9fb2890f
4 changed files with 22 additions and 12 deletions

View File

@ -1,6 +1,7 @@
require('sweetalert/dist/sweetalert.css'); require('sweetalert/dist/sweetalert.css');
import start from 'retrospring/common'; import start from 'retrospring/common';
import initAnnouncements from 'retrospring/features/announcement/index';
import initAnswerbox from 'retrospring/features/answerbox/index'; import initAnswerbox from 'retrospring/features/answerbox/index';
import initInbox from 'retrospring/features/inbox/index'; import initInbox from 'retrospring/features/inbox/index';
import initUser from 'retrospring/features/user'; import initUser from 'retrospring/features/user';
@ -19,3 +20,4 @@ document.addEventListener('DOMContentLoaded', initLists);
document.addEventListener('DOMContentLoaded', initQuestionbox); document.addEventListener('DOMContentLoaded', initQuestionbox);
document.addEventListener('DOMContentLoaded', initQuestion); document.addEventListener('DOMContentLoaded', initQuestion);
document.addEventListener('DOMContentLoaded', initModeration); document.addEventListener('DOMContentLoaded', initModeration);
document.addEventListener('turbolinks:load', initAnnouncements)

View File

@ -51,17 +51,6 @@ _ready = ->
lineColor: bodyColor lineColor: bodyColor
density: 23000 density: 23000
$(".announcement").each ->
aId = $(this)[0].dataset.announcementId
unless (window.localStorage.getItem("announcement#{aId}"))
$(this).toggleClass("d-none")
$(document).on "click", ".announcement button.close", (evt) ->
announcement = event.target.closest(".announcement")
aId = announcement.dataset.announcementId
window.localStorage.setItem("announcement#{aId}", true)
$(document).ready _ready $(document).ready _ready
$(document).on 'turbolinks:load', _ready $(document).on 'turbolinks:load', _ready

View File

@ -0,0 +1,5 @@
export default function (event: Event): void {
const announcement = (event.target as HTMLElement).closest(".announcement") as HTMLDivElement;
const aId = announcement.dataset.announcementId;
window.localStorage.setItem(`announcement${aId}`, 'true');
}

View File

@ -0,0 +1,14 @@
import registerEvents from 'utilities/registerEvents';
import closeAnnouncementHandler from './close';
export default (): void => {
registerEvents([
{ type: 'click', target: '.announcement button.close', handler: closeAnnouncementHandler, global: true },
]);
document.querySelectorAll('.announcement').forEach(function (el: HTMLDivElement) {
if (!window.localStorage.getItem(el.dataset.announcementId)) {
el.classList.remove('d-none');
}
});
}