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>