Skip to content

Commit

Permalink
move toasts to toasts.js and add error toast
Browse files Browse the repository at this point in the history
  • Loading branch information
lavajuno committed Sep 15, 2023
1 parent d09f0c7 commit 02cba2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/resources/static/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ <h1>Edit User</h1>
<div class="" id="TOAST_MESSAGE"></div>
</body>

<script src="toast.js"></script>
<script src="editor.js"></script>
</html>
2 changes: 2 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

<input class="name_field" id="CREATE_FIELD" placeholder="new user's name...">
<button onclick="handle_create()">Create User</button>
<button onclick="display_list(refresh=true)">Refresh List</button>
</div>

<div id="TOAST_MESSAGE"></div>
</body>

<script src="toast.js"></script>
<script src="index.js"></script>
</html>
26 changes: 26 additions & 0 deletions src/main/resources/static/toast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var toast_timeout;

/* Show a regular grey toast */
function show_toast(message) {
clearTimeout(toast_timeout);
var td = document.getElementById("TOAST_MESSAGE");
td.innerHTML = message;
td.className = "show";
toast_timeout = setTimeout(hide_toast, 3000);
}

/* Show a red toast for errors */
function show_error(message) {
clearTimeout(toast_timeout);
var td = document.getElementById("TOAST_MESSAGE");
td.innerHTML = message;
td.className = "show error";
toast_timeout = setTimeout(hide_toast, 3000);
}

/* Used by show_toast,
can also be invoked manually to hide the current toast */
function hide_toast() {
var td = document.getElementById("TOAST_MESSAGE");
td.className = td.className.replace("show", "hide");
}

1 comment on commit 02cba2a

@lavajuno
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add refresh button in list

Please sign in to comment.