Skip to content

871-refactor: Refactor youtube api #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 21, 2025
Merged

Conversation

Quiddlee
Copy link
Member

@Quiddlee Quiddlee commented May 5, 2025

What type of PR is this? (select all that apply)

  • πŸ• Feature
  • πŸ› Bug Fix
  • 🚧 Breaking Change
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ“ Documentation Update

Description

Related Tickets & Documents

Screenshots, Recordings

Please replace this line with any relevant images for UI changes.

Added/updated tests?

  • πŸ‘Œ Yes
  • πŸ™…β€β™‚οΈ No, because they aren't needed
  • πŸ™‹β€β™‚οΈ No, because I need help

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

Summary by CodeRabbit

  • New Features

    • Introduced mentor video playlist functionality with a dedicated video player widget fetching public mentor talks.
    • Added a new mentor API service to retrieve mentorship YouTube playlist data.
    • Created a utility to transform and filter mentor videos for display.
  • Improvements

    • Updated environment variable names to a NEXT_PUBLIC_ prefix for better client-side exposure.
    • Refactored video playlist player to accept video items directly, removing internal fetching logic.
    • Enhanced CI workflows and environment declarations to align with new variable naming conventions.
  • Bug Fixes

    • Filtered out private YouTube videos to ensure only public mentor content is shown.
  • Chores

    • Added new runtime dependency for data fetching.
    • Simplified test suites by removing network mocks and focusing on prop-driven tests.

@Quiddlee Quiddlee self-assigned this May 5, 2025
@github-actions github-actions bot changed the title refactor: 871 - move youtube api to separate domain 871-refactor: Refactor youtube api May 5, 2025
@Quiddlee Quiddlee marked this pull request as ready for review May 5, 2025 13:47
@Quiddlee Quiddlee marked this pull request as draft May 5, 2025 13:47
Copy link
Contributor

coderabbitai bot commented May 5, 2025

πŸ“ Walkthrough

Walkthrough

The changes introduce a refactored YouTube API integration using a new MentorApi class and updated environment variable conventions. The Api class now supports multiple services, including YouTube, and the application fetches mentor playlist data via a dedicated store and SWR. The video playlist UI is simplified to accept pre-fetched video data.

Changes

