Sheets is your data source — logs sync there and the app reads back from it on every load.
Step 1 — New Sheet
sheets.google.com → new → name it FuelKit Log
Step 2 — Apps Script
Extensions → Apps Script → replace ALL code with this:
function formatDate(val) {
if (!val) return '';
// If Sheets stored it as a Date object, format as DD/MM/YYYY
if (val instanceof Date) {
const d = val.getDate().toString().padStart(2,'0');
const m = (val.getMonth()+1).toString().padStart(2,'0');
const y = val.getFullYear();
return d+'/'+m+'/'+y;
}
return String(val);
}
function doGet(e) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sh = ss.getSheetByName("Log");
let rows = [];
if (sh && sh.getLastRow() >= 2) {
const vals = sh.getRange(2,1,sh.getLastRow()-1,8).getValues();
rows = vals.map(r => ({
date: formatDate(r[0]),
time: String(r[1]),
meal: String(r[2]),
food: String(r[3]),
calories: Number(r[4]) || 0,
protein: Number(r[5]) || 0,
carbs: Number(r[6]) || 0,
fat: Number(r[7]) || 0
}));
}
const json = JSON.stringify({rows});
const cb = (e && e.parameter) ? e.parameter.callback : null;
if (cb) {
return ContentService
.createTextOutput(cb + '(' + json + ')')
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
return ContentService
.createTextOutput(json)
.setMimeType(ContentService.MimeType.JSON);
}
function doPost(e) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sh = ss.getSheetByName("Log");
if (!sh) {
sh = ss.insertSheet("Log");
sh.appendRow(["Date","Time","Meal","Food",
"Calories","Protein(g)","Carbs(g)","Fat(g)"]);
}
const d = JSON.parse(e.postData.contents);
sh.appendRow([d.date, d.time, d.meal, d.food,
d.calories, d.protein, d.carbs, d.fat]);
return ContentService.createTextOutput("OK");
}
⚠️ Replace ALL existing code with this. Then Deploy → New Deployment → Web App → Execute as: Me → Who has access: Anyone → Deploy → copy the /exec URL.