feat(filters): add No tags filter to transactions and shared pages

This commit is contained in:
2026-04-13 05:20:49 +10:00
parent 1296555f17
commit 1b561af9e9
4 changed files with 42 additions and 13 deletions
+19 -5
View File
@@ -40,12 +40,20 @@ function TagFilter({ value, onChange }: { value: string[]; onChange: (v: string[
return () => document.removeEventListener("mousedown", handler);
}, []);
if (!tags.length) return null;
const toggle = (id: string) =>
onChange(value.includes(id) ? value.filter((x) => x !== id) : [...value, id]);
const toggle = (id: string) => {
let next: string[];
if (value.includes(id)) {
next = value.filter((x) => x !== id);
} else if (id === "untagged") {
next = ["untagged"];
} else {
next = [...value.filter((x) => x !== "untagged"), id];
}
onChange(next);
};
const label = value.length === 0 ? "All Tags"
: value.includes("untagged") ? "No tags"
: value.length === 1 ? (tags.find((t) => String(t.id) === value[0])?.name ?? "1 tag")
: `${value.length} tags`;
@@ -61,6 +69,11 @@ function TagFilter({ value, onChange }: { value: string[]; onChange: (v: string[
</button>
{open && (
<div className="absolute top-full mt-1 z-20 bg-zinc-900 border border-zinc-700 rounded-lg shadow-xl min-w-[160px] max-h-56 overflow-y-auto">
<label className="flex items-center gap-2 px-3 py-1.5 hover:bg-zinc-800 cursor-pointer text-sm border-b border-zinc-800">
<input type="checkbox" checked={value.includes("untagged")} onChange={() => toggle("untagged")}
className="accent-indigo-500 flex-shrink-0" />
<span className="text-zinc-400 italic">No tags</span>
</label>
{tags.map((t) => (
<label key={t.id} className="flex items-center gap-2 px-3 py-1.5 hover:bg-zinc-800 cursor-pointer text-sm">
<input type="checkbox" checked={value.includes(String(t.id))} onChange={() => toggle(String(t.id))}
@@ -259,8 +272,9 @@ function PaymentHistory({ participantId, currentUserId }: { participantId: numbe
// ── Main page ─────────────────────────────────────────────────────────────────
export default function SharedPage() {
const [tagIds, setTagIds] = useState<string[]>([]);
const realTagIds = tagIds.filter((id) => id !== "untagged");
const { data: transactions = [], isLoading: txLoading } = useSharedTransactions(tagIds);
const { data: balances = [], isLoading: balLoading } = useParticipantBalances(tagIds);
const { data: balances = [], isLoading: balLoading } = useParticipantBalances(realTagIds);
const { data: me } = useCurrentUser();
const [addingParticipant, setAddingParticipant] = useState(false);
const [paymentModal, setPaymentModal] = useState<{ id: number; name: string; balance: number } | null>(null);