From c6e291f7e875f2023b554209d9a34cb9cd476a10 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 13:16:51 +0200 Subject: [PATCH 1/6] Dark theme: prevent white flash on page load --- static/assets/js/core.js | 15 +-------------- static/assets/js/theme.js | 40 +++++++++++++++++++++++++++++++++++++++ templates/base.html | 4 +++- 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 static/assets/js/theme.js diff --git a/static/assets/js/core.js b/static/assets/js/core.js index 7b02b27d..25de1c94 100755 --- a/static/assets/js/core.js +++ b/static/assets/js/core.js @@ -104,17 +104,4 @@ $(document).ready(function() { }); }); } - - /** Dark mode controller */ - if (store.get('dark-mode') === true) { - document.documentElement.setAttribute('data-theme', 'dark') - } - $('[data-toggle="dark-mode"]').on('click', function () { - if (store.get('dark-mode') === true) { - store.set('dark-mode', false); - return document.documentElement.setAttribute('data-theme', 'light') - } - store.set('dark-mode', true) - document.documentElement.setAttribute('data-theme', 'dark') - }) -}); \ No newline at end of file +}); diff --git a/static/assets/js/theme.js b/static/assets/js/theme.js new file mode 100644 index 00000000..721b2556 --- /dev/null +++ b/static/assets/js/theme.js @@ -0,0 +1,40 @@ +let setCookie = function(name, value, days) { + if (!name || !value) return false; + let expires = ''; + let secure = ''; + if (location.protocol === 'https:') secure = 'Secure; '; + + if (days) { + let date = new Date(); + date.setTime(date.getTime() + (days * 24*60*60*1000)); + expires = 'Expires=' + date.toUTCString() + '; '; + } + + document.cookie = name + '=' + value + '; ' + + expires + + secure + + 'sameSite=Lax; ' + + 'domain=' + window.location.hostname + '; ' + + 'path=/'; + return true; + } + +let getCookie = function(name) { + let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); + if (match) return match[2]; +} + +$(document).ready(function() { + /** Dark mode controller */ + if (getCookie('dark-mode') === "true") { + document.documentElement.setAttribute('data-theme', 'dark'); + } + $('[data-toggle="dark-mode"]').on('click', function () { + if (getCookie('dark-mode') === "true") { + setCookie('dark-mode', 'false', 30); + return document.documentElement.setAttribute('data-theme', 'light') + } + setCookie('dark-mode', 'true', 30); + document.documentElement.setAttribute('data-theme', 'dark') + }) +}); diff --git a/templates/base.html b/templates/base.html index c7539b7b..0f1827c8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,7 +1,7 @@ {% from "_formhelpers.html" import render_field, render_field_errors %} - + + + From bdc3102420115bd7616c5e9d90462a2148119447 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 13:18:41 +0200 Subject: [PATCH 2/6] Fix space error footer --- templates/footer.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/footer.html b/templates/footer.html index 19645413..407bc7eb 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -33,8 +33,7 @@
Copyright © {{ YEAR }} - SimpleLogin - . + SimpleLogin. All rights reserved.
From cb269a1bbe861d2dfa89c7e22bd6565c0e350811 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 13:49:53 +0200 Subject: [PATCH 3/6] Change pagination style --- app/dashboard/templates/dashboard/alias_log.html | 4 ++-- app/dashboard/templates/dashboard/index.html | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/dashboard/templates/dashboard/alias_log.html b/app/dashboard/templates/dashboard/alias_log.html index 66cc21d3..fea2bbae 100644 --- a/app/dashboard/templates/dashboard/alias_log.html +++ b/app/dashboard/templates/dashboard/alias_log.html @@ -146,11 +146,11 @@ diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 71471fc1..6985b6f7 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -400,13 +400,15 @@
From e44d92705c1b64d4b0ede5f141758e312909d6b6 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 13:50:17 +0200 Subject: [PATCH 4/6] Add missing last_page check (index) Move disabled class to correct element (alias_log) --- app/dashboard/templates/dashboard/alias_log.html | 9 +++++---- app/dashboard/views/index.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/dashboard/templates/dashboard/alias_log.html b/app/dashboard/templates/dashboard/alias_log.html index fea2bbae..aca5a498 100644 --- a/app/dashboard/templates/dashboard/alias_log.html +++ b/app/dashboard/templates/dashboard/alias_log.html @@ -145,12 +145,13 @@ diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index fc314c50..d8cff532 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -6,6 +6,7 @@ from sqlalchemy.orm import joinedload from app import alias_utils from app.api.serializer import get_alias_infos_with_pagination_v2 +from app.config import PAGE_LIMIT from app.dashboard.base import dashboard_bp from app.extensions import db from app.log import LOG @@ -140,18 +141,24 @@ def index(): stats = get_stats(current_user) + alias_infos = get_alias_infos_with_pagination_v2( + current_user, page, query, sort, alias_filter + ) + last_page = ( + len(alias_infos) < PAGE_LIMIT + ) + return render_template( "dashboard/index.html", client_users=client_users, - alias_infos=get_alias_infos_with_pagination_v2( - current_user, page, query, sort, alias_filter - ), + alias_infos=alias_infos, highlight_alias_id=highlight_alias_id, query=query, AliasGeneratorEnum=AliasGeneratorEnum, mailboxes=mailboxes, show_intro=show_intro, page=page, + last_page=last_page, sort=sort, filter=alias_filter, stats=stats, From c0041d55bc8202487473ed0a24368cb309e44cca Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 14:23:29 +0200 Subject: [PATCH 5/6] Set input background to white for light theme --- static/assets/css/darkmode.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/assets/css/darkmode.css b/static/assets/css/darkmode.css index eefa1600..9a7b5b4f 100644 --- a/static/assets/css/darkmode.css +++ b/static/assets/css/darkmode.css @@ -9,7 +9,7 @@ --heading-color: #818cab; --heading-background: #FFF; --border: 1px solid rgba(0, 40, 100, 0.12); - --input-bg-color: var(--light); + --input-bg-color: var(--white); } [data-theme="dark"] { From 012bc52694d2a6088142a64164f3cf9175bdf647 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Thu, 14 May 2020 14:29:36 +0200 Subject: [PATCH 6/6] Fix formatting --- app/dashboard/views/index.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index d8cff532..2d9f1df6 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -1,5 +1,4 @@ from dataclasses import dataclass - from flask import render_template, request, redirect, url_for, flash from flask_login import login_required, current_user from sqlalchemy.orm import joinedload @@ -144,9 +143,7 @@ def index(): alias_infos = get_alias_infos_with_pagination_v2( current_user, page, query, sort, alias_filter ) - last_page = ( - len(alias_infos) < PAGE_LIMIT - ) + last_page = len(alias_infos) < PAGE_LIMIT return render_template( "dashboard/index.html",