Skip to content

Commit 3661b2d

Browse files
Add localstore trigger to remember alert closed
1 parent f6fd8b8 commit 3661b2d

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/assets/js/main.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import "../css/main.css";
22

33
document.addEventListener("DOMContentLoaded", function () {
4-
document
5-
.querySelector(".rvo-alert .rvo-button__close")
6-
.addEventListener("click", function (event) {
7-
const parrent = event.target.closest(".rvo-alert");
8-
parrent.style.display = "none";
4+
document.querySelectorAll(".rvo-alert").forEach(function (alertDiv) {
5+
const closeButton = alertDiv.querySelector(".rvo-button__close");
6+
const alertId = alertDiv.getAttribute("data-alert-id");
7+
8+
if (localStorage.getItem(`alertClosed-${alertId}`) === "true") {
9+
alertDiv.style.display = "none";
10+
}
11+
12+
closeButton.addEventListener("click", function (event) {
13+
alertDiv.style.display = "none";
14+
15+
// Set a localStorage item to remember the alert is closed
16+
localStorage.setItem(`alertClosed-${alertId}`, "true");
917
});
18+
});
1019
});

src/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
<div
3434
class="rvo-max-width-layout rvo-max-width-layout--md rvo-min-width-layout--sm"
3535
>
36-
<div class="rvo-alert rvo-alert--info rvo-alert--padding-md">
36+
<div
37+
class="rvo-alert rvo-alert--info rvo-alert--padding-md"
38+
data-alert-id="index-poc-alert"
39+
>
3740
<span
3841
class="utrecht-icon rvo-icon rvo-icon-info rvo-icon--xl rvo-status-icon-info"
3942
role="img"

webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ module.exports = {
4949
filename: "assets/images/[name][ext][query]",
5050
},
5151
},
52+
{
53+
test: /\.(woff|woff2|eot|ttf|otf)$/i,
54+
type: "asset/resource",
55+
generator: {
56+
filename: "assets/fonts/[name][ext][query]",
57+
},
58+
},
5259
],
5360
},
5461
optimization: {

0 commit comments

Comments
 (0)