You are an expert React developer tasked with modifying the UI of my nextjs site based on my query and files below. Carefully think through this task below and generate high quality code to accomplish the task by modifying the site's files below:Task:"How can you modify my nextjs site so that the file list is displayed on the left side panel (which is expanded/reduced from the arrow button on the left side of the screen)?
Carefully analyze my files to determine how to modify them in order to have the 'filelist' features on the left panel rather than the top header of the page which is where they currently are"
here is my app's files structure and content labeled with xml tags:
<directory_tree>
cool-code/
├── app/
│ ├── api/
│ │ └── github/
│ │ │ └── route.ts
│ ├── globals.css
│ ├── layout.tsx
│ ├── page.module.css
│ └── page.tsx
├── components/
│ ├── FileContent.module.css
│ ├── FileContent.tsx
│ ├── FileList.module.css
│ ├── FileList.tsx
│ ├── RepoViewer.module.css
│ ├── RepoViewer.tsx
│ └── icons.ts
├── cool-code_prompt.txt
├── next.config.js
├── package.json
└── tsconfig.json
</directory_tree>
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
api: '/api/chat',
onFinish: () => {
// Any additional logic to run when the chat response is complete
},
});
const fileContextMessage = Object.entries(selectedFileContents)
.map(([path, content]) => `File: ${path}\n\nContent:\n${content}\n\n`)
.join('---\n\n');
const fullPrompt = `Here are the contents of the selected files:\n\n${fileContextMessage}\nUser query: ${input}\n\nPlease provide an answer based on the file contents and the user's query.`;
handleSubmit(e, {
options: {
body: { prompt: fullPrompt },
},
});
To modify your Next.js site so that the file list is displayed on a collapsible left side panel (which can be expanded or reduced using an arrow button on the left side of the screen), you'll need to adjust both your RepoViewer.tsx component and your associated CSS in RepoViewer.module.css. Here's how you can achieve this:
1. Update RepoViewer.tsx
We'll restructure the RepoViewer component to place the file list inside a left side panel and ensure it can be toggled using a button.
Changes to be made:
Ensure the file list and repository URL input form are inside the side panel (fileListContainer).
Add logic to handle the toggling of the side panel (isFileListOpen state).
Adjust the layout to shift the main content when the side panel is open.
Updated RepoViewer.tsx:
// components/RepoViewer.tsx
'use client';
import React, { useState, useRef, useEffect } from 'react';
import styles from './RepoViewer.module.css';
import FileList from './FileList';
import FileContent from './FileContent';
import { useChat } from 'ai/react';
import ReactMarkdown from 'react-markdown';
import { FaChevronLeft, FaChevronRight } from 'react-icons/fa'; // Import toggle icons
// ... [rest of your imports and interface definitions]
const RepoViewer: React.FC = () => {
// ... [your existing state and hooks]
// State to control the visibility of the side panel
const [isFileListOpen, setIsFileListOpen] = useState(false);
const toggleFileList = () => {
setIsFileListOpen(!isFileListOpen);
};
// ... [rest of your useEffect hooks and functions]
return (
<main className={styles.container}>
{/* Toggle Button to expand/collapse the side panel */}
<button
onClick={toggleFileList}
className={`${styles.toggleButton} ${isFileListOpen ? styles.open : ''}`}
aria-label={isFileListOpen ? 'Collapse file list' : 'Expand file list'}
>
{isFileListOpen ? <FaChevronLeft /> : <FaChevronRight />}
</button>
<div className={styles.content}>
{/* Side Panel */}
<div className={`${styles.fileListContainer} ${isFileListOpen ? styles.open : styles.collapsed}`}>
{files.length === 0 ? (
// Repository URL Input Form
<form onSubmit={handleRepoSubmit} className={styles.inputContainer}>
<input
type="text"
value={repoUrl}
onChange={(e) => setRepoUrl(e.target.value)}
placeholder="Enter GitHub repository URL (e.g., https://github.com/owner/repo)"
className={styles.inputBox}
/>
<button type="submit" className={styles.submitButton} disabled={loading}>
{loading ? 'Loading...' : 'Load Repo'}
</button>
</form>
) : (
// File List Component
<FileList
files={files}
selectedFiles={selectedFiles}
onFileSelect={handleFileSelect}
/>
)}
</div>
{/* Main Content Area */}
<div className={styles.fileContentWrapper}>
{/* Display selected file content or chat conversation */}
{selectedFile ? (
<FileContent file={selectedFile} />
) : (
<div className={`${styles.conversationContainer} ${isPromptMinimized ? styles.fullHeight : ''}`}>
{messages.map((m, index) => (
<div key={index} className={`${styles.messageBubble} ${styles[m.role]}`}>
<ReactMarkdown>{m.content}</ReactMarkdown>
</div>
))}
<div ref={messagesEndRef} />
</div>
)}
</div>
</div>
{/* Prompt Input Area */}
<div className={`${styles.promptContainer} ${isPromptMinimized ? styles.minimized : ''}`}>
<button
onClick={togglePromptMinimize}
className={styles.minimizeButton}
aria-label={isPromptMinimized ? 'Maximize prompt' : 'Minimize prompt'}
>
{isPromptMinimized ? '🔼' : '🔽'}
</button>
{!isPromptMinimized && (
<form onSubmit={handleChatSubmit} className={styles.promptForm}>
<textarea
value={input}
onChange={handleInputChange}
onInput={(e) => {
const target = e.target as HTMLTextAreaElement;
target.style.height = 'auto';
target.style.height = `${target.scrollHeight}px`;
}}
placeholder="Ask about the selected files..."
className={styles.promptInput}
disabled={isLoading}
/>
<div className={styles.buttonContainer}>
<button type="submit" className={styles.promptButton} disabled={isLoading}>
{isLoading ? 'Sending...' : 'Send'}
</button>
</div>
</form>
)}
</div>
</main>
);
};
export default RepoViewer;
Explanation:
Toggle Button: We added a button to toggle the side panel's visibility. It updates the isFileListOpen state and changes its icon based on the panel's state.
Side Panel (fileListContainer): The panel contains either the repository URL input form (if no files are loaded) or the FileList component. It uses CSS classes to control its open or collapsed state.
Content Layout: We adjusted the content div to no longer shift based on the side panel's state. Instead, we'll handle the layout purely with CSS flex properties.
2. Update RepoViewer.module.css
We'll modify the CSS to style the side panel and ensure the main content adjusts appropriately when the panel is toggled.
Updated RepoViewer.module.css:
/* components/RepoViewer.module.css */
/* Container for the entire application */
.container {
display: flex;
flex-direction: column;
height: 100vh; /* Ensure the container takes full viewport height */
overflow: hidden;
}
/* Content area that contains the side panel and main content */
.content {
display: flex;
flex: 1;
overflow: hidden;
}
/* Side Panel Styles */
.fileListContainer {
width: 0; /* Start collapsed */
transition: width 0.3s ease;
overflow-y: auto;
background-color: #1e1e1e; /* Dark background */
color: #ffffff;
flex-shrink: 0; /* Prevent shrinking when resizing */
}
/* Expanded Side Panel */
.fileListContainer.open {
width: 250px; /* Expanded width */
}
/* Collapsed Side Panel */
.fileListContainer.collapsed {
width: 0; /* Collapsed width */
}
/* Toggle Button Styles */
.toggleButton {
position: absolute;
top: 50%;
left: 0;
transform: translate(-50%, -50%); /* Position to the left of the side panel */
background-color: #1e1e1e;
border: 1px solid #444;
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: #fff;
z-index: 1000;
transition: left 0.3s ease;
}
/* Adjust position when side panel is open */
.fileListContainer.open + .toggleButton {
left: 250px; /* Match the side panel's expanded width */
}
/* Main Content Area */
.fileContentWrapper {
flex: 1;
padding: 1rem;
overflow-y: auto;
background-color: #1e1e1e;
color: #ffffff;
}
/* Conversation Container */
.conversationContainer {
display: flex;
flex-direction: column;
gap: 10px;
height: 100%;
overflow-y: auto;
word-wrap: break-word;
overflow-wrap: break-word;
}
/* Message Bubbles */
.messageBubble {
padding: 10px;
border-radius: 8px;
max-width: 80%;
word-wrap: break-word;
overflow-wrap: break-word;
}
.user {
align-self: flex-end;
background-color: #1e3a8a;
}
.assistant {
align-self: flex-start;
background-color: #2c2c2c;
}
/* Prompt Container */
.promptContainer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #2c2c2c;
padding: 10px;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}
/* ... [rest of your styles] */
/* Adjust the height of conversation container when prompt is minimized */
.conversationContainer.fullHeight {
height: calc(100vh - 100px); /* Adjust based on your header/footer height */
}
Explanation:
Container Layout:
Set height: 100vh for .container to make it take the full viewport height.
Use flex properties to manage the layout of .content, .fileListContainer, and .fileContentWrapper.
Side Panel (.fileListContainer):
Initially set width: 0 for the collapsed state.
Define an .open class to set width: 250px when the panel is expanded.
Use flex-shrink: 0 to prevent the panel from shrinking when the window is resized.
Toggle Button (.toggleButton):
Position the button absolutely relative to the container.
Adjust the left position based on whether the side panel is open or collapsed.
Main Content (.fileContentWrapper):
Use flex: 1 to allow it to take the remaining space.
Ensure it scrolls vertically if content overflows.
3. Adjust Other Components if Necessary
Ensure that the FileList and FileContent components display correctly within the side panel and main content area, respectively. No changes should be needed for these components if they use responsive styles.
4. Test the Implementation
Run your Next.js application.
Enter a GitHub repository URL in the side panel input form.
Upon loading the repository, the side panel should display the file list.
Use the toggle button on the left to expand or collapse the side panel.
Ensure that the main content area adjusts accordingly.
Select files and interact with the chat prompt to verify functionality.
Additional Notes
Responsive Design: Ensure that your layout is responsive on different screen sizes. You might need to add media queries to adjust the side panel width or layout on smaller screens.
Accessibility: Consider adding aria-labels and adjusting keyboard navigation for better accessibility.
State Management: If the isFileListOpen state needs to be maintained across different components or pages, consider using a context or global state management solution.
By applying these changes, you'll move the file list and repository URL input form into a collapsible left side panel controlled by a toggle button. This layout enhancement should improve the user experience by providing a more intuitive navigation structure similar to many code editors and IDEs.