feat(market): fix publish-duplicates, add offer detail page + filters

The vecino/market view had three gaps:

- Publishing inventory duplicated the listing. discover() appended every
  offer the relay streamed, but relays legitimately resend an addressable
  NIP-99 event (stored copy + live echo on publish). Merge by
  (authorPubkeyHex, id) so each offer appears once; two authors reusing a
  lot id stay distinct.
- No product detail. Tapping a card jumped straight to chat. Add a
  read-only "product page" (MarketOfferDetailScreen) with title, mode,
  category, eco badge, coarse location, price, a "Shared by" seller
  section (profile fetched by pubkey) and the message button. Reached via
  a new /market/offer route; cards are now fully tappable. Shows only what
  the network already carries — no photos/description added to the wire.
- No filters. Add a filter bar (type, category, eco) mirroring inventory,
  each chip group shown only when a discovered offer can match it. To make
  the eco filter real, publish the organic flag on the wire: Offer.isOrganic
  -> NIP-99 'organic' tag -> OfferMapper -> ShareableLot.

Tests: commons_core organic round-trip; app-side dedup, two-author
separation, filter logic, mapper passthrough; detail-screen widget tests.
i18n keys added to en/es/pt/ast and slang regenerated.
This commit is contained in:
vjrj 2026-07-10 19:10:40 +02:00
parent e852b569ce
commit 54d7c2d3b5
21 changed files with 982 additions and 107 deletions

View file

