Record planting day and show harvest dates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-06 10:07:21 +01:00
parent 07057e6c3d
commit 83a9cb6dcc
11 changed files with 282 additions and 44 deletions

View file

@ -3,9 +3,9 @@
if (typeof module === "object" && module.exports) module.exports = api;
if (root) root.ValleySync = api;
})(typeof window === "undefined" ? globalThis : window, () => ({
mergeSnapshot(localChecks, savingIds, currentRevision, snapshot) {
mergeSnapshot(localChecks, savingIds, currentRevision, snapshot, localPlantings = {}, savingPlantings = new Set()) {
if (!snapshot || !Number.isInteger(snapshot.revision) || snapshot.revision <= currentRevision) {
return { applied: false, revision: currentRevision, checks: localChecks };
return { applied: false, revision: currentRevision, checks: localChecks, plantings: localPlantings };
}
const checks = { ...(snapshot.checks || {}) };
@ -14,7 +14,12 @@
checks[itemId] = Boolean(localChecks[itemId]);
}
}
return { applied: true, revision: snapshot.revision, checks };
const plantings = { ...(snapshot.plantings || {}) };
for (const itemId of savingPlantings) {
if (Object.prototype.hasOwnProperty.call(localPlantings, itemId)) plantings[itemId] = localPlantings[itemId];
else delete plantings[itemId];
}
return { applied: true, revision: snapshot.revision, checks, plantings };
},
confirmWrite(localChecks, currentRevision, result) {
@ -22,5 +27,12 @@
checks: { ...localChecks, [result.itemId]: Boolean(result.checked) },
revision: Math.max(currentRevision, result.revision)
};
},
confirmPlanting(localPlantings, currentRevision, result) {
const plantings = { ...localPlantings };
if (result.planted) plantings[result.itemId] = result.planted;
else delete plantings[result.itemId];
return { plantings, revision: Math.max(currentRevision, result.revision) };
}
}));