@youversion/platform-react-hooks 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/AGENTS.md +183 -0
- package/CHANGELOG.md +8 -0
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @youversion/platform-react-hooks@1.8.
|
|
2
|
+
> @youversion/platform-react-hooks@1.8.1 build /home/runner/work/platform-sdk-react/platform-sdk-react/packages/hooks
|
|
3
3
|
> tsc -p tsconfig.build.json
|
|
4
4
|
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @youversion/platform-react-hooks
|
|
2
|
+
|
|
3
|
+
## OVERVIEW
|
|
4
|
+
React integration layer providing data fetching hooks with 3 core providers: YouVersionProvider, YouVersionAuthProvider, and ReaderProvider.
|
|
5
|
+
|
|
6
|
+
**Depends on `@youversion/platform-core` for all API calls.** Hooks delegate to core clients; do not implement raw HTTP here.
|
|
7
|
+
|
|
8
|
+
**Related packages:**
|
|
9
|
+
- For lower-level API clients → see `packages/core/AGENTS.md`
|
|
10
|
+
- For pre-built UI components → see `packages/ui/AGENTS.md`
|
|
11
|
+
|
|
12
|
+
## STRUCTURE
|
|
13
|
+
- `use*.ts` - Data fetching hooks (useBook, useChapter, usePassage, useVersion, etc.)
|
|
14
|
+
- `context/` - Providers and contexts (separate files, exported via index.ts)
|
|
15
|
+
- `utility/` - Helper functions (useDebounce, extractTextFromHTML, extractVersesFromHTML)
|
|
16
|
+
|
|
17
|
+
## PUBLIC API
|
|
18
|
+
- Data fetching hooks: useBook, useChapter, usePassage, useVersion, useVOTD, useVerse, useChapterNavigation, etc.
|
|
19
|
+
- YouVersionProvider - Core SDK configuration
|
|
20
|
+
- YouVersionAuthProvider - Authentication state
|
|
21
|
+
- ReaderProvider - Reading session context
|
|
22
|
+
- Utility functions exported from utility/index
|
|
23
|
+
|
|
24
|
+
## PROVIDERS
|
|
25
|
+
|
|
26
|
+
- **YouVersionProvider**
|
|
27
|
+
- Holds core SDK configuration (API base URL, clients)
|
|
28
|
+
- Wrap this around your app before using any data hooks
|
|
29
|
+
|
|
30
|
+
- **YouVersionAuthProvider**
|
|
31
|
+
- Manages authentication state (userInfo, tokens, isLoading, error)
|
|
32
|
+
- Auth hooks like `useYVAuth` depend on this provider
|
|
33
|
+
|
|
34
|
+
- **ReaderProvider**
|
|
35
|
+
- Manages Bible reading session state (currentVersion, currentChapter, currentBook, currentVerse)
|
|
36
|
+
- Hooks like `useChapterNavigation` depend on this provider
|
|
37
|
+
|
|
38
|
+
## DOs / DON'Ts
|
|
39
|
+
|
|
40
|
+
✅ Do: Use `YouVersionProvider` for configuration and access that config in hooks
|
|
41
|
+
✅ Do: Wrap async data access in hooks rather than calling core clients directly in components
|
|
42
|
+
✅ Do: Keep hooks **UI-agnostic** (no JSX returned, no direct DOM manipulation)
|
|
43
|
+
✅ Do: Use the `useApiData` pattern for new data fetching hooks
|
|
44
|
+
|
|
45
|
+
❌ Don't: Import components from `@youversion/platform-react-ui`
|
|
46
|
+
❌ Don't: Talk directly to `fetch`/HTTP; always use `@youversion/platform-core`
|
|
47
|
+
❌ Don't: Access `window.localStorage` directly for auth; rely on core's storage abstractions
|
|
48
|
+
|
|
49
|
+
## DATA FETCHING PATTERN
|
|
50
|
+
|
|
51
|
+
Hooks use a custom React Query-like pattern via `useApiData`:
|
|
52
|
+
- Returns `{ data, loading, error, refetch }`
|
|
53
|
+
- Provides caching and refetch capability
|
|
54
|
+
- New hooks should follow this same pattern
|
|
55
|
+
|
|
56
|
+
## CONVENTIONS
|
|
57
|
+
- Context and Provider in separate files
|
|
58
|
+
- All contexts exported via context/index.ts
|
|
59
|
+
- TypeScript declarations generated separately (no bundling)
|
|
60
|
+
- Build: tsc only
|
|
61
|
+
|
|
62
|
+
## USAGE EXAMPLES
|
|
63
|
+
|
|
64
|
+
### Provider Setup (Required)
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
// Wrap your app with YouVersionProvider before using any hooks
|
|
68
|
+
import { YouVersionProvider } from '@youversion/platform-react-hooks';
|
|
69
|
+
|
|
70
|
+
function App() {
|
|
71
|
+
return (
|
|
72
|
+
<YouVersionProvider
|
|
73
|
+
appKey="your-app-key"
|
|
74
|
+
theme="light" // "light" | "dark"
|
|
75
|
+
>
|
|
76
|
+
<MyApp />
|
|
77
|
+
</YouVersionProvider>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// With authentication enabled
|
|
82
|
+
function AppWithAuth() {
|
|
83
|
+
return (
|
|
84
|
+
<YouVersionProvider
|
|
85
|
+
appKey="your-app-key"
|
|
86
|
+
includeAuth={true}
|
|
87
|
+
authRedirectUrl="https://myapp.com/callback"
|
|
88
|
+
>
|
|
89
|
+
<MyApp />
|
|
90
|
+
</YouVersionProvider>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Data Fetching Hooks
|
|
96
|
+
|
|
97
|
+
All data hooks return `{ data, loading, error, refetch }`:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useChapter, useVersion, useVerseOfTheDay } from '@youversion/platform-react-hooks';
|
|
101
|
+
|
|
102
|
+
// Fetch a Bible chapter
|
|
103
|
+
function ChapterView() {
|
|
104
|
+
const { chapter, loading, error } = useChapter(
|
|
105
|
+
111, // versionId (e.g., 111 = NIV)
|
|
106
|
+
'JHN', // book (USFM abbreviation)
|
|
107
|
+
3 // chapter number
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (loading) return <div>Loading...</div>;
|
|
111
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
112
|
+
return <div>{chapter?.content}</div>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Fetch Bible version metadata
|
|
116
|
+
function VersionInfo() {
|
|
117
|
+
const { version, loading } = useVersion(111);
|
|
118
|
+
if (loading) return <div>Loading...</div>;
|
|
119
|
+
return <div>{version?.name} ({version?.abbreviation})</div>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Fetch Verse of the Day
|
|
123
|
+
function DailyVerse() {
|
|
124
|
+
const dayOfYear = Math.floor((Date.now() - new Date(new Date().getFullYear(), 0, 0).getTime()) / 86400000);
|
|
125
|
+
const { data: votd, loading, refetch } = useVerseOfTheDay(dayOfYear);
|
|
126
|
+
|
|
127
|
+
if (loading) return <div>Loading...</div>;
|
|
128
|
+
return (
|
|
129
|
+
<div>
|
|
130
|
+
<p>{votd?.verse.text}</p>
|
|
131
|
+
<button onClick={refetch}>Refresh</button>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Authentication Hook
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { useYVAuth } from '@youversion/platform-react-hooks';
|
|
141
|
+
|
|
142
|
+
function AuthExample() {
|
|
143
|
+
const { auth, userInfo, signIn, signOut } = useYVAuth();
|
|
144
|
+
|
|
145
|
+
if (auth.isLoading) return <div>Loading...</div>;
|
|
146
|
+
|
|
147
|
+
if (!auth.isAuthenticated) {
|
|
148
|
+
return (
|
|
149
|
+
<button onClick={() => signIn({ redirectUrl: window.location.origin + '/callback' })}>
|
|
150
|
+
Sign In with YouVersion
|
|
151
|
+
</button>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<p>Welcome, {userInfo?.name}!</p>
|
|
158
|
+
<button onClick={signOut}>Sign Out</button>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Conditional Fetching
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
// Use the `enabled` option to conditionally fetch
|
|
168
|
+
function ConditionalFetch({ versionId }: { versionId: number | null }) {
|
|
169
|
+
const { version, loading } = useVersion(versionId ?? 0, {
|
|
170
|
+
enabled: versionId !== null, // Only fetch when versionId is provided
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ...
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## TESTING
|
|
178
|
+
|
|
179
|
+
- Run tests: `pnpm --filter @youversion/platform-react-hooks test`
|
|
180
|
+
- Framework: Vitest with jsdom environment
|
|
181
|
+
- React Testing Library for component/hook tests
|
|
182
|
+
- Mock object factories live in `__tests__/mocks` (not MSW - hooks delegate HTTP to core)
|
|
183
|
+
- Use provider wrappers for tests so hooks see the same context as in the app
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @youversion/platform-react-hooks
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 607be3c: Refactor verse HTML transformation to support verse-level highlighting. Extract HTML processing logic to `verse-html-utils.ts` with new `wrapVerseContent()` function that wraps verse content in CSS-targetable `<span class="yv-v">` elements. Simplify footnote extraction using wrapped verse structure. Remove CSS rule preventing text wrapping. Add comprehensive test coverage for verse wrapping behavior.
|
|
8
|
+
- Updated dependencies [607be3c]
|
|
9
|
+
- @youversion/platform-core@1.8.1
|
|
10
|
+
|
|
3
11
|
## 1.8.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youversion/platform-react-hooks",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@youversion/platform-core": "1.8.
|
|
25
|
+
"@youversion/platform-core": "1.8.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=19.1.0 <20.0.0"
|