aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts/main.js')
-rw-r--r--public/javascripts/main.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/public/javascripts/main.js b/public/javascripts/main.js
index d2b60ff..2dc4fe3 100644
--- a/public/javascripts/main.js
+++ b/public/javascripts/main.js
@@ -58,8 +58,13 @@ function changeFav (isFav) {
updateFavNode()
}
+function usersEqual (user1, user2) {
+ if (user1 == null || user2 == null) return false
+ return user1.type === user2.type && user1.index === user2.index
+}
+
function updateFavNode () {
- if (getCurrentFav() === selectedUser) {
+ if (usersEqual(getCurrentFav(), selectedUser)) {
favNode.innerHTML = ''
} else {
favNode.innerHTML = '&#xE83A'
@@ -108,8 +113,8 @@ searchNode.addEventListener('input', function (e) {
searchNode.addEventListener('submit', submitForm)
function submitForm (e) {
- if (results == null) return
if (e) e.preventDefault()
+ if (results == null) return
const indexInResult = selectedResult === -1 ? 0 : selectedResult
selectedUser = users[results[indexInResult].index]
@@ -186,7 +191,7 @@ searchNode.addEventListener('blur', function (e) {
})
favNode.addEventListener('click', function () {
- if (getCurrentFav() === selectedUser) {
+ if (usersEqual(getCurrentFav(), selectedUser)) {
changeFav(false)
} else {
changeFav(true)