Sign In Sign Up

Refactor video detail component architecture

Handed off from T-edd9fe0c-1f84-44f7-94de-b0f9312337ea

Instructions: "Handoff from parent thread"

Continuing work from thread edd9fe0c. When you lack specific information you can use read_thread to get it. @components/video-detail.tsx @components/video-content-tabs.tsx @components/ui/sidebar/sidebar.tsx @components/providers/sidebar-provider.tsx @components/playlist-sidebar.tsx @components/ui/ai-assistant/index.tsx I recently refactored the application into a "Fixed App Shell" layout with a left sidebar for playlists and a right sidebar for chat/chapters. For the right sidebar: - I implemented a resizable width (default 380px, max 640px) with a drag handle. - I removed CSS transitions from the sidebar and main content to ensure high-performance (60fps) resizing without lag. - The resize handle supports double-clicking to toggle between default and max width. - The component is currently named VideoContentTabs (in components/video-content-tabs.tsx), which I identified as a naming candidate for improvement. For the chat interface (inside the right sidebar): - I updated the typography so H1-H6 headers use the same font size as body text but are bolded. - I improved the input area to be an auto-growing textarea. My current goal is to finalize the desktop version by refactoring components/video-detail.tsx and related components for maximum cleanliness and readability. - I specifically want to rename/refactor the right sidebar component (VideoContentTabs) to something that makes more sense. - The code should be "clean, modern, best practices" and highly readable (Dave Thomas standard). - I want a plan before execution and requested a "second pair of eyeballs" (Oracle) on the architecture. We did a lot of work on the two sidebars. We have now a left optional sidebar for playlists, and we have a right sidebar. Sidebar for the chat and the chapters. Now before we finalize The desktop version and move on to the mobile version. I need you to go through @components/video-detail.tsx look at everything deeply, mainly the cleanliness of the code, the naming of modules. I saw for example that the right side sidebar naming is something with content tabs or whatever. It all needs to make sense. It all needs to be easily readable and digestible. Readability of the code is the most important thing. You need to keep it clean, modern, best practices. The code needs to sing, and I would like that people like Dave Thomas, even though he's not a TypeScript guy, would love and approve this code and architecture. Give me a plan of all the things first and also pull in the oracle for a second pair of eyeballs, please.

I'm focused on the refactoring of VideoDetail and associated components. Currently, I'm concentrating on VideoContentTabs, aiming for a name and structure that better aligns with modern coding practices. The emphasis is on readability and adherence to best practices. I'm exploring various naming options to capture its function accurately.

Defining Refactor Scope

I'm now zeroing in on defining the precise scope of the refactor. My initial assessment of VideoDetail and related components is complete, including a look at PlaylistSidebar and other dependencies. The next step is to create a detailed plan, using the oracle tool for guidance on best practices. I'm prioritizing the VideoContentTabs renaming and restructuring while maintaining existing functionality.

Consulting the Oracle

I've taken a comprehensive look at the component structure, specifically VideoDetail, VideoContentTabs, and related files. My initial assessment confirms the need for refactoring, aligning with the user's goals. I will now consult the oracle tool to gain insights on naming conventions, separation of concerns, and overall architecture optimization for improved readability and code cleanliness before formulating a detailed plan.

I've begun to synthesize the Oracle's blueprint. My focus now is solidifying the discrete actions. I'm visualizing the renaming of the VideoContentTabs as the initial move, instantly setting the stage for the next phase. Next, I'm analyzing the 3-column layout and the necessity of extracting FixedSidebarLayout.

Analyzing the Action Steps

My strategy is taking shape. I'm focusing on the individual action items outlined in the Oracle's plan. I've broken down each step, like renaming components and creating new ones. The user's directive to present the plan first is clear. I'm leveraging the todo_write approach to track these actions, ensuring a structured and efficient execution, particularly, the creation of components/video-companion-sidebar.tsx.

Synthesizing the Steps

I've distilled the Oracle's plan. I'm focusing on creating the todo_write plan, which is crucial for tracking progress. I'm prioritizing the renaming and creation steps, specifically, the refactoring of VideoContentTabs and the extraction of FixedSidebarLayout. I'm also considering the best placement for VideoMainContent. Now, I'm ready to present the plan, and await the user's approval.

