Skip to content

Commit

Permalink
Remember sort field, fix #103
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Sep 1, 2024
1 parent 70581a6 commit 01323c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## [v2.0.1] - 2024-08-31
### Changed
## [v2.0.1] - 2024-09-01
### Added
- Remember `sort` field

### Fixed
- Bug [#103](https://github.com/aceberg/WatchYourLAN/issues/103)

## [v2.0.0] - 2024-08-30
### Added
Expand Down
21 changes: 18 additions & 3 deletions internal/web/public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ async function loadAddrs() {
addrsArray = await (await fetch(url)).json();
bkpArray = addrsArray;

displayArrayData(addrsArray);
field = localStorage.getItem("sortField");

checkNotEmpty(addrsArray);
}

function sortBy(field) {
sortByAny(addrsArray, field);
function sortBy(f) {
field = f;
localStorage.setItem("sortField", field);
checkNotEmpty(addrsArray);
}

function editClick() {
Expand All @@ -62,6 +66,17 @@ function editClick() {
loadAddrs();
}

function checkNotEmpty(someArray) {

if (someArray.length > 0) {
if (field != null) {
sortByAny(someArray);
} else {
displayArrayData(someArray);
}
}
}

async function editForm(id, known) {

const name = document.getElementById("name"+id).value;
Expand Down
3 changes: 2 additions & 1 deletion internal/web/public/js/sort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var oldField = '';
var field = '';

function displayArrayData(someArray) {
document.getElementById('tBody').innerHTML = "";
Expand All @@ -11,7 +12,7 @@ function displayArrayData(someArray) {
}
}

function sortByAny(someArray, field) {
function sortByAny(someArray) {

if (field != oldField) {
oldField = field;
Expand Down

0 comments on commit 01323c6

Please sign in to comment.