[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.
Šī revīzija ir iekļauta:
Lucien Cartier-Tilet 2020-08-28 22:23:35 +02:00
vecāks e710c594f1
revīzija 16f23c08c6
Parakstījis: phundrak
GPG atslēgas ID: BD7789E705CB8DCA
2 mainīti faili ar 13 papildinājumiem un 7 dzēšanām

Parādīt failu

@ -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

Parādīt failu

@ -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();