From c6c88456cfa94fe68bd719103e41d660e0899406 Mon Sep 17 00:00:00 2001
From: tracer <tracer@24unix.net>
Date: Sat, 29 Oct 2022 14:26:42 +0200
Subject: [PATCH] keep sort order when changing the column, only revert in same
 colum

---
 public/assets/js/functions.js | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/public/assets/js/functions.js b/public/assets/js/functions.js
index 0b88136..854a63f 100644
--- a/public/assets/js/functions.js
+++ b/public/assets/js/functions.js
@@ -98,16 +98,29 @@ function sortBy(column) {
         document.getElementById(title).innerHTML = upCase(title)
     )
 
-    // switch direction on every call
+    console.log("col", column)
+    console.log("curcol", currentColumn)
+
+    if (currentColumn === column) {
+        console.log("in switch")
+        // switch direction on every call on same column
+        if (currentSortOrder === 'asc') {
+            currentSortOrder = 'desc'
+        } else {
+            currentSortOrder = 'asc'
+        }
+        console.log("col", column)
+    } else {
+        currentColumn = column
+    }
+
     let currentTitleElement = document.getElementById(column)
     let currentTitle = currentTitleElement.innerHTML
-
     let newTitle
+
     if (currentSortOrder === 'asc') {
-        currentSortOrder = 'desc'
         newTitle = currentTitle[0] + currentTitle.substring(1) + '&nbsp;&#11015;'
     } else {
-        currentSortOrder = 'asc'
         newTitle = currentTitle[0] + currentTitle.substring(1) + '&nbsp;&#11014;'
     }
     currentTitleElement.innerHTML = newTitle
@@ -183,6 +196,7 @@ function closeError() {
 
 // global scope
 let currentSortOrder = 'desc'
+let currentColumn = 'last'
 
 document.addEventListener('DOMContentLoaded', () => {
     const table = document.getElementById('address_table') || false