Period totals footer, category reorder, mobile fixes, PWA with update prompt
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
COPY index.html styles.css app.js /usr/share/nginx/html/
|
COPY index.html styles.css app.js manifest.json sw.js icon-192.png icon-512.png /usr/share/nginx/html/
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -20,11 +20,12 @@ To use another port: `PORT=8080 python3 server.py`.
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Sidebar views** — Daily, Weekly, Monthly and All expenses with live counts, each group with its own total.
|
- **Sidebar views** — Daily, Weekly, Monthly and All expenses with live counts, each group with its own total.
|
||||||
- **Categories** — Food, Transport, Household, Utilities, Shopping, Health, Beauty, Entertainment, Other.
|
- **Categories** — Food, Transport, Household, Utilities, Shopping, Health, Beauty, Entertainment, Other. Drag them up or down to rearrange; the order is remembered.
|
||||||
|
- **Period totals** — the sidebar footer shows total spending for today, this week or this month at a tap.
|
||||||
- **Repeats** — mark an expense Daily, Weekly or Monthly. Repeating entries appear under “Repeating expenses” with the next due date and a one-click **Log next occurrence** button.
|
- **Repeats** — mark an expense Daily, Weekly or Monthly. Repeating entries appear under “Repeating expenses” with the next due date and a one-click **Log next occurrence** button.
|
||||||
- **Summary** — totals plus a per-category spending breakdown for whatever is shown.
|
- **Summary** — totals plus a per-category spending breakdown for whatever is shown.
|
||||||
- **INR amounts** — everything is shown in rupees (₹) with Indian digit grouping.
|
- **INR amounts** — everything is shown in rupees (₹) with Indian digit grouping.
|
||||||
- **Search and filters** — by text, category and repeat type.
|
- **Search and filters** — by text and category.
|
||||||
- **Edit / delete** — every entry can be changed or removed.
|
- **Edit / delete** — every entry can be changed or removed.
|
||||||
- **Sample data** — realistic entries are loaded on first run so each view has content. Use **Clear all** to start empty and **Load sample data** to add them back.
|
- **Sample data** — realistic entries are loaded on first run so each view has content. Use **Clear all** to start empty and **Load sample data** to add them back.
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ Cloudflare caches `app.js`/`styles.css` at the edge, so every deploy that
|
|||||||
changes them must bump the `?v=` query in `index.html` or visitors keep
|
changes them must bump the `?v=` query in `index.html` or visitors keep
|
||||||
getting the old files until the edge entry expires.
|
getting the old files until the edge entry expires.
|
||||||
|
|
||||||
|
The app is also a PWA: `sw.js` caches the shell for offline use and shows an
|
||||||
|
"Update to latest version" button when a deploy ships. Every deploy that
|
||||||
|
changes the app must bump the `CACHE` name in `sw.js` (`tally-v3`, `tally-v4`,
|
||||||
|
…) or installed clients never see the update.
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
|
|
||||||
- `index.html` — page structure
|
- `index.html` — page structure
|
||||||
|
|||||||
109
app.js
109
app.js
@@ -18,8 +18,37 @@ var CATS = {
|
|||||||
|
|
||||||
var FREQ_LABEL = { once: "One-time", daily: "Daily", weekly: "Weekly", monthly: "Monthly" };
|
var FREQ_LABEL = { once: "One-time", daily: "Daily", weekly: "Weekly", monthly: "Monthly" };
|
||||||
var STORE_KEY = "expense-tracker.expenses.v1";
|
var STORE_KEY = "expense-tracker.expenses.v1";
|
||||||
|
var ORDER_KEY = "expense-tracker.catorder.v1";
|
||||||
|
|
||||||
var state = { tab: "daily", q: "", cat: "all", freq: "all", editingId: null, screen: "add", selMonth: null, selYear: null, selWeek: null, selDate: null };
|
/* Category order, persisted so drag-reorder survives reloads. Unknown saved
|
||||||
|
names are dropped; new categories append in their default position. */
|
||||||
|
function getCatOrder() {
|
||||||
|
var names = Object.keys(CATS);
|
||||||
|
try {
|
||||||
|
var saved = JSON.parse(localStorage.getItem(ORDER_KEY) || "[]");
|
||||||
|
if (!Array.isArray(saved)) return names;
|
||||||
|
var known = saved.filter(function (n) { return CATS[n] !== undefined; });
|
||||||
|
names.forEach(function (n) { if (known.indexOf(n) === -1) known.push(n); });
|
||||||
|
return known;
|
||||||
|
} catch (e) {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveCatOrder(names) {
|
||||||
|
try { localStorage.setItem(ORDER_KEY, JSON.stringify(names)); } catch (e) { /* session-only order */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
function refillCatOptions() {
|
||||||
|
var sel = $("fCat");
|
||||||
|
var cur = sel.value;
|
||||||
|
sel.innerHTML = getCatOrder().map(function (c) {
|
||||||
|
return '<option value="' + c + '">' + c + "</option>";
|
||||||
|
}).join("");
|
||||||
|
sel.value = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
var state = { tab: "daily", q: "", cat: "all", period: "month", editingId: null, screen: "add", selMonth: null, selYear: null, selWeek: null, selDate: null };
|
||||||
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||||
|
|
||||||
/* All amounts display in INR. */
|
/* All amounts display in INR. */
|
||||||
@@ -170,7 +199,6 @@ function filtered(list) {
|
|||||||
if (mondayOf(e.date) !== state.selWeek) return false;
|
if (mondayOf(e.date) !== state.selWeek) return false;
|
||||||
}
|
}
|
||||||
if (state.cat !== "all" && e.category !== state.cat) return false;
|
if (state.cat !== "all" && e.category !== state.cat) return false;
|
||||||
if (state.freq !== "all" && e.frequency !== state.freq) return false;
|
|
||||||
if (q && (e.description + " " + e.category).toLowerCase().indexOf(q) === -1) return false;
|
if (q && (e.description + " " + e.category).toLowerCase().indexOf(q) === -1) return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -335,23 +363,77 @@ function renderNav(list) {
|
|||||||
$("countWeekly").textContent = c.weekly;
|
$("countWeekly").textContent = c.weekly;
|
||||||
$("countMonthly").textContent = c.monthly;
|
$("countMonthly").textContent = c.monthly;
|
||||||
$("countAll").textContent = c.all;
|
$("countAll").textContent = c.all;
|
||||||
var names = Object.keys(CATS);
|
var names = getCatOrder();
|
||||||
var html = '<li><button type="button" class="cat-item' + (state.cat === "all" ? " active" : "") +
|
var html = '<li><button type="button" class="cat-item' + (state.cat === "all" ? " active" : "") +
|
||||||
'" data-cat="all"><span class="dot" style="background:#c9c9c9"></span><span>All categories</span>' +
|
'" data-cat="all"><span class="dot" style="background:#c9c9c9"></span><span>All categories</span>' +
|
||||||
'<span class="count">' + list.length + "</span></button></li>";
|
'<span class="count">' + list.length + "</span></button></li>";
|
||||||
html += names.map(function (n) {
|
html += names.map(function (n) {
|
||||||
return '<li><button type="button" class="cat-item' + (state.cat === n ? " active" : "") +
|
return '<li draggable="true" data-order="' + esc(n) + '"><button type="button" class="cat-item' + (state.cat === n ? " active" : "") +
|
||||||
'" data-cat="' + esc(n) + '"><span class="dot" style="background:' + (CATS[n] || "#c9c9c9") + '"></span>' +
|
'" data-cat="' + esc(n) + '"><span class="dot" style="background:' + (CATS[n] || "#c9c9c9") + '"></span>' +
|
||||||
"<span>" + esc(n) + "</span>" +
|
"<span>" + esc(n) + "</span>" +
|
||||||
'<span class="count">' + (byCat[n] || 0) + "</span></button></li>";
|
'<span class="count">' + (byCat[n] || 0) + "</span></button></li>";
|
||||||
}).join("");
|
}).join("");
|
||||||
$("catList").innerHTML = html;
|
$("catList").innerHTML = html;
|
||||||
var m = 0;
|
var d = 0, w = 0, m = 0;
|
||||||
list.forEach(function (e) { if (e.date.slice(0, 7) === mo) m += e.amount; });
|
list.forEach(function (e) {
|
||||||
$("sideMonth").textContent = money.format(m);
|
if (e.date === t) d += e.amount;
|
||||||
|
if (mondayOf(e.date) === wk) w += e.amount;
|
||||||
|
if (e.date.slice(0, 7) === mo) m += e.amount;
|
||||||
|
});
|
||||||
|
var labels = { day: "Today", week: "This week", month: "This month" };
|
||||||
|
var totals = { day: d, week: w, month: m };
|
||||||
|
$("periodLabel").textContent = labels[state.period] || labels.month;
|
||||||
|
$("sideMonth").textContent = money.format(totals[state.period] === undefined ? m : totals[state.period]);
|
||||||
|
Array.prototype.forEach.call(document.querySelectorAll("[data-period]"), function (b) {
|
||||||
|
b.classList.toggle("active", b.getAttribute("data-period") === state.period);
|
||||||
|
});
|
||||||
$("topMonth").textContent = money.format(m);
|
$("topMonth").textContent = money.format(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Drag-to-reorder for the sidebar categories. Only the named categories move;
|
||||||
|
"All categories" stays pinned at the top. */
|
||||||
|
var dragName = null;
|
||||||
|
function wireCatDnD() {
|
||||||
|
var list = $("catList");
|
||||||
|
list.addEventListener("dragstart", function (e) {
|
||||||
|
var li = e.target.closest("li[data-order]");
|
||||||
|
if (!li) { e.preventDefault(); return; }
|
||||||
|
dragName = li.getAttribute("data-order");
|
||||||
|
e.dataTransfer.effectAllowed = "move";
|
||||||
|
try { e.dataTransfer.setData("text/plain", dragName); } catch (err) { /* some browsers need the try */ }
|
||||||
|
li.classList.add("dragging");
|
||||||
|
});
|
||||||
|
list.addEventListener("dragend", function () {
|
||||||
|
dragName = null;
|
||||||
|
Array.prototype.forEach.call(list.querySelectorAll(".dragging, .drag-over"), function (el) {
|
||||||
|
el.classList.remove("dragging", "drag-over");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
list.addEventListener("dragover", function (e) {
|
||||||
|
var li = e.target.closest("li[data-order]");
|
||||||
|
if (!li || !dragName) return;
|
||||||
|
e.preventDefault();
|
||||||
|
e.dataTransfer.dropEffect = "move";
|
||||||
|
Array.prototype.forEach.call(list.querySelectorAll(".drag-over"), function (el) {
|
||||||
|
if (el !== li) el.classList.remove("drag-over");
|
||||||
|
});
|
||||||
|
li.classList.add("drag-over");
|
||||||
|
});
|
||||||
|
list.addEventListener("drop", function (e) {
|
||||||
|
var li = e.target.closest("li[data-order]");
|
||||||
|
if (!li || !dragName) return;
|
||||||
|
e.preventDefault();
|
||||||
|
var target = li.getAttribute("data-order");
|
||||||
|
if (target === dragName) return;
|
||||||
|
var names = getCatOrder();
|
||||||
|
names.splice(names.indexOf(dragName), 1);
|
||||||
|
names.splice(names.indexOf(target), 0, dragName);
|
||||||
|
saveCatOrder(names);
|
||||||
|
refillCatOptions();
|
||||||
|
renderAll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* Landing shows only the add form; records live behind the menu drawer. */
|
/* Landing shows only the add form; records live behind the menu drawer. */
|
||||||
var RECORD_SECTIONS = ["viewHead", "statsSection", "sumCard", "listSection", "templatesCard"];
|
var RECORD_SECTIONS = ["viewHead", "statsSection", "sumCard", "listSection", "templatesCard"];
|
||||||
|
|
||||||
@@ -489,10 +571,7 @@ function showErr(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var catSel = $("fCat");
|
refillCatOptions();
|
||||||
catSel.innerHTML = Object.keys(CATS).map(function (c) {
|
|
||||||
return '<option value="' + c + '">' + c + "</option>";
|
|
||||||
}).join("");
|
|
||||||
$("fDate").value = todayStr();
|
$("fDate").value = todayStr();
|
||||||
|
|
||||||
document.querySelectorAll(".nav-item[data-tab]").forEach(function (btn) {
|
document.querySelectorAll(".nav-item[data-tab]").forEach(function (btn) {
|
||||||
@@ -591,7 +670,13 @@ function init() {
|
|||||||
}
|
}
|
||||||
$("datePicker").addEventListener("change", function (e) { pickDateInput(e.target.closest("[data-dinput]")); });
|
$("datePicker").addEventListener("change", function (e) { pickDateInput(e.target.closest("[data-dinput]")); });
|
||||||
$("datePicker").addEventListener("input", function (e) { pickDateInput(e.target.closest("[data-dinput]")); });
|
$("datePicker").addEventListener("input", function (e) { pickDateInput(e.target.closest("[data-dinput]")); });
|
||||||
$("fFreqFilter").addEventListener("change", function (e) { state.freq = e.target.value; renderAll(); });
|
document.querySelector(".period-pick").addEventListener("click", function (e) {
|
||||||
|
var b = e.target.closest("[data-period]");
|
||||||
|
if (!b) return;
|
||||||
|
state.period = b.getAttribute("data-period");
|
||||||
|
renderAll();
|
||||||
|
});
|
||||||
|
wireCatDnD();
|
||||||
|
|
||||||
$("expForm").addEventListener("submit", function (e) {
|
$("expForm").addEventListener("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import ExpenseForm from "./src/components/ExpenseForm";
|
|||||||
import ExpenseGroups from "./src/components/ExpenseGroups";
|
import ExpenseGroups from "./src/components/ExpenseGroups";
|
||||||
import RepeatTemplates from "./src/components/RepeatTemplates";
|
import RepeatTemplates from "./src/components/RepeatTemplates";
|
||||||
import SummaryBars from "./src/components/SummaryBars";
|
import SummaryBars from "./src/components/SummaryBars";
|
||||||
import { CATEGORIES } from "./src/categories";
|
import { CATEGORIES, applyCatOrder } from "./src/categories";
|
||||||
import {
|
import {
|
||||||
addDaysStr,
|
addDaysStr,
|
||||||
groupKey,
|
groupKey,
|
||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
todayStr,
|
todayStr,
|
||||||
uid,
|
uid,
|
||||||
} from "./src/logic";
|
} from "./src/logic";
|
||||||
import { loadExpenses, saveExpenses } from "./src/storage";
|
import { loadExpenses, saveExpenses, loadCatOrder, saveCatOrder } from "./src/storage";
|
||||||
import s from "./src/styles";
|
import s from "./src/styles";
|
||||||
|
|
||||||
const TABS = ["daily", "weekly", "monthly"];
|
const TABS = ["daily", "weekly", "monthly"];
|
||||||
@@ -37,7 +37,9 @@ export default function App() {
|
|||||||
const [tab, setTab] = useState("daily");
|
const [tab, setTab] = useState("daily");
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
const [catFilter, setCatFilter] = useState("all");
|
const [catFilter, setCatFilter] = useState("all");
|
||||||
const [freqFilter, setFreqFilter] = useState("all");
|
const [period, setPeriod] = useState("month");
|
||||||
|
const [catOrder, setCatOrder] = useState(null);
|
||||||
|
const [arranging, setArranging] = useState(false);
|
||||||
const [editingId, setEditingId] = useState(null);
|
const [editingId, setEditingId] = useState(null);
|
||||||
const [pendingDeleteId, setPendingDeleteId] = useState(null);
|
const [pendingDeleteId, setPendingDeleteId] = useState(null);
|
||||||
const currency = "INR";
|
const currency = "INR";
|
||||||
@@ -52,6 +54,7 @@ export default function App() {
|
|||||||
setExpenses(list);
|
setExpenses(list);
|
||||||
setReady(true);
|
setReady(true);
|
||||||
});
|
});
|
||||||
|
loadCatOrder().then(setCatOrder);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function update(list) {
|
function update(list) {
|
||||||
@@ -103,11 +106,10 @@ export default function App() {
|
|||||||
const q = query.trim().toLowerCase();
|
const q = query.trim().toLowerCase();
|
||||||
return expenses.filter((e) => {
|
return expenses.filter((e) => {
|
||||||
if (catFilter !== "all" && e.category !== catFilter) return false;
|
if (catFilter !== "all" && e.category !== catFilter) return false;
|
||||||
if (freqFilter !== "all" && e.frequency !== freqFilter) return false;
|
|
||||||
if (q && (e.description + " " + e.category).toLowerCase().indexOf(q) === -1) return false;
|
if (q && (e.description + " " + e.category).toLowerCase().indexOf(q) === -1) return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}, [expenses, query, catFilter, freqFilter]);
|
}, [expenses, query, catFilter]);
|
||||||
|
|
||||||
const groups = useMemo(() => {
|
const groups = useMemo(() => {
|
||||||
const map = {};
|
const map = {};
|
||||||
@@ -144,6 +146,21 @@ export default function App() {
|
|||||||
return { d, w, m, counts: { daily: dc, weekly: wc, monthly: mc }, catCounts: cats };
|
return { d, w, m, counts: { daily: dc, weekly: wc, monthly: mc }, catCounts: cats };
|
||||||
}, [expenses]);
|
}, [expenses]);
|
||||||
|
|
||||||
|
const orderedCats = useMemo(() => applyCatOrder(CATEGORIES, catOrder), [catOrder]);
|
||||||
|
const periodTotal = period === "day" ? stats.d : period === "week" ? stats.w : stats.m;
|
||||||
|
const periodNoun = period === "day" ? "today" : period === "week" ? "this week" : "this month";
|
||||||
|
|
||||||
|
function moveCat(index, dir) {
|
||||||
|
const names = orderedCats.map((c) => c.name);
|
||||||
|
const j = index + dir;
|
||||||
|
if (j < 0 || j >= names.length) return;
|
||||||
|
const t = names[index];
|
||||||
|
names[index] = names[j];
|
||||||
|
names[j] = t;
|
||||||
|
setCatOrder(names);
|
||||||
|
saveCatOrder(names);
|
||||||
|
}
|
||||||
|
|
||||||
function editExpense(id) {
|
function editExpense(id) {
|
||||||
setEditingId(id);
|
setEditingId(id);
|
||||||
setPendingDeleteId(null);
|
setPendingDeleteId(null);
|
||||||
@@ -161,7 +178,7 @@ export default function App() {
|
|||||||
<Text style={[s.headerTotal, { fontSize: 20 }]}>{menuOpen ? "\u2715" : "\u2630"}</Text>
|
<Text style={[s.headerTotal, { fontSize: 20 }]}>{menuOpen ? "\u2715" : "\u2630"}</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
<Text style={s.headerTotal}>{money(stats.m, currency)} this month</Text>
|
<Text style={s.headerTotal}>{money(periodTotal, currency)} {periodNoun}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={s.card}>
|
<View style={s.card}>
|
||||||
@@ -183,6 +200,7 @@ export default function App() {
|
|||||||
: blankForm()
|
: blankForm()
|
||||||
}
|
}
|
||||||
submitLabel={editing ? "Save changes" : "Add expense"}
|
submitLabel={editing ? "Save changes" : "Add expense"}
|
||||||
|
categories={orderedCats}
|
||||||
onSubmit={submitForm}
|
onSubmit={submitForm}
|
||||||
onCancel={editing ? () => setEditingId(null) : null}
|
onCancel={editing ? () => setEditingId(null) : null}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
@@ -226,20 +244,41 @@ export default function App() {
|
|||||||
<Pressable onPress={() => setCatFilter("all")} style={[s.chip, catFilter === "all" && s.chipActive]}>
|
<Pressable onPress={() => setCatFilter("all")} style={[s.chip, catFilter === "all" && s.chipActive]}>
|
||||||
<Text style={[s.chipText, catFilter === "all" && s.chipTextActive]}>All</Text>
|
<Text style={[s.chipText, catFilter === "all" && s.chipTextActive]}>All</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
{CATEGORIES.map((c) => (
|
{orderedCats.map((c) => (
|
||||||
<Pressable key={c.name} onPress={() => setCatFilter(c.name)} style={[s.chip, catFilter === c.name && s.chipActive]}>
|
<Pressable key={c.name} onPress={() => setCatFilter(c.name)} style={[s.chip, catFilter === c.name && s.chipActive]}>
|
||||||
<Text style={[s.chipText, catFilter === c.name && s.chipTextActive]}>{"\u25cf"} {c.name} <Text style={s.chipCount}>{"\u00b7"} {stats.catCounts[c.name] || 0}</Text></Text>
|
<Text style={[s.chipText, catFilter === c.name && s.chipTextActive]}>{"\u25cf"} {c.name} <Text style={s.chipCount}>{"\u00b7"} {stats.catCounts[c.name] || 0}</Text></Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<Text style={s.label}>Repeats</Text>
|
<Pressable onPress={() => setArranging(!arranging)} style={[s.btn, s.btnSubtle, s.btnSmall, { alignSelf: "flex-start", marginTop: 8 }]}>
|
||||||
<View style={s.chips}>
|
<Text style={s.btnSmallText}>{arranging ? "Done" : "Arrange"}</Text>
|
||||||
{["all", "once", "daily", "weekly", "monthly"].map((f) => (
|
</Pressable>
|
||||||
<Pressable key={f} onPress={() => setFreqFilter(f)} style={[s.chip, freqFilter === f && s.chipActive]}>
|
{arranging ? (
|
||||||
<Text style={[s.chipText, freqFilter === f && s.chipTextActive]}>
|
<View style={{ marginTop: 4 }}>
|
||||||
{f === "all" ? "All" : f === "once" ? "One-time" : f.charAt(0).toUpperCase() + f.slice(1)}
|
{orderedCats.map((c, i) => (
|
||||||
|
<View key={c.name} style={s.arrangeRow}>
|
||||||
|
<Text style={s.arrangeName}>
|
||||||
|
<Text style={{ color: c.color }}>{"\u25cf "}</Text>
|
||||||
|
{c.name}
|
||||||
</Text>
|
</Text>
|
||||||
|
<View style={s.arrangeBtns}>
|
||||||
|
<Pressable onPress={() => moveCat(i, -1)} disabled={i === 0} style={[s.btn, s.btnSubtle, s.btnSmall]}>
|
||||||
|
<Text style={s.btnSmallText}>{"\u2191"}</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Pressable onPress={() => moveCat(i, 1)} disabled={i === orderedCats.length - 1} style={[s.btn, s.btnSubtle, s.btnSmall]}>
|
||||||
|
<Text style={s.btnSmallText}>{"\u2193"}</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
<Text style={s.label}>Total for</Text>
|
||||||
|
<View style={s.chips}>
|
||||||
|
{[["day", "Today"], ["week", "Week"], ["month", "Month"]].map(([p, label]) => (
|
||||||
|
<Pressable key={p} onPress={() => setPeriod(p)} style={[s.chip, period === p && s.chipActive]}>
|
||||||
|
<Text style={[s.chipText, period === p && s.chipTextActive]}>{label}</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ working as before; this folder is the future-proof rewrite.
|
|||||||
- **Daily / Weekly / Monthly tabs** — the same expenses regrouped by day, by week
|
- **Daily / Weekly / Monthly tabs** — the same expenses regrouped by day, by week
|
||||||
(Monday–Sunday) or by month, each group with its own total.
|
(Monday–Sunday) or by month, each group with its own total.
|
||||||
- **Categories** — Food, Transport, Household, Utilities, Shopping, Health,
|
- **Categories** — Food, Transport, Household, Utilities, Shopping, Health,
|
||||||
Beauty, Entertainment, Other.
|
Beauty, Entertainment, Other. Tap Arrange to reorder them with ↑ ↓.
|
||||||
- **Repeats** — mark an expense Daily, Weekly or Monthly. They appear under
|
- **Repeats** — mark an expense Daily, Weekly or Monthly. They appear under
|
||||||
“Repeating expenses” with the next due date and a **Log next occurrence** button.
|
“Repeating expenses” with the next due date and a **Log next occurrence** button.
|
||||||
- **Summary** — totals plus a per-category spending breakdown of whatever is shown.
|
- **Summary** — totals plus a per-category spending breakdown of whatever is shown.
|
||||||
|
|||||||
@@ -16,3 +16,12 @@ export function colorFor(category) {
|
|||||||
const found = CATEGORIES.find((c) => c.name === category);
|
const found = CATEGORIES.find((c) => c.name === category);
|
||||||
return found ? found.color : "#c9c9c9";
|
return found ? found.color : "#c9c9c9";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function applyCatOrder(list, saved) {
|
||||||
|
if (!Array.isArray(saved)) return list;
|
||||||
|
const byName = {};
|
||||||
|
list.forEach((c) => { byName[c.name] = c; });
|
||||||
|
const ordered = saved.filter((n) => byName[n]).map((n) => byName[n]);
|
||||||
|
list.forEach((c) => { if (ordered.indexOf(c) === -1) ordered.push(c); });
|
||||||
|
return ordered;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function Chip({ label, active, onPress, dot }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ExpenseForm({ initial, submitLabel, onSubmit, onCancel, currency }) {
|
export default function ExpenseForm({ initial, submitLabel, onSubmit, onCancel, currency, categories = CATEGORIES }) {
|
||||||
const [desc, setDesc] = useState(initial.description);
|
const [desc, setDesc] = useState(initial.description);
|
||||||
const [amount, setAmount] = useState(initial.amount);
|
const [amount, setAmount] = useState(initial.amount);
|
||||||
const [cat, setCat] = useState(initial.category);
|
const [cat, setCat] = useState(initial.category);
|
||||||
@@ -61,7 +61,7 @@ export default function ExpenseForm({ initial, submitLabel, onSubmit, onCancel,
|
|||||||
|
|
||||||
<Text style={s.label}>Category</Text>
|
<Text style={s.label}>Category</Text>
|
||||||
<View style={s.chips}>
|
<View style={s.chips}>
|
||||||
{CATEGORIES.map((c) => (
|
{categories.map((c) => (
|
||||||
<Chip key={c.name} label={c.name} dot active={cat === c.name} onPress={() => setCat(c.name)} />
|
<Chip key={c.name} label={c.name} dot active={cat === c.name} onPress={() => setCat(c.name)} />
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -4,6 +4,25 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
|
|||||||
import { seedSamples } from "./logic";
|
import { seedSamples } from "./logic";
|
||||||
|
|
||||||
const KEY = "expense-tracker.expenses.v1";
|
const KEY = "expense-tracker.expenses.v1";
|
||||||
|
const ORDER_KEY = "expense-tracker.catorder.v1";
|
||||||
|
|
||||||
|
export async function loadCatOrder() {
|
||||||
|
try {
|
||||||
|
const raw = await AsyncStorage.getItem(ORDER_KEY);
|
||||||
|
const arr = JSON.parse(raw || "[]");
|
||||||
|
return Array.isArray(arr) ? arr : null;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveCatOrder(names) {
|
||||||
|
try {
|
||||||
|
await AsyncStorage.setItem(ORDER_KEY, JSON.stringify(names));
|
||||||
|
} catch (e) {
|
||||||
|
// Storage unavailable; the in-memory order still works this session.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadExpenses() {
|
export async function loadExpenses() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ export default StyleSheet.create({
|
|||||||
chipText: { color: palette.muted, fontWeight: "400", fontSize: 13, fontFamily: SUB },
|
chipText: { color: palette.muted, fontWeight: "400", fontSize: 13, fontFamily: SUB },
|
||||||
chipCount: { fontSize: 13, fontFamily: BODY },
|
chipCount: { fontSize: 13, fontFamily: BODY },
|
||||||
chipTextActive: { color: "#fff" },
|
chipTextActive: { color: "#fff" },
|
||||||
|
arrangeRow: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingVertical: 6, borderTopWidth: 1, borderTopColor: palette.line },
|
||||||
|
arrangeName: { fontSize: 15, color: palette.ink, fontFamily: SUB },
|
||||||
|
arrangeBtns: { flexDirection: "row", gap: 6 },
|
||||||
chipRow: { marginBottom: 4 },
|
chipRow: { marginBottom: 4 },
|
||||||
|
|
||||||
btnRow: { flexDirection: "row", gap: 8, marginTop: 14 },
|
btnRow: { flexDirection: "row", gap: 8, marginTop: 14 },
|
||||||
|
|||||||
BIN
icon-192.png
Normal file
BIN
icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
icon-512.png
Normal file
BIN
icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
65
index.html
65
index.html
@@ -7,7 +7,15 @@
|
|||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Petit+Formal+Script&family=Shadows+Into+Light+Two&family=Style+Script&family=Waterfall&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Petit+Formal+Script&family=Shadows+Into+Light+Two&family=Style+Script&family=Waterfall&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="styles.css?v=2">
|
<link rel="stylesheet" href="styles.css?v=3">
|
||||||
|
<link rel="manifest" href="manifest.json">
|
||||||
|
<meta name="theme-color" content="#ff6fae">
|
||||||
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||||
|
<meta name="apple-mobile-web-app-title" content="Tally">
|
||||||
|
<link rel="icon" href="icon-192.png">
|
||||||
|
<link rel="apple-touch-icon" href="icon-192.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="topbar-mini">
|
<header class="topbar-mini">
|
||||||
@@ -56,18 +64,13 @@
|
|||||||
<ul class="cats" id="catList"></ul>
|
<ul class="cats" id="catList"></ul>
|
||||||
|
|
||||||
<div class="side-foot">
|
<div class="side-foot">
|
||||||
<label class="field compact">
|
<div class="period-pick" role="group" aria-label="Total for period">
|
||||||
<span>Repeats</span>
|
<button type="button" class="btn subtle small" data-period="day">Today</button>
|
||||||
<select id="fFreqFilter" aria-label="Filter by repeat">
|
<button type="button" class="btn subtle small" data-period="week">Week</button>
|
||||||
<option value="all">All repeats</option>
|
<button type="button" class="btn subtle small" data-period="month">Month</button>
|
||||||
<option value="once">One-time</option>
|
</div>
|
||||||
<option value="daily">Daily</option>
|
|
||||||
<option value="weekly">Weekly</option>
|
|
||||||
<option value="monthly">Monthly</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<div class="month-total">
|
<div class="month-total">
|
||||||
<span>This month</span>
|
<span id="periodLabel">This month</span>
|
||||||
<strong id="sideMonth">$0.00</strong>
|
<strong id="sideMonth">$0.00</strong>
|
||||||
</div>
|
</div>
|
||||||
<div class="side-btns">
|
<div class="side-btns">
|
||||||
@@ -164,6 +167,42 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="app.js?v=2"></script>
|
<script src="app.js?v=3"></script>
|
||||||
|
<button type="button" id="btnUpdate" class="update-pill" hidden>Update to latest version</button>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
if (!("serviceWorker" in navigator)) return;
|
||||||
|
var btn = document.getElementById("btnUpdate");
|
||||||
|
function show() { btn.hidden = false; }
|
||||||
|
btn.addEventListener("click", function () {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = "Updating…";
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
navigator.serviceWorker.getRegistration().then(function (reg) {
|
||||||
|
if (reg && reg.waiting) reg.waiting.postMessage({ type: "SKIP_WAITING" });
|
||||||
|
else location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
navigator.serviceWorker.addEventListener("controllerchange", function () { location.reload(); });
|
||||||
|
window.addEventListener("load", function () {
|
||||||
|
navigator.serviceWorker.register("sw.js", { updateViaCache: "none" }).then(function (reg) {
|
||||||
|
if (reg.waiting) { show(); return; }
|
||||||
|
reg.addEventListener("updatefound", function () {
|
||||||
|
var w = reg.installing;
|
||||||
|
if (!w) return;
|
||||||
|
w.addEventListener("statechange", function () {
|
||||||
|
if (w.state === "installed" && navigator.serviceWorker.controller) show();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
function check() { reg.update().catch(function () {}); }
|
||||||
|
setInterval(check, 30 * 60 * 1000);
|
||||||
|
document.addEventListener("visibilitychange", function () { if (!document.hidden) check(); });
|
||||||
|
}).catch(function () { /* offline-first unavailable; the app still works */ });
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
15
manifest.json
Normal file
15
manifest.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "Tally",
|
||||||
|
"short_name": "Tally",
|
||||||
|
"description": "Daily, weekly and monthly expense tracking. Private by design.",
|
||||||
|
"start_url": "/",
|
||||||
|
"scope": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"orientation": "portrait",
|
||||||
|
"background_color": "#ffe3ee",
|
||||||
|
"theme_color": "#ff6fae",
|
||||||
|
"icons": [
|
||||||
|
{ "src": "icon-192.png", "sizes": "192x192", "type": "image/png" },
|
||||||
|
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" }
|
||||||
|
]
|
||||||
|
}
|
||||||
31
styles.css
31
styles.css
@@ -202,6 +202,9 @@ body.nav-open .side { transform: none; }
|
|||||||
padding: 1px 9px;
|
padding: 1px 9px;
|
||||||
}
|
}
|
||||||
.cat-item.active .count { background: rgba(255, 255, 255, 0.24); color: #fff; }
|
.cat-item.active .count { background: rgba(255, 255, 255, 0.24); color: #fff; }
|
||||||
|
.cats li[draggable="true"] { cursor: grab; }
|
||||||
|
.cats li.dragging { opacity: 0.45; }
|
||||||
|
.cats li.drag-over { box-shadow: 0 -3px 0 var(--accent); }
|
||||||
|
|
||||||
/* Sidebar footer card */
|
/* Sidebar footer card */
|
||||||
.side-foot {
|
.side-foot {
|
||||||
@@ -222,6 +225,8 @@ body.nav-open .side { transform: none; }
|
|||||||
}
|
}
|
||||||
.month-total strong { font-family: var(--font-display); font-weight: 400; font-size: 19px; color: var(--ink); }
|
.month-total strong { font-family: var(--font-display); font-weight: 400; font-size: 19px; color: var(--ink); }
|
||||||
.side-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
.side-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
||||||
|
.period-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
||||||
|
.period-pick .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
|
||||||
|
|
||||||
/* Main view header: big title + date subline, like the Tasks Today view. */
|
/* Main view header: big title + date subline, like the Tasks Today view. */
|
||||||
.view-head h2 { margin: 0; font-size: 35px; }
|
.view-head h2 { margin: 0; font-size: 35px; }
|
||||||
@@ -315,6 +320,8 @@ body.nav-open .side { transform: none; }
|
|||||||
.field { display: grid; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
|
.field { display: grid; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
|
||||||
.field input, .field select {
|
.field input, .field select {
|
||||||
font: inherit;
|
font: inherit;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 16px;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
background: var(--card);
|
background: var(--card);
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
@@ -330,6 +337,15 @@ body.nav-open .side { transform: none; }
|
|||||||
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||||
.form-err { color: var(--danger); font-size: 13px; margin: 0 0 10px; }
|
.form-err { color: var(--danger); font-size: 13px; margin: 0 0 10px; }
|
||||||
.form-btns { display: flex; gap: 8px; }
|
.form-btns { display: flex; gap: 8px; }
|
||||||
|
.update-pill {
|
||||||
|
position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 60;
|
||||||
|
font-family: var(--font-btn); font-size: 19px;
|
||||||
|
background: var(--accent); color: #fff; border: none; border-radius: 999px;
|
||||||
|
padding: 10px 22px; cursor: pointer;
|
||||||
|
box-shadow: 0 6px 20px rgba(214, 51, 132, 0.35);
|
||||||
|
}
|
||||||
|
.update-pill:hover { background: var(--accent-dark); }
|
||||||
|
.update-pill:disabled { opacity: 0.75; cursor: default; }
|
||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
.btn {
|
.btn {
|
||||||
@@ -408,6 +424,21 @@ body.nav-open .side { transform: none; }
|
|||||||
/* Footer */
|
/* Footer */
|
||||||
.foot { margin: 0; }
|
.foot { margin: 0; }
|
||||||
|
|
||||||
|
/* Small phones: single-column form, tighter rhythm, no overflow. */
|
||||||
|
@media (max-width: 520px) {
|
||||||
|
.wrap { padding: 0 12px; }
|
||||||
|
.topbar-mini { padding: 10px 12px 16px; }
|
||||||
|
.topbar-month { font-size: 14px; }
|
||||||
|
.card { padding: 14px; }
|
||||||
|
.row2 { grid-template-columns: 1fr; }
|
||||||
|
.row2 > * { min-width: 0; }
|
||||||
|
.view-head h2 { font-size: 28px; }
|
||||||
|
.bar-row { grid-template-columns: 96px 1fr 64px; gap: 8px; font-size: 12.5px; }
|
||||||
|
.stats { gap: 12px; }
|
||||||
|
.group-head { flex-wrap: wrap; row-gap: 2px; }
|
||||||
|
.form-btns { flex-wrap: wrap; }
|
||||||
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
* { transition: none !important; animation: none !important; }
|
* { transition: none !important; animation: none !important; }
|
||||||
}
|
}
|
||||||
|
|||||||
49
sw.js
Normal file
49
sw.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/* Tally service worker: offline shell + update prompts.
|
||||||
|
Bump CACHE on every deploy that changes the app. */
|
||||||
|
var CACHE = "tally-v3";
|
||||||
|
var SHELL = [
|
||||||
|
"/",
|
||||||
|
"/index.html",
|
||||||
|
"/styles.css",
|
||||||
|
"/app.js",
|
||||||
|
"/manifest.json",
|
||||||
|
"/icon-192.png",
|
||||||
|
"/icon-512.png"
|
||||||
|
];
|
||||||
|
|
||||||
|
self.addEventListener("install", function (e) {
|
||||||
|
// {cache:"reload"} bypasses the browser HTTP cache so a fresh deploy
|
||||||
|
// precaches new bytes instead of the stale responses it may hold.
|
||||||
|
e.waitUntil(caches.open(CACHE).then(function (c) {
|
||||||
|
return c.addAll(SHELL.map(function (u) { return new Request(u, { cache: "reload" }); }));
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("activate", function (e) {
|
||||||
|
e.waitUntil(caches.keys().then(function (keys) {
|
||||||
|
return Promise.all(keys.filter(function (k) { return k !== CACHE; }).map(function (k) {
|
||||||
|
return caches.delete(k);
|
||||||
|
}));
|
||||||
|
}).then(function () { return self.clients.claim(); }));
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("message", function (e) {
|
||||||
|
if (e.data && e.data.type === "SKIP_WAITING") self.skipWaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("fetch", function (e) {
|
||||||
|
var url = new URL(e.request.url);
|
||||||
|
if (e.request.method !== "GET" || url.origin !== self.location.origin) return;
|
||||||
|
// Shell URLs ignore the query string (?v= cache-buster): one entry per file.
|
||||||
|
var key = SHELL.indexOf(url.pathname) !== -1 ? url.pathname : e.request;
|
||||||
|
e.respondWith(caches.match(key, { cacheName: CACHE }).then(function (hit) {
|
||||||
|
if (hit) return hit;
|
||||||
|
return fetch(e.request).then(function (res) {
|
||||||
|
if (res && res.ok) {
|
||||||
|
var copy = res.clone();
|
||||||
|
caches.open(CACHE).then(function (c) { c.put(key, copy); });
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user