Skip to content

refactor: update app module imports, enhance PWA support, and improve…#104

Open
D240021 wants to merge 1 commit intocode-flexing:mainfrom
D240021:main
Open

refactor: update app module imports, enhance PWA support, and improve…#104
D240021 wants to merge 1 commit intocode-flexing:mainfrom
D240021:main

Conversation

@D240021
Copy link
Copy Markdown

@D240021 D240021 commented Mar 29, 2026

Issue

Closes #48

Summary

This work delivers a mobile-first dashboard with offline-capable core flows, local persistence (IndexedDB via Dexie), automatic sync when connectivity returns, and PWA support (service worker + web app manifest). The goal is to let farmers view progress, vault balances, and AI-related content without a network connection, with data reconciled when back online.


What was implemented

Progressive Web App (PWA)

  • Integrated @ducanh2912/next-pwa (Workbox under the hood) in next.config.ts.
  • Added public/manifest.json and public/icons/icon.svg for installability and theming.
  • Configured fallbacks.document to /offline so navigation has a precached offline fallback when both network and cache miss.
  • Next.js 16 defaults to Turbopack; dev and build scripts use --webpack so the PWA plugin (webpack-based) runs correctly.
  • Service worker is disabled in development; use npm run build + npm run start to test the full PWA.

Local storage & IndexedDB (Dexie)

  • Added dexie with a dedicated database (harvest-finance-offline) storing:
    • Cached seasonal tips API responses
    • Vault snapshots (serializable vault rows + icon keys)
    • AI chat messages and last insights for offline display
    • Sync queue entries for deferred actions (e.g. chat while offline)
    • Client id and last sync metadata

Synchronization

  • POST /api/v1/sync: server-side merge with last-write-wins using per-resource timestamps (seasonalTipsAt, vaultsAt, aiAt), persisting merged state under the Next.js app’s data/ directory (file-backed; suitable to replace with PostgreSQL/Supabase/Nest later).
  • pushSync() runs when the app detects online again (useOfflineSync + useOnlineStatus).

Mobile-oriented UI (dashboard area)

  • DashboardShell: mobile header, touch-friendly targets, safe-area padding, slide-out navigation drawer wired to the menu button (previously non-functional on small screens).
  • OfflineIndicator: clear online/offline status for users.
  • Dashboard page layout tuned for small screens (spacing, full-width primary actions where appropriate).

Feature wiring

  • Seasonal tips: loads from IndexedDB first; on network failure, falls back to cached tips if available.
  • Vault overview: aligned with VaultCard; loads/saves default vault list to IndexedDB for offline viewing; deposit/withdraw modals guard against vault === null during SSR/prerender.
  • AI assistant: persists chat to IndexedDB; offline sends enqueue sync items and shows a message using cached insights when possible; successful online responses are saved locally.

Supporting / repo fixes (needed for a clean build)

  • Resolved merge conflicts in backend app.module.ts and frontend portfolio/page.tsx.
  • Added clsx and tailwind-merge (used by cn()).
  • Adjusted a few UI prop types (e.g. Card/Badge variants, Stack gap vs spacing) and Stellar Freighter API usage (getPublicKeygetAddress).
  • Minor fixes so TypeScript and static generation succeed (e.g. modals with nullable vault).

How to verify

  1. npm run build && npm run start in the frontend.
  2. Open the dashboard, then DevTools → NetworkOffline and reload; cached shell and stored data should still be usable.
  3. Check Application → IndexedDB → harvest-finance-offline for stored records.
  4. Toggle back online and confirm /api/v1/sync requests in the Network tab when sync runs.

Out of scope / follow-ups

  • Supabase/PostgreSQL and NestJS conflict APIs are described in the original issue as the long-term backend; this iteration implements sync on the Next.js API with a file store as a concrete, testable contract that can be swapped for a real DB later.
  • Background Sync API (browser background sync) is not fully custom-implemented; online event + explicit pushSync() covers “sync when connectivity is restored” for this codebase.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

@D240021 is attempting to deploy a commit to the vic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

Hey @D240021! 👋 It looks like this PR isn't linked to any issue.

If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g., Closes #123), or by clicking a button below:

Issue Title
#77 🚀 Issue #48 — Mobile-First Offline Dashboard Link to this issue

ℹ️ Learn more about linking PRs to issues

@vic-Gray
Copy link
Copy Markdown
Collaborator

vic-Gray commented Apr 1, 2026

@D240021 pls resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📥 Issue #18 — Implement Transaction History Export / Download

2 participants