@ -11,6 +11,7 @@ import '../services/offer_outbox.dart';
import '../services/social_service.dart';
import '../services/social_settings.dart';
import '../state/offers_cubit.dart';
import 'market_widgets.dart';
import 'theme.dart';
/// The market (redesign screens 04/05): discover seeds shared near you. Opens
@ -300,6 +301,7 @@ class MarketBody extends StatelessWidget {
onChanged: cubit.search,
),
),
_MarketFilterBar(state: state),
Expanded(
child: RefreshIndicator(
onRefresh: refresh,
@ -329,10 +331,8 @@ class MarketBody extends StatelessWidget {
return _OfferCard(
offer: o,
mine: mine,
onContact: mine
? null
: () =>
context.push('/chat/${o.authorPubkeyHex}'),
onTap: () =>
context.push('/market/offer', extra: o),
);
},
),
@ -348,119 +348,177 @@ class MarketBody extends StatelessWidget {
/// One discovered offer. Human words for the reciprocity mode; coarse "near you"
/// instead of any precise location; price only when it's a sale.
class _OfferCard extends StatelessWidget {
const _OfferCard({required this.offer, this.mine = false, this.onContact});
const _OfferCard({required this.offer, this.mine = false, this.onTap});
final Offer offer;
/// Whether this is the current user's own listing (shown with a "You" badge).
final bool mine;
/// Opens a private chat with the author; null for our own listings.
final VoidCallback? onContact;
/// Opens the offer's detail ("product") page.
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final t = context.t;
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: seedOutline),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
final radius = BorderRadius.circular(14);
return Material(
color: Colors.white,
borderRadius: radius,
child: InkWell(
key: Key('market.offer.${offer.authorPubkeyHex}.${offer.id}'),
onTap: onTap,
borderRadius: radius,
child: Container(
decoration: BoxDecoration(
borderRadius: radius,
border: Border.all(color: seedOutline),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
offer.summary,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: seedOnSurface,
),
),
),
if (mine) ...[
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: seedGreen,
borderRadius: BorderRadius.circular(20),
),
child: Text(
t.market.mine,
style: const TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w700,
Row(
children: [
Expanded(
child: Text(
offer.summary,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: seedOnSurface,
),
),
),
),
const SizedBox(width: 6),
],
_TypeChip(label: _offerTypeLabel(t, offer.type)),
if (mine) ...[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: seedGreen,
borderRadius: BorderRadius.circular(20),
),
child: Text(
t.market.mine,
style: const TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(width: 6),
],
OfferTypeChip(label: offerTypeLabel(t, offer.type)),
],
),
const SizedBox(height: 6),
Row(
children: [
const Icon(Icons.place_outlined, size: 15, color: seedMuted),
const SizedBox(width: 4),
Text(t.market.near,
style: const TextStyle(color: seedMuted, fontSize: 13)),
if (offer.isOrganic) ...[
const SizedBox(width: 10),
const Icon(Icons.eco, size: 15, color: seedGreen),
],
const Spacer(),
if (offer.type == OfferType.sale && offer.priceAmount != null)
Text(
'${offer.priceAmount} ${offer.priceCurrency ?? ''}'.trim(),
style: const TextStyle(
color: seedOnSurface,
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 4),
const Icon(Icons.chevron_right, size: 18, color: seedMuted),
],
),
],
),
const SizedBox(height: 6),
Row(
children: [
const Icon(Icons.place_outlined, size: 15, color: seedMuted),
const SizedBox(width: 4),
Text(t.market.near, style: const TextStyle(color: seedMuted, fontSize: 13)),
const Spacer(),
if (offer.type == OfferType.sale && offer.priceAmount != null)
Text(
'${offer.priceAmount} ${offer.priceCurrency ?? ''}'.trim(),
style: const TextStyle(
color: seedOnSurface,
fontWeight: FontWeight.w600,
),
),
if (onContact != null)
TextButton.icon(
onPressed: onContact,
icon: const Icon(Icons.chat_bubble_outline, size: 16),
label: Text(t.market.contact),
),
],
),
],
),
),
);
}
}
String _offerTypeLabel(Translations t, OfferType type) => switch (type) {
OfferType.gift => t.share.gift,
OfferType.exchange => t.share.exchange,
OfferType.sale => t.share.sell,
OfferType.wanted => t.market.wanted,
OfferType.lend => t.share.exchange,
};
/// Optional filters over the discovered offers, mirroring the inventory filter
/// bar: reciprocity mode (give/swap/sell/wanted), category, and the eco flag.
/// Each chip group only appears when some discovered offer can match it.
class _MarketFilterBar extends StatelessWidget {
const _MarketFilterBar({required this.state});
class _TypeChip extends StatelessWidget {
const _TypeChip({required this.label});
final String label;
final OffersState state;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: seedPrimaryContainer,
borderRadius: BorderRadius.circular(20),
),
child: Text(
label,
style: const TextStyle(
color: seedOnPrimaryContainer,
fontSize: 12,
fontWeight: FontWeight.w600,
final t = context.t;
final cubit = context.read<OffersCubit>();
final categories = state.categories;
// Only offer type chips for modes some discovered offer actually holds.
final types = <OfferType>[
for (final type in const [
OfferType.gift,
OfferType.exchange,
OfferType.sale,
OfferType.wanted,
])
if (state.offers.any((o) => o.type == type)) type,
];
final hasOrganic = state.hasOrganic;
if (categories.isEmpty && types.isEmpty && !hasOrganic) {
return const SizedBox.shrink();
}
final chips = <Widget>[
if (hasOrganic)
FilterChip(
key: const Key('market.filter.organic'),
avatar: Icon(
Icons.eco,
size: 18,
color: state.organicOnly ? null : seedGreen,
),
label: Text(t.editVariety.organic),
selected: state.organicOnly,
onSelected: (_) => cubit.toggleOrganicOnly(),
),
for (final type in types)
FilterChip(
key: Key('market.filter.type.${type.name}'),
label: Text(offerTypeLabel(t, type)),
selected: state.typeFilter.contains(type),
onSelected: (_) => cubit.toggleType(type),
),
for (final category in categories)
FilterChip(
key: Key('market.filter.category.$category'),
label: Text(category),
selected: state.categoryFilter.contains(category),
onSelected: (_) => cubit.toggleCategory(category),
),
];
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Row(
children: [
for (final chip in chips)
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: chip,
),
if (state.hasActiveFilter)
TextButton.icon(
key: const Key('market.filter.clear'),
onPressed: cubit.clearFilters,
icon: const Icon(Icons.clear, size: 18),
label: Text(t.inventory.clearFilters),
),
],
),
);
}