Skip to content

feat(share): region-aware targets + native Web Share via react-share #61

Closed

Description

@Ardnived

Summary

Atlas event sharing is hand-rolled and static: ShareContent (src/components/molecules/ShareContent/ShareContent.tsx) renders a fixed row of 5 share targets (Email, Facebook, X, LinkedIn, Flipboard) from inline intent-URL templates, with no Web Share API and no awareness of who is sharing or from where. Meditation events are shared globally — a viewer in Russia wants VK/Telegram, one in Japan wants LINE, one in India wants WhatsApp — yet every viewer sees the same five Western targets, and mobile users never get their native OS share sheet (the one surface that already knows their installed apps). This replaces the mechanism with a comprehensive, library-backed one: react-share for broad global + region-specific coverage, the native Web Share API on capable devices, and a small region→platforms map that orders targets to the viewer's region.

Research finding: no single library covers all three needs (broad + region-specific platforms, region filtering, Web Share API). The architecture is react-share (base — React 18, TS, tree-shakeable, zero <head>/SDK assumptions, so safe inside the <sahaj-atlas> embed) + a tiny self-authored navigator.share wrapper + a hand-maintained country → ordered platforms map (no npm package provides per-region platform preferences).

Relationship to #52: WS7 adds the resolver summary header above ShareContent; it does not touch the share targets. This ticket replaces the targets/mechanism inside ShareContent; the two are complementary (PR #58 line).

Current behavior

  • ShareContent({ label, url }) hardcodes a socials array of 5 intent URLs (ShareContent.tsx:72-93), rendered as <Link target="_blank"> around house SVG icons — identical for every viewer, region, and device.
  • No navigator.share anywhere in the repo — mobile users never get the native sheet.
  • label/url are encodeURI'd then interpolated into intent URLs (ShareContent.tsx:70-71), which double-encodes once a library that encodes internally takes over (fix in passing).
  • Share icons are hand-drawn SVGs in src/components/atoms/Icons/socials.tsx.
  • Two consumers pass only label+url: ShareView.tsx:36 and RegistrationForm.tsx:111 (registration thank-you screen).

Proposed improvement

Confirmed product decisions:

  • Region signal → the viewer's location (not the event's country). From useIpLocation() (extended to expose the ISO country_code) with a locale-region-subtag fallback, then a universal default.
  • Mobile → native-first, grid fallback, keyed on navigator.share capability (not UA): when available, one prominent "Share…" button opens the native sheet (which surfaces the user's installed apps — WhatsApp, KakaoTalk, WeChat, SMS — the ultimate region filter); otherwise render the region-filtered button grid. Copy-link always visible. If a native call fails (a host page can disable web-share via Permissions-Policy → NotAllowedError), reveal the grid so the user is never stranded.
  • Icons → react-share's bundled icon components, and remove the in-house social-share icons react-share replaces (Email, Facebook, X/Twitter, LinkedIn, VK) plus Flipboard (dropped — react-share has no Flipboard button). Keep the meeting glyphs (Zoom, Google Meet, YouTube).

Changes:

  • Add react-share (pnpm add; named imports only so Vite tree-shakes to the ~5–8 buttons actually rendered).
  • New pure src/lib/share/platforms.ts: a PlatformKey union, DEFAULT_PLATFORMS, a PLATFORMS_BY_COUNTRY map (ISO alpha-2 → ordered list, seeded from DataReportal, hand-maintained) and platformsForCountry(code?). Platforms: WhatsApp, Telegram, Facebook, X, LinkedIn, Reddit, Email, VK, OK.ru, LINE, Viber, Weibo. (KakaoTalk/WeChat/Zalo/SMS have no web-share URL → native sheet only.)
  • Extend IpLocationSchema (src/types/ip-location.ts) with optional country_code; new thin hook src/hooks/use-viewer-country.ts (IP → locale subtag → undefined).
  • New src/hooks/use-web-share.ts: SSR-safe { canShare, share } wrapper over navigator.share.
  • New src/components/molecules/ShareContent/platform-buttons.tsx: PlatformKey → react-share *ShareButton + *Icon renderer, each with an i18n aria-label.
  • Refactor ShareContent: keep CopyField + the label/url API, add an optional country? prop (resolved by the consumers so the molecule stays pure/SSR-testable), drop the encodeURI double-encode, render native-button-or-grid.
  • Wire ShareView + RegistrationForm to resolve viewer country via useViewerCountry() and pass country.
  • Remove the replaced icons from socials.tsx; trim the SOCIAL_ICONS/SocialIcon dispatcher and the Icons.stories.tsx gallery.
  • Add i18n aria-label keys (share.share_on with %{platform}, share.native) across all locales via pnpm i18n:add.

Acceptance criteria

  • react-share added; only named *ShareButton/*Icon imports (tree-shaken); embed.js gzip delta noted in the PR
  • platformsForCountry returns a region-ordered list for seeded countries (RU→VK/OK/Telegram, JP→LINE, IN→WhatsApp, US→X/Facebook) and DEFAULT_PLATFORMS for unknown/undefined; case-insensitive
  • Share drawer shows the region-filtered grid on desktop; each button opens the correct platform composer with the right URL/title (no double-encoding)
  • On a navigator.share-capable device a "Share…" button opens the native OS sheet; the grid is the fallback when unavailable or when the native call is blocked; copy-link always present
  • Viewer country resolves from useIpLocation().country_code with a locale-subtag fallback and a graceful default (no error when both are absent)
  • ShareContent stays pure/prop-driven (label, url, optional country); both consumers (ShareView, RegistrationForm) keep working
  • In-house social-share icons replaced by react-share are removed (Email/Facebook/Twitter/LinkedIn/VK/Flipboard); meeting glyphs (Zoom/Meet/YouTube) kept; dispatcher + icon story updated; no dangling references
  • Platform aria-labels added across all 10 locales (%{} interpolation) via pnpm i18n:add
  • Unit tests (node-only, renderToStaticMarkup): platformsForCountry selector, ShareContent grid output for ≥2 regions + a raw-URL assertion, useWebShare detection
  • Ladle stories demo region variants (a country arg on ShareContent; seeded ['ip-location'] on ShareView)
  • Lint + typecheck + test:run + build + ladle:build pass

Files affected

  • src/components/molecules/ShareContent/ShareContent.tsx (+ new platform-buttons.tsx, story, test)
  • src/lib/share/platforms.ts (new, + test)
  • src/hooks/use-web-share.ts, src/hooks/use-viewer-country.ts (new)
  • src/types/ip-location.ts (add country_code)
  • src/views/ShareView/ShareView.tsx (+ story), src/components/organisms/RegistrationForm/RegistrationForm.tsx
  • src/components/atoms/Icons/socials.tsx, src/components/atoms/Icons/Icons.stories.tsx
  • public/locales/<lng>/common.json (aria-label keys)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions