From a65e8c61ece4e29fb040c9c7f067d6e57ad22d01 Mon Sep 17 00:00:00 2001
From: echicken <echicken@bbs.electronicchicken.com>
Date: Wed, 7 Oct 2020 13:00:01 -0400
Subject: [PATCH] Make listDirectories a bit less ugly. Added libHasFiles(lib);
 returns true as soon as it encounters a dir in a lib that has any files in
 it. listLibraries() only returns libs that have populated dirs.

---
 webv4/lib/files.js | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/webv4/lib/files.js b/webv4/lib/files.js
index a4fc22ba81..ea409ba4c7 100644
--- a/webv4/lib/files.js
+++ b/webv4/lib/files.js
@@ -8,20 +8,25 @@ function count_files(dir) {
     return Math.floor(file_size(fn) / 22); // ixb record length is 22 bytes
 }
 
+function libHasFiles(lib) {
+    return lib.dir_list.some(function (e) {
+        return count_files(e.code) > 0;
+    });
+}
+
 function listLibraries() {
-	return file_area.lib_list.filter(function (library) {
-        return library.dir_list.length >= 1;
+	return file_area.lib_list.filter(function (lib) {
+        return lib.dir_list.length >= 1 && libHasFiles(lib);
     });
 }
 
-function listDirectories(library) {
-	var dirs = [];
-	file_area.lib_list[library].dir_list.forEach(function (dir) {
-        const fc = count_files(dir.code);
-        if (fc < 1) return;
-		dirs.push({ dir: dir, fileCount: fc });
-	});
-	return dirs;
+function listDirectories(lib) {
+    return file_area.lib_list[lib].dir_list.reduce(function (a, c) {
+        const fc = count_files(c.code);
+        if (fc < 1) return a;
+        a.push({ dir: c, fileCount: fc });
+        return a;
+    }, []);
 }
 
 function listFiles(dir) {
-- 
GitLab