Updated TODOs

The Oracle and I have reviewed the code. The architecture is sound (Fixed App Shell), but the VideoDetail component has too many responsibilities (layout, logic, content rendering), and the naming for the right sidebar (VideoContentTabs) is implementation-specific rather than semantic.

Here is the refactoring plan to make the code "sing":

1. Semantic Renaming

VideoContentTabsVideoCompanionSidebar

  • Why: It's not just "tabs"—it's the dedicated companion panel for the video (Chat + Chapters). This matches the naming pattern of PlaylistSidebar.
  • Action: Rename the file and component. Clean up unused "legacy" props (activeTab, onTabChange, etc.) that clutter the interface.

2. Layout Extraction

Create FixedSidebarLayout

  • Why: VideoDetail is currently manually calculating paddings and positioning sidebars. This "glue" code obscures the actual business logic.
  • Action: Extract a reusable shell component that accepts leftSidebar, rightSidebar, and children.
    <FixedSidebarLayout
      leftSidebar={<PlaylistSidebar ... />}
      rightSidebar={<VideoCompanionSidebar ... />}
    >
      {/* Content */}
    </FixedSidebarLayout>
    

3. Logic Extraction (Hooks)

Create usePlaylistNavigation & useScrollOutOfView

  • Why:
    • Playlist index math (nextVideo, previousVideo, etc.) takes up ~20 lines of noise in the main component.
    • The scroll listener logic (isOutOfView) is verbose and slightly buggy (it never sets true).
  • Action: Move this logic into clean, testable hooks.

4. Component Decomposition

Create VideoMainContent

  • Why: The content below the player (metadata, description tab, transcript tab, CTA) creates a massive render block.
  • Action: Extract this into a dumb UI component. VideoDetail effectively becomes a "Controller" that just wires up data to the Layout, Player, and MainContent.

Execution Order

  1. Rename the right sidebar and clean it up.
  2. Create the hooks.
  3. Create the FixedSidebarLayout.
  4. Extract VideoMainContent.
  5. Rewire VideoDetail to be a clean orchestrator.

Shall I proceed with this plan?

yea looks dope, fire away! 🚀

I'm starting the refactoring, as planned. The first step involves renaming VideoContentTabs to VideoCompanionSidebar and cleaning up its props. I'll read the code now and then move on to implementing the usePlaylistNavigation hooks.

Executing the Renames

I'm deep in the rename-and-cleanup phase. Successfully renamed VideoContentTabs to VideoCompanionSidebar and am now carefully inspecting its props for streamlining. Then, on to the usePlaylistNavigation and useScrollOutOfView hooks.

I've got the video content tabs in place and am moving on to the components/video-companion-sidebar.tsx file. Renaming the component to VideoCompanionSidebar is the first step. Next, I'll clean up the props and rename the interface.

Constructing the Sidebar

I've initiated the creation of components/video-companion-sidebar.tsx. The component has been renamed, and I'm currently refining the props and the interface names. I've removed some props, like activeTab, and renamed SidebarTab to CompanionTab internally. My next step is checking if VideoTabId is imported in video-detail.tsx before finalizing its placement and usage. I will also be updating the storage key.

VideoTabId 3 matches

I've pinpointed VideoTabId's limited scope – it's exclusively used within video-content-tabs.tsx. This suggests a straightforward internal refactor is viable. My next step involves initializing components/video-companion-sidebar.tsx.

I've got the VideoCompanionSidebar component implemented, and I've decided to postpone work on VideoContentTabs until I make some necessary updates to VideoDetail. Currently, I'm focusing on the hooks, specifically starting with usePlaylistNavigation in hooks/use-playlist-navigation.ts.

Defining Hook Implementation Path

I'm making progress. I've laid the groundwork and am creating the usePlaylistNavigation and useScrollOutOfView hooks. My focus is now on hooks/use-playlist-navigation.ts, and I'm currently verifying the existence of the hooks directory to ensure everything's set up correctly before diving into the implementation details of the hook itself.