Period totals footer, category reorder, mobile fixes, PWA with update prompt

This commit is contained in:
2026-09-19 00:29:43 +00:00
parent e800ab82ff
commit 9e543bec1a
15 changed files with 339 additions and 44 deletions

View File

@@ -9,7 +9,7 @@ import ExpenseForm from "./src/components/ExpenseForm";
import ExpenseGroups from "./src/components/ExpenseGroups";
import RepeatTemplates from "./src/components/RepeatTemplates";
import SummaryBars from "./src/components/SummaryBars";
import { CATEGORIES } from "./src/categories";
import { CATEGORIES, applyCatOrder } from "./src/categories";
import {
addDaysStr,
groupKey,
@@ -21,7 +21,7 @@ import {
todayStr,
uid,
} from "./src/logic";
import { loadExpenses, saveExpenses } from "./src/storage";
import { loadExpenses, saveExpenses, loadCatOrder, saveCatOrder } from "./src/storage";
import s from "./src/styles";
const TABS = ["daily", "weekly", "monthly"];
@@ -37,7 +37,9 @@ export default function App() {
const [tab, setTab] = useState("daily");
const [query, setQuery] = useState("");
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 [pendingDeleteId, setPendingDeleteId] = useState(null);
const currency = "INR";
@@ -52,6 +54,7 @@ export default function App() {
setExpenses(list);
setReady(true);
});
loadCatOrder().then(setCatOrder);
}, []);
function update(list) {
@@ -103,11 +106,10 @@ export default function App() {
const q = query.trim().toLowerCase();
return expenses.filter((e) => {
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;
return true;
});
}, [expenses, query, catFilter, freqFilter]);
}, [expenses, query, catFilter]);
const groups = useMemo(() => {
const map = {};
@@ -144,6 +146,21 @@ export default function App() {
return { d, w, m, counts: { daily: dc, weekly: wc, monthly: mc }, catCounts: cats };
}, [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) {
setEditingId(id);
setPendingDeleteId(null);
@@ -161,7 +178,7 @@ export default function App() {
<Text style={[s.headerTotal, { fontSize: 20 }]}>{menuOpen ? "\u2715" : "\u2630"}</Text>
</Pressable>
</View>
<Text style={s.headerTotal}>{money(stats.m, currency)} this month</Text>
<Text style={s.headerTotal}>{money(periodTotal, currency)} {periodNoun}</Text>
</View>
<View style={s.card}>
@@ -183,6 +200,7 @@ export default function App() {
: blankForm()
}
submitLabel={editing ? "Save changes" : "Add expense"}
categories={orderedCats}
onSubmit={submitForm}
onCancel={editing ? () => setEditingId(null) : null}
currency={currency}
@@ -226,20 +244,41 @@ export default function App() {
<Pressable onPress={() => setCatFilter("all")} style={[s.chip, catFilter === "all" && s.chipActive]}>
<Text style={[s.chipText, catFilter === "all" && s.chipTextActive]}>All</Text>
</Pressable>
{CATEGORIES.map((c) => (
{orderedCats.map((c) => (
<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>
</Pressable>
))}
</View>
</ScrollView>
<Text style={s.label}>Repeats</Text>
<Pressable onPress={() => setArranging(!arranging)} style={[s.btn, s.btnSubtle, s.btnSmall, { alignSelf: "flex-start", marginTop: 8 }]}>
<Text style={s.btnSmallText}>{arranging ? "Done" : "Arrange"}</Text>
</Pressable>
{arranging ? (
<View style={{ marginTop: 4 }}>
{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>
<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}>
{["all", "once", "daily", "weekly", "monthly"].map((f) => (
<Pressable key={f} onPress={() => setFreqFilter(f)} style={[s.chip, freqFilter === f && s.chipActive]}>
<Text style={[s.chipText, freqFilter === f && s.chipTextActive]}>
{f === "all" ? "All" : f === "once" ? "One-time" : f.charAt(0).toUpperCase() + f.slice(1)}
</Text>
{[["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>
))}
</View>

View File

@@ -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
(Monday–Sunday) or by month, each group with its own total.
- **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
“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.

View File

@@ -16,3 +16,12 @@ export function colorFor(category) {
const found = CATEGORIES.find((c) => c.name === category);
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;
}

View File

@@ -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 [amount, setAmount] = useState(initial.amount);
const [cat, setCat] = useState(initial.category);
@@ -61,7 +61,7 @@ export default function ExpenseForm({ initial, submitLabel, onSubmit, onCancel,
<Text style={s.label}>Category</Text>
<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)} />
))}
</View>

View File

@@ -4,6 +4,25 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
import { seedSamples } from "./logic";
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() {
try {

View File

@@ -64,6 +64,9 @@ export default StyleSheet.create({
chipText: { color: palette.muted, fontWeight: "400", fontSize: 13, fontFamily: SUB },
chipCount: { fontSize: 13, fontFamily: BODY },
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 },
btnRow: { flexDirection: "row", gap: 8, marginTop: 14 },