Skip to content

Conversation

@bmanquen
Copy link
Collaborator

Add a hook to get a specific language.

- fix languages api response data schema
- update existing useLanguages tests
- update mock data for languages
- update vitest coverage to include all files
- add endpoint to retrieve a specific language data
- abstract the language client logic into its own hook
- create tests for get language endpoint
- move tests for language client from useLanguages tests to
its own file
@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: 18efea4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-react-hooks Minor
@youversion/platform-core Minor
@youversion/platform-react-ui Minor
nextjs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

Greptile Overview

Greptile Summary

Added useLanguage hook to fetch a single language by ID from the Platform API, along with a refactored useLanguagesClient hook for better code reuse.

Key Changes

  • Created useLanguage hook following the established pattern from useVersion (fetches single language by ID)
  • Extracted useLanguagesClient hook from useLanguages to eliminate duplicate client creation logic
  • Renamed default_bible_version_id to default_bible_id in the Language schema for better API consistency
  • Refactored useLanguages to use the new useLanguagesClient hook (DRY principle)
  • Added comprehensive test coverage for both new hooks
  • Enhanced vitest coverage configuration to track all source files

Architecture

The implementation properly follows the established monorepo patterns: core package contains the API client and schemas (pure TypeScript), hooks package provides React integration, and workspace dependencies use the workspace:* protocol. The new hooks follow the same composition pattern as existing hooks like useVersion and useBibleClient.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The implementation follows all established patterns, includes comprehensive tests, maintains proper dependency order, and improves code quality through refactoring. The schema change is backward-compatible within the same version bump, and all changes are well-tested.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/src/schemas/language.ts Renamed default_bible_version_id to default_bible_id for consistency
packages/hooks/src/useLanguageClient.ts New client hook for LanguagesClient following established pattern from useBibleClient
packages/hooks/src/useLanguage.ts New hook to fetch a single language by ID, following pattern from useVersion hook
packages/hooks/src/useLanguages.ts Refactored to use useLanguagesClient hook, removing duplicate client creation logic
packages/hooks/vitest.config.ts Added coverage configuration to include all source files and generate comprehensive reports

Sequence Diagram

sequenceDiagram
    participant App as React Component
    participant useLanguage as useLanguage Hook
    participant useLanguagesClient as useLanguagesClient Hook
    participant useApiData as useApiData Hook
    participant LanguagesClient as LanguagesClient
    participant ApiClient as ApiClient
    participant API as Platform API

    App->>useLanguage: Call useLanguage(languageId, options)
    useLanguage->>useLanguagesClient: Get LanguagesClient instance
    useLanguagesClient->>YouVersionContext: useContext()
    YouVersionContext-->>useLanguagesClient: {appKey, apiHost, installationId}
    useLanguagesClient->>ApiClient: new ApiClient(config)
    ApiClient-->>useLanguagesClient: apiClient instance
    useLanguagesClient->>LanguagesClient: new LanguagesClient(apiClient)
    LanguagesClient-->>useLanguagesClient: languagesClient instance
    useLanguagesClient-->>useLanguage: Return memoized client
    
    useLanguage->>useApiData: Call with fetch function and deps
    useApiData->>LanguagesClient: getLanguage(languageId)
    LanguagesClient->>LanguagesClient: Validate languageId (Zod schema)
    LanguagesClient->>ApiClient: get(`/v1/languages/${languageId}`)
    ApiClient->>API: HTTP GET /v1/languages/{languageId}
    API-->>ApiClient: Language data
    ApiClient-->>LanguagesClient: Language object
    LanguagesClient-->>useApiData: Language object
    useApiData-->>useLanguage: {data, loading, error, refetch}
    useLanguage-->>App: {language, loading, error, refetch}

Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

Additional Comments (1)

packages/hooks/src/index.ts
Missing exports for new hooks - add these lines:

export * from './useLanguages';
export * from './useLanguage';
export * from './useLanguageClient';
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/index.ts
Line: 20:20

Comment:
Missing exports for new hooks - add these lines:

```suggestion
export * from './useLanguages';
export * from './useLanguage';
export * from './useLanguageClient';
```

How can I resolve this? If you propose a fix, please make it concise.

@bmanquen bmanquen force-pushed the bm/YPE-1099-add-useLanguage-hook branch from 77ec682 to 75369cb Compare January 27, 2026 04:05
@bmanquen bmanquen force-pushed the bm/YPE-1099-add-useLanguage-hook branch 2 times, most recently from b6ef626 to 18efea4 Compare January 27, 2026 04:14
@bmanquen
Copy link
Collaborator Author

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

2 participants