You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/12/10 19:02:22 UTC

[incubator-ponymail-foal] 01/02: refactor calc_per_page

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 61f8ff6508096728e7d895fa60dbe19e403e5620
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Dec 10 20:02:02 2021 +0100

    refactor calc_per_page
    
    This should fix #146.
---
 webui/js/source/listview-flat.js | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/webui/js/source/listview-flat.js b/webui/js/source/listview-flat.js
index f42138d..be2810f 100644
--- a/webui/js/source/listview-flat.js
+++ b/webui/js/source/listview-flat.js
@@ -15,6 +15,11 @@
  limitations under the License.
  */
 
+let compact_email_height = 24;  // a normal email element is 24 pixels high
+let preview_email_height = 40;
+
+let narrow_width = 600;  // <= 600 pixels and we're in narrow view
+
 function calc_per_page() {
     // Figure out how many emails per page
     let body = document.body;
@@ -23,12 +28,13 @@ function calc_per_page() {
         html.clientHeight, html.scrollHeight);
     let width = Math.max(body.scrollWidth,
         html.clientWidth, html.scrollWidth);
-    let email_h = G_current_listmode_compact ? 24 : 40;
-    if (width < 600) {
-        console.log("Using narrow view, halving emails per page...");
-        email_h = G_current_listmode_compact ? 36 : 80;
+    let email_h = G_current_listmode_compact ? compact_email_height : preview_email_height;
+    if (width < narrow_width) {
+        console.log("Using narrow view, reducing emails per page...");
+        email_h = G_current_listmode_compact ? compact_email_height * 1.5 : preview_email_height*2;
     }
-    height -= 180;
+    height -= document.getElementById("emails").scrollHeight + 4; // top area height plus spacing
+    email_h += 2;
     let per_page = Math.max(5, Math.floor(height / email_h));
     per_page -= per_page % 5;
     console.log("Viewport is %ux%u. We can show %u emails per page".format(width, height, per_page));