Sort selected items to bottom and enable Widgets
pull/2454/head
Erik Andresen 2023-01-05 18:41:51 +01:00
parent 29a9687c57
commit 83e76d4001
3 changed files with 31 additions and 16 deletions

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Refactor code to store grocery list in separate file
0.03: Sort selected items to bottom and enable Widgets

View File

@ -1,5 +1,6 @@
var filename = 'grocery_list.json';
var settings = require("Storage").readJSON(filename,1)|| { products: [] };
let menu;
function updateSettings() {
require("Storage").writeJSON(filename, settings);
@ -11,19 +12,32 @@ function twoChat(n){
return ''+n;
}
const mainMenu = settings.products.reduce(function(m, p, i){
const name = twoChat(p.quantity)+' '+p.name;
m[name] = {
function sortMenu() {
mainMenu.sort((a,b) => {
const byValue = a.value-b.value;
return byValue !== 0 ? byValue : a.index-b.index;
});
if (menu) {
menu.draw();
}
}
const mainMenu = settings.products.map((p,i) => ({
title: twoChat(p.quantity)+' '+p.name,
value: p.ok,
format: v => v?'[x]':'[ ]',
index: i,
onchange: v => {
settings.products[i].ok = v;
updateSettings();
sortMenu();
}
};
return m;
}, {
'': { 'title': 'Grocery list' }
});
}));
sortMenu();
mainMenu[''] = { 'title': 'Grocery list' };
mainMenu['< Back'] = ()=>{load();};
E.showMenu(mainMenu);
Bangle.loadWidgets();
menu = E.showMenu(mainMenu);
Bangle.drawWidgets();

View File

@ -1,7 +1,7 @@
{
"id": "grocery",
"name": "Grocery",
"version": "0.02",
"version": "0.03",
"description": "Simple grocery (shopping) list - Display a list of product and track if you already put them in your cart.",
"icon": "grocery.png",
"type": "app",