Skip to content

Commit 5400b80

Browse files
authored
Add web examples (#13797)
1 parent de5972e commit 5400b80

17 files changed

Lines changed: 4567 additions & 3 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"web:stage": "npm run start:stage -w @audius/web",
3434
"web:e2e": "npm run test:e2e -w @audius/web",
3535
"web:test": "turbo run test --filter=@audius/web",
36+
"web:example:trending": "cd packages/web/examples/trending && npm run dev",
3637
"DESKTOP====================================": "",
3738
"desktop:dev": "concurrently -k 'BROWSER=none npm run start:dev -w @audius/web' 'wait-on http://0.0.0.0:3000 && npm run electron:localhost -w @audius/web -- 3000'",
3839
"desktop:prod": "concurrently -k 'BROWSER=none npm run start:prod -w @audius/web' 'wait-on http://0.0.0.0:3002 && npm run electron:localhost -w @audius/web -- 3002'",
@@ -50,6 +51,8 @@
5051
"mobile:example:trending": "cd packages/mobile/examples/trending && npx expo start",
5152
"mobile:example:auth-sign-in": "cd packages/mobile/examples/auth-sign-in && npx expo start",
5253
"mobile:example:authenticated-writes": "cd packages/mobile/examples/authenticated-writes && npx expo start",
54+
"mobile:example:like-repost": "cd packages/mobile/examples/like-repost && npx expo start",
55+
"mobile:example:upload": "cd packages/mobile/examples/upload && npx expo start",
5356
"EMBED======================================": "",
5457
"embed:prod": "npm run start:prod -w embed",
5558
"embed:stage": "npm run start:stage -w embed",

packages/web/examples/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Web Examples
2+
3+
Runnable examples for building Audius-style web features (Vite + React). Use these when implementing **SDK setup**, **trending/read APIs**, or similar capabilities so that AIs and developers can find reference implementations quickly.
4+
5+
## Available examples
6+
7+
| Example | Description | How to run |
8+
|--------|-------------|------------|
9+
| [trending](./trending/) | **Vite + React**: SDK setup + trending tracks (mirrors mobile trending example). | From repo root: `cd packages/web/examples/trending && npm install && npm run dev` or `npm run web:example:trending`. Build SDK first: `npm run build -w @audius/sdk`. |
10+
11+
## Quick start
12+
13+
From the **apps repo root**:
14+
15+
```bash
16+
npm install
17+
npm run build -w @audius/sdk
18+
cd packages/web/examples/trending
19+
npm install
20+
npm run dev
21+
```
22+
23+
Open the URL shown (default `http://localhost:5174`).
24+
25+
## Keywords (for search / AI)
26+
27+
SDK setup, Vite, React, trending tracks, getTrendingTracks, Audius SDK, web example, React Query.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Trending on Audius – Web Example</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)