[Dart] Cleaner code, force the web page to reload on modifier code

The code in `navbar.dart' is now more declarative and cleaner.

If the `lastUpdate' variable’s content change, then it will force the
user to reload the page, bypassing their cache. This can be useful in
case of an update with which the cache could break the website.
This commit is contained in:
Lucien Cartier-Tilet 2020-08-28 22:23:35 +02:00
parent e710c594f1
commit 16f23c08c6
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 13 additions and 7 deletions

View File

@ -51,15 +51,11 @@ Future<Element> makeHome() async {
// Create a clickable icon // Create a clickable icon
// `t_elem` must be an SVG declared in the above `icons` variable. // `t_elem` must be an SVG declared in the above `icons` variable.
Element makeIcon(SvgElement t_elem) { Element makeIcon(SvgElement t_elem) {
final icon = t_elem..classes.add('nav-icon'); return t_elem..classes.add('nav-icon');
return icon;
} }
// Create the dropdown sitemap // Create the dropdown sitemap
Future<Element> makePages() async { Future<Element> makePages() async {
var pages = Element.ul()
..attributes['id'] = 'drop-page'
..classes.add('dropdown');
return Element.li() return Element.li()
..attributes['tabindex'] = '0' ..attributes['tabindex'] = '0'
..append(Element.a() ..append(Element.a()
@ -67,7 +63,9 @@ Future<Element> makePages() async {
..attributes['href'] = 'javascript:void(0)' ..attributes['href'] = 'javascript:void(0)'
..append(makeIcon(icons['pages']))) ..append(makeIcon(icons['pages'])))
..classes.addAll(['nav-item', 'has-dropdown']) ..classes.addAll(['nav-item', 'has-dropdown'])
..append(pages); ..append(Element.ul()
..attributes['id'] = 'drop-page'
..classes.add('dropdown'));
} }
// Create the array of share icons // Create the array of share icons

View File

@ -1,4 +1,5 @@
import 'dart:html' show DivElement, Element, querySelector, querySelectorAll; import 'dart:html'
show DivElement, Element, querySelector, querySelectorAll, window;
import './navbar.dart' show makeNavbar; import './navbar.dart' show makeNavbar;
@ -40,6 +41,13 @@ Future<void> linkifyImg() async {
} }
Future<void> reorganizeHtml() async { Future<void> reorganizeHtml() async {
final ls = window.localStorage;
final lastUpdate = '20200828';
if (ls['last-update'] != lastUpdate) {
ls['last-update'] = lastUpdate;
window.location.reload();
}
// Make navbar // Make navbar
final navbar = await makeNavbar(); final navbar = await makeNavbar();