Files/Group Change Summary
.env.example, .github/workflows/*, env.d.ts, src/shared/types/types.ts Renamed and added environment variables to use NEXT_PUBLIC_ prefix; updated type definitions and workflow usage accordingly.
package.json Added "swr" as a new dependency.
src/core/api/app-api.ts, src/shared/api/api.ts, src/shared/types/types.ts Refactored Api class to support YouTube API via new MentorApi; updated instantiation to use two base URLs.
src/entities/mentor/api/mentor-api.ts, src/entities/mentor/constants.ts, src/entities/mentor/types.ts, src/entities/mentor/helpers/transform-mentor-videos.ts Introduced MentorApi, constants, types, and helper for transforming YouTube API data.
src/entities/mentor/model/store.ts, src/entities/mentor/index.ts Added MentorStore with async loading and filtering of mentor YouTube playlist; exported store.
src/shared/constants.ts Added constants for YouTube API results per page and SWR cache key.
src/shared/helpers/filter-youtube-private-videos.ts Added helper to filter out private YouTube videos.
src/shared/helpers/log-request.ts Updated logging utility for improved environment handling and import style.
src/shared/ui/video-playlist-with-player/video-playlist-with-player.tsx Refactored component to accept videoItems prop instead of fetching data internally; simplified logic.
src/shared/ui/video-playlist-with-player/video-playlist-with-player.test.tsx Updated tests to provide video data directly as props, removed fetch mocking and related tests.
src/widgets/mentors-feedback/ui/mentors-feedback.tsx Switched to using a widget-specific mentor talks playlist player component.
src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx Added new component to fetch and display mentor playlist using SWR and the refactored store.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MentorTalksVideoPlaylistWithPlayer
    participant mentorStore
    participant MentorApi
    participant YouTubeAPI

    User->>MentorTalksVideoPlaylistWithPlayer: Render component
    MentorTalksVideoPlaylistWithPlayer->>mentorStore: loadYoutubePlaylist()
    mentorStore->>MentorApi: queryMentorPlaylist()
    MentorApi->>YouTubeAPI: GET /playlistItems
    YouTubeAPI-->>MentorApi: Playlist data
    MentorApi-->>mentorStore: MentorPlaylistResponse
    mentorStore->>mentorStore: filter & transform videos
    mentorStore-->>MentorTalksVideoPlaylistWithPlayer: Video[]
    MentorTalksVideoPlaylistWithPlayer->>User: Render VideoPlaylistWithPlayer with videoItems
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Refactor YouTube API to utilize new API class (#871) βœ…

Suggested reviewers

  • andron13
  • dzmitry-varabei
  • SpaNb4
  • natanchik

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-21T19_49_40_566Z-debug-0.log

Note

⚑️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚑️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boostβ€”your workflow just got faster.


πŸ“œ Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 3e2e3e7 and f827084.

πŸ“’ Files selected for processing (8)
  • .env.example (1 hunks)
  • .github/workflows/main.yml (1 hunks)
  • .github/workflows/preview-create.yml (1 hunks)
  • .github/workflows/production.yml (1 hunks)
  • .github/workflows/visual-testing-on-comment.yml (1 hunks)
  • .github/workflows/visual-testing-on-push.yml (1 hunks)
  • src/core/api/app-api.ts (2 hunks)
  • src/shared/constants.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • .github/workflows/main.yml
  • .github/workflows/preview-create.yml
  • .github/workflows/visual-testing-on-comment.yml
  • .github/workflows/visual-testing-on-push.yml
  • .env.example
  • src/shared/constants.ts
  • .github/workflows/production.yml
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/core/api/app-api.ts (2)
src/entities/mentor/api/mentor-api.ts (1)
  • MentorApi (6-19)
src/shared/api/api-base-class.ts (1)
  • ApiBaseClass (14-127)
πŸ”‡ Additional comments (6)
src/core/api/app-api.ts (6)

2-2: New import added for MentorApi.

The import is correctly structured and aligns with the project's import pattern.


12-12: New mentor API property added.

The property declaration follows the same pattern as existing API properties.


14-17: Constructor signature updated to support YouTube API integration.

The constructor now correctly accepts both a base URI for REST API and a separate YouTube API URI, supporting the dual-API architecture.


18-21: Services object expanded to include YouTube API.

The services object now correctly initializes both REST and YouTube API services using their respective base URIs.


25-25: MentorApi initialized with services.

The mentor API is properly instantiated with the services object, consistent with the initialization pattern of other APIs.


1-27:

βœ… Verification successful

Verify API instantiation is updated throughout the codebase.

The constructor signature change requires updates wherever Api is instantiated. Ensure all usages are updated to provide both URI parameters.


🏁 Script executed:

#!/bin/bash
# Find all locations where Api is instantiated to ensure they're updated
echo "Checking for Api instantiations..."
rg -A 3 "new Api\(" --type ts

Length of output: 317


All Api instantiations updated

I searched for new Api( and found only one occurrence in src/shared/api/api.ts, which already passes both NEXT_PUBLIC_API_BASE_URL and NEXT_PUBLIC_YOUTUBE_API_BASE_URL. No further updates are needed.

✨ Finishing Touches
  • πŸ“ Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (9)
src/shared/helpers/filter-youtube-private-videos.ts (2)

1-5: Add error handling for unexpected data structures

The function properly filters videos based on privacy status, but doesn't handle possible edge cases.

export function filterYoutubePrivateVideos(videos: GoogleApiYouTubePlaylistItemResource[]) {
-  return videos.filter((item) => item.status.privacyStatus === videoPrivacyStatus.public);
+  return videos?.filter((item) => item?.status?.privacyStatus === videoPrivacyStatus.public) || [];
}

1-5: Consider importing GoogleApiYouTubePlaylistItemResource type

The type for the input parameter is used but not imported, which might make the code harder to understand without seeing the full type definition.

src/entities/mentor/helpers/transform-mentors-videos.ts (2)

3-9: Add error handling for unexpected data structures

The transformation function doesn't handle cases where the input array might contain items with missing properties.

export function transformMentorsVideos(videos: GoogleApiYouTubePlaylistItemResource[]): Video[] {
-  return videos.map((item) => ({
-    id: item.snippet.resourceId.videoId,
-    title: item.snippet.title,
-    thumbnail: item.snippet.thumbnails.medium.url,
-  }));
+  return videos?.map((item) => {
+    if (!item?.snippet) return null;
+    
+    return {
+      id: item.snippet?.resourceId?.videoId || '',
+      title: item.snippet?.title || '',
+      thumbnail: item.snippet?.thumbnails?.medium?.url || '',
+    };
+  }).filter(Boolean) as Video[] || [];
}

1-9: Consider importing GoogleApiYouTubePlaylistItemResource type

The type for the input parameter is used but not imported, which would improve code readability and type checking.

src/entities/mentor/model/store.ts (1)

7-11: Consider enhancing error handling.

The error message is generic and doesn't include details about the specific error, which might make debugging harder.

 if (res.isSuccess) {
   return res.result;
 }

-throw new Error('Error while loading mentor playlist.');
+throw new Error(`Error while loading mentor playlist: ${res.error || 'Unknown error'}`);
.env.example (1)

2-3: Specific URL in example file may not be ideal.

Using a specific URL (https://cdn.rs.school) in the example file could lead developers to inadvertently use the production URL in development environments.

-NEXT_PUBLIC_API_BASE_URL=https://cdn.rs.school
+NEXT_PUBLIC_API_BASE_URL=https://example.api.url
src/core/api/app-api.ts (1)

12-15: Constructor parameters could be optimized.

The parameters are marked as private readonly but are only used within the constructor.

 constructor(
-  private readonly baseURI: string,
-  private readonly youtubeBaseURI: string,
+  baseURI: string,
+  youtubeBaseURI: string,
 ) {
src/entities/mentor/api/mentor-api.ts (1)

6-19: Good API abstraction with proper dependency injection

The MentorApi class nicely encapsulates YouTube API interactions with:

  • Clean dependency injection through constructor
  • Well-defined method for playlist queries
  • Appropriate use of environment variables for API key
  • Proper typing with the MentorPlaylistResponse type

Consider adding error handling or request options (like timeout) to make the API calls more robust.

src/shared/ui/video-playlist-with-player/video-playlist-with-player.test.tsx (1)

23-64: Video selection test needs explanation for multiple VideoPlayer calls

The test expects VideoPlayer to be called 3 times, but it's not immediately clear why. Consider adding a comment explaining the sequence of calls:

  1. Initial render
  2. Re-render after state updates
  3. After clicking a different video
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between f0c0e63 and ba5e4d4.

β›” Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
πŸ“’ Files selected for processing (25)
  • .env.example (1 hunks)
  • .github/workflows/main.yml (1 hunks)
  • .github/workflows/preview-create.yml (1 hunks)
  • .github/workflows/production.yml (1 hunks)
  • .github/workflows/visual-testing-on-comment.yml (1 hunks)
  • .github/workflows/visual-testing-on-push.yml (1 hunks)
  • env.d.ts (1 hunks)
  • package.json (1 hunks)
  • src/core/api/app-api.ts (2 hunks)
  • src/entities/mentor/api/mentor-api.ts (1 hunks)
  • src/entities/mentor/constants.ts (1 hunks)
  • src/entities/mentor/helpers/transform-mentors-videos.ts (1 hunks)
  • src/entities/mentor/index.ts (1 hunks)
  • src/entities/mentor/model/store.ts (1 hunks)
  • src/entities/mentor/types.ts (1 hunks)
  • src/shared/api/api-base-class.ts (2 hunks)
  • src/shared/api/api.ts (1 hunks)
  • src/shared/constants.ts (2 hunks)
  • src/shared/helpers/filter-youtube-private-videos.ts (1 hunks)
  • src/shared/helpers/log-request.ts (2 hunks)
  • src/shared/types/types.ts (1 hunks)
  • src/shared/ui/video-playlist-with-player/video-playlist-with-player.test.tsx (4 hunks)
  • src/shared/ui/video-playlist-with-player/video-playlist-with-player.tsx (3 hunks)
  • src/widgets/mentors-feedback/ui/mentors-feedback.tsx (2 hunks)
  • src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
src/shared/helpers/filter-youtube-private-videos.ts (1)
src/shared/ui/video-playlist-with-player/constants.ts (1)
  • videoPrivacyStatus (1-4)
src/widgets/mentors-feedback/ui/mentors-feedback.tsx (1)
src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx (1)
  • MentorTalksVideoPlaylistWithPlayer (10-29)
src/shared/api/api.ts (1)
src/core/api/app-api.ts (1)
  • Api (6-24)
src/entities/mentor/helpers/transform-mentors-videos.ts (2)
src/entities/mentor/index.ts (1)
  • transformMentorsVideos (4-4)
src/shared/types/types.ts (1)
  • Video (12-16)
src/entities/mentor/model/store.ts (2)
src/shared/api/api.ts (1)
  • api (3-6)
src/entities/mentor/index.ts (1)
  • mentorStore (3-3)
src/entities/mentor/api/mentor-api.ts (4)
src/shared/types/types.ts (1)
  • ApiServices (18-21)
src/entities/mentor/types.ts (1)
  • MentorPlaylistResponse (10-12)
src/shared/constants.ts (1)
  • YOUTUBE_API_MAX_RESULTS_PER_PAGE (10-10)
src/entities/mentor/constants.ts (1)
  • MENTORSHIP_YOUTUBE_PLAYLIST_ID (1-1)
src/shared/ui/video-playlist-with-player/video-playlist-with-player.tsx (1)
src/shared/types/types.ts (1)
  • Video (12-16)
πŸ”‡ Additional comments (30)
src/shared/helpers/log-request.ts (2)

1-1: Use named import for inspect.
Importing inspect directly from 'util' simplifies the code and enables tree-shaking in modern bundlers.


60-63: Direct invocation of inspect.
Calling inspect(logObject, { depth: null, colors: process.env.NODE_ENV !== 'production' }) is concise and maintains clear logging behavior.

package.json (1)

49-50: Good addition of SWR for data fetching

Adding SWR as a dependency is appropriate for implementing client-side data fetching with caching in the mentor playlist component.

src/entities/mentor/constants.ts (1)

1-1: Good use of constants for YouTube playlist ID

Extracting the YouTube playlist ID into a named constant improves maintainability by centralizing this configuration value.

src/shared/types/types.ts (1)

20-20: Good API service separation

Adding a dedicated YouTube API service property improves code organization by separating different API clients.

src/entities/mentor/index.ts (1)

3-4: New exports for refactored YouTube API

These exports expose the mentor store for state management and the transformation utility needed by the new mentor video playlist implementation.

.github/workflows/production.yml (1)

24-26:

βœ… Verification successful

Environment variables updated to follow Next.js conventions

The environment variables now follow the NEXT_PUBLIC_ prefix convention for client-side exposure.

Ensure that other workflow files and environment configurations have been updated consistently to use these new variable names.


🏁 Script executed:

#!/bin/bash
# Verify other workflow files are using the same env var naming convention
grep -r "API_BASE_URL\|YOUTUBE_API_BASE_URL\|YOUTUBE_API_KEY" .github/workflows/ --include="*.yml" | grep -v "NEXT_PUBLIC_"

Length of output: 123


🏁 Script executed:

#!/bin/bash
# Verify that any .env* files have been updated to use NEXT_PUBLIC_ prefixes
grep -R "API_BASE_URL\|YOUTUBE_API_BASE_URL\|YOUTUBE_API_KEY" -n --include="*.env*" . | grep -v "NEXT_PUBLIC_"

Length of output: 110


No stale environment variable references detected
Workflows and env files were scannedβ€”no occurrences of the old API_BASE_URL, YOUTUBE_API_BASE_URL, or YOUTUBE_API_KEY without the NEXT_PUBLIC_ prefix remain.

src/shared/api/api-base-class.ts (2)

62-62: Default logging enabled

The shouldLog parameter now defaults to true, ensuring API requests are logged by default unless explicitly disabled.


125-125: URL construction simplified

String concatenation is now used instead of the URL constructor to combine base URL and query string.

.github/workflows/main.yml (1)

12-14: Environment variables updated for Next.js client-side access

Environment variables have been renamed with the NEXT_PUBLIC_ prefix to align with Next.js conventions for client-side accessibility. Additional YouTube API variables have been added to support the new functionality.

src/shared/api/api.ts (1)

3-6: API initialization updated to support multiple services

The Api class is now initialized with two base URLs to support both the main API and YouTube API services, aligning with the updated constructor in src/core/api/app-api.ts.

.github/workflows/preview-create.yml (1)

19-21: Consistent environment variable updates

Environment variables have been updated with the NEXT_PUBLIC_ prefix and additional YouTube API variables to maintain consistency across all workflows.

.github/workflows/visual-testing-on-push.yml (1)

10-12: Environment variables correctly updated with NEXT_PUBLIC_ prefix

The environment variables have been properly updated with the Next.js public environment variable convention (NEXT_PUBLIC_ prefix), which makes them accessible on the client side.

.github/workflows/visual-testing-on-comment.yml (1)

11-13: Environment variables correctly updated with NEXT_PUBLIC_ prefix

The environment variables have been properly updated with the Next.js public environment variable convention (NEXT_PUBLIC_ prefix), matching the changes made in other workflow files.

src/shared/constants.ts (2)

10-10: Good addition of YouTube API pagination constant

Adding a constant for the maximum results per page is a good practice for API pagination settings.


108-108: Appropriate SWR cache key constant added

The SWR cache key constant helps maintain consistency in data fetching cache identifiers across components.

src/widgets/mentors-feedback/ui/mentors-feedback.tsx (2)

6-8: Clean import of specialized component

Import of the specialized playlist component aligns with the refactoring approach of separating concerns.


53-53: Improved component usage with encapsulated playlist fetching

The change simplifies the component usage by encapsulating all YouTube playlist fetching and processing logic within the specialized component, improving readability and maintainability.

src/entities/mentor/model/store.ts (1)

1-15: Simple and focused store implementation.

The store provides a clean abstraction for loading YouTube playlist data with proper error handling.

env.d.ts (1)

4-6: Proper environment variable declarations for Next.js client-side usage.

The NEXT_PUBLIC_ prefix follows Next.js conventions for client-exposed variables.

.env.example (1)

5-7: Well-structured environment variables for YouTube API.

The section is clearly marked and includes the standard YouTube API v3 endpoint.

src/core/api/app-api.ts (3)

16-19: Clean separation of API services.

Creating separate service instances for REST and YouTube APIs promotes better separation of concerns.


10-10: Mentor API integration looks good.

The MentorApi is properly integrated following the same pattern as the existing TrainerApi.

Also applies to: 22-22


1-24:

βœ… Verification successful

Verify YouTube API key handling.

It's not clear how the YouTube API key is passed to the ApiBaseClass.


🏁 Script executed:

#!/bin/bash
# Check how the API key is handled in ApiBaseClass
echo "ApiBaseClass implementation:"
grep -A 20 "class ApiBaseClass" $(find src -name "api-base-class.ts")

echo "YouTube API key usage:"
grep -r "NEXT_PUBLIC_YOUTUBE_API_KEY" src --include="*.ts" --include="*.tsx"

Length of output: 967


YouTube API key is handled in MentorApi

The ApiBaseClass doesn’t need the key in its constructorβ€”mentor-api.ts adds it as a query parameter (key: process.env.NEXT_PUBLIC_YOUTUBE_API_KEY). No changes required in app-api.ts.

src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx (1)

1-29: Well-architected component with clean separation of concerns

This new component follows best practices by:

  • Using SWR for data fetching with appropriate cache key
  • Properly handling loading and error states with testable UI elements
  • Filtering private videos and transforming data before passing to the presentation component
  • Keeping the component focused on its primary responsibility

The implementation effectively encapsulates the fetching and processing logic that was previously mixed with presentation concerns.

src/shared/ui/video-playlist-with-player/video-playlist-with-player.test.tsx (2)

15-21: Simplified test correctly matches component changes

The test now properly checks the component with directly provided props instead of mocking fetch calls, which aligns with the refactored component's design.


66-94: Improved test for playlist height with more direct DOM manipulation

The test now directly manipulates the player element's offsetHeight property rather than using a global prototype override, which is a safer approach.

src/shared/ui/video-playlist-with-player/video-playlist-with-player.tsx (3)

14-16: Props interface simplified for better component responsibility

Removing the API fetching props in favor of direct video items improves component responsibility separation.


22-36: Effective use of callback ref for cleanup

Using a callback ref to handle both initial measurement and resize event cleanup is an elegant solution.


47-57: Improved JSX structure with better semantics

The refactored JSX structure with explicit data-testid attributes improves testability.

Copy link

github-actions bot commented May 7, 2025

Lighthouse Report:

  • Performance: 70 / 100
  • Accessibility: 96 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

Copy link

github-actions bot commented May 8, 2025

Lighthouse Report:

  • Performance: 78 / 100
  • Accessibility: 96 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

@Quiddlee Quiddlee requested a review from SpaNb4 May 8, 2025 09:32
@SpaNb4
Copy link
Collaborator

SpaNb4 commented May 8, 2025

@Quiddlee We should also update the env vars in the repo settings so CI/CD works correctly, right?

upd: Never mind, I see you're mapping them to different names in the workflow files

@Quiddlee
Copy link
Member Author

Quiddlee commented May 8, 2025

@Quiddlee We should also update the env vars in the repo settings so CI/CD works correctly, right?

I have updated the env names only in our codebase, the ci/cd names should remain the same
Screenshot 2025-05-08 at 1 18 48β€―PM

@Quiddlee Quiddlee mentioned this pull request May 8, 2025
1 task
@Quiddlee Quiddlee marked this pull request as ready for review May 12, 2025 19:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/shared/helpers/filter-youtube-private-videos.ts (1)

1-6: Function implementation looks good, but consider adding type safety improvements.

The function correctly filters out private videos from the YouTube playlist response. For better maintainability, consider:

  1. Adding an explicit return type
  2. Adding null/undefined checks for defensive programming
- export function filterYoutubePrivateVideos(videos: MentorPlaylistResponse) {
-   return videos.items.filter((item) => item.status.privacyStatus === videoPrivacyStatus.public);
+ export function filterYoutubePrivateVideos(videos: MentorPlaylistResponse): GoogleApiYouTubePlaylistItemResource[] {
+   if (!videos?.items?.length) return [];
+   return videos.items.filter((item) => item.status?.privacyStatus === videoPrivacyStatus.public);
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ba5e4d4 and 3e2e3e7.

πŸ“’ Files selected for processing (7)
  • env.d.ts (1 hunks)
  • src/entities/mentor/helpers/transform-mentor-videos.ts (1 hunks)
  • src/entities/mentor/index.ts (1 hunks)
  • src/entities/mentor/model/store.ts (1 hunks)
  • src/shared/helpers/filter-youtube-private-videos.ts (1 hunks)
  • src/shared/helpers/log-request.ts (3 hunks)
  • src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx (1 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • src/entities/mentor/helpers/transform-mentor-videos.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/entities/mentor/index.ts
  • src/shared/helpers/log-request.ts
  • src/widgets/mentors-feedback/ui/mentors-playlist/mentor-talks-video-playlist-with-player.tsx
  • src/entities/mentor/model/store.ts
  • env.d.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/shared/helpers/filter-youtube-private-videos.ts (2)
src/entities/mentor/types.ts (1)
  • MentorPlaylistResponse (10-12)
src/shared/ui/video-playlist-with-player/constants.ts (1)
  • videoPrivacyStatus (1-4)

Copy link

Lighthouse Report:

  • Performance: 78 / 100
  • Accessibility: 96 / 100
  • Best Practices: 100 / 100
  • SEO: 100 / 100

View detailed report

@Quiddlee Quiddlee merged commit 8734dfa into main May 21, 2025
3 checks passed
@Quiddlee Quiddlee deleted the refactor/871-Refactor-youtube-api branch May 21, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor youtube api
4 participants