|
| 1 | +# Trending (Web) |
| 2 | + |
| 3 | +Minimal Vite + React app that renders **trending tracks** from Audius. Use this as a reference for: |
| 4 | + |
| 5 | +- **SDK setup** in a browser / Vite app (singleton, node polyfills) |
| 6 | +- **Fetching trending** via `sdk.tracks.getTrendingTracks()` |
| 7 | +- **Track artwork** with mirror fallback (try next CDN on image error) |
| 8 | +- **Play** via `sdk.tracks.getTrackStreamUrl()` + HTML5 `Audio` |
| 9 | +- **React Query** for caching and loading state |
| 10 | + |
| 11 | +Mirrors the [mobile trending example](../../mobile/examples/trending/): same SDK usage and hook shape, with a simple list UI. |
| 12 | + |
| 13 | +## How to run |
| 14 | + |
| 15 | +1. From the **apps repo root**, install and build the SDK if needed: |
| 16 | + |
| 17 | + ```bash |
| 18 | + npm install |
| 19 | + npm run build -w @audius/sdk |
| 20 | + ``` |
| 21 | + |
| 22 | +2. Install the example's dependencies and start Vite: |
| 23 | + |
| 24 | + ```bash |
| 25 | + cd packages/web/examples/trending |
| 26 | + npm install |
| 27 | + npm run dev |
| 28 | + ``` |
| 29 | + |
| 30 | + Or from repo root: `npm run web:example:trending` (run `npm install` in the example dir first). |
| 31 | + |
| 32 | +3. Open the URL shown (default `http://localhost:5174`). |
| 33 | + |
| 34 | +## Project layout |
| 35 | + |
| 36 | +| File | Purpose | |
| 37 | +|------|---------| |
| 38 | +| `index.html` | Entry HTML; script loads `src/main.tsx`. | |
| 39 | +| `src/main.tsx` | Mounts `App` into `#root`. | |
| 40 | +| `src/sdk.ts` | Singleton `getSDK()` — `sdk({ appName: 'AudiusWebExample' })`. | |
| 41 | +| `src/hooks/useTrendingTracks.ts` | React Query hook calling `getSDK().tracks.getTrendingTracks({ limit, offset, time })`. | |
| 42 | +| `src/App.tsx` | Renders trending list with artwork, play button, loading/error. Wraps app in `QueryClientProvider`. | |
| 43 | +| `src/components/TrackArtworkImage.tsx` | Track cover image with **mirror fallback**: on load error, tries `artwork.mirrors` by swapping host. | |
| 44 | +| `src/utils/artwork.ts` | `getArtworkUrl(artwork, size)`, `getNextMirrorUrl(url, mirrors)` for CDN fallback. | |
| 45 | +| `vite.config.ts` | React plugin + node polyfills (buffer, process) for SDK. | |
| 46 | + |
| 47 | +## Keywords (for search / AI) |
| 48 | + |
| 49 | +SDK setup, Vite, React, trending tracks, getTrendingTracks, Audius SDK, web example, node polyfills, singleton SDK, React Query. |
| 50 | + |
| 51 | +## Source of truth (implementation) |
| 52 | + |
| 53 | +- **SDK factory:** `packages/sdk/src/sdk/sdk.ts` — `sdk(config)` with `appName` (and optional `services`, `apiKey`, etc.). |
| 54 | +- **Tracks API:** `packages/sdk` — `getTrendingTracks(params)`. |
| 55 | +- **Mobile counterpart:** `packages/mobile/examples/trending/` — same pattern for Expo. |
0 commit comments