-
Notifications
You must be signed in to change notification settings - Fork 1
feat(frontend): implement collaboration service #14
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect } from "react"; | ||
| import { useRouter, useParams } from "next/navigation"; | ||
| import dynamic from "next/dynamic"; | ||
| import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"; | ||
| import Header from "@/components/ui/header"; | ||
| import QuestionPanel from "@/components/practice/question-panel"; | ||
| import CommunicationPanel from "@/components/practice/communication-panel"; | ||
| import CodeOutputPanel from "@/components/practice/code-output-panel"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Spinner } from "@/components/ui/spinner"; | ||
| import { useCollaborationState, useCollaborationActions } from "@/stores/collaboration-store"; | ||
|
|
||
| const CodeEditorPanel = dynamic(() => import("@/components/practice/code-editor-panel"), { | ||
| ssr: false, | ||
| loading: () => <div className="h-full flex items-center justify-center">Loading editor...</div>, | ||
| }); | ||
|
|
||
| export default function PracticePage() { | ||
| const router = useRouter(); | ||
| const params = useParams(); | ||
| const roomId = params?.id as string; | ||
|
|
||
| const { roomDetails, isLoading, error } = useCollaborationState(); | ||
| const { fetchRoomDetails, reset } = useCollaborationActions(); | ||
|
|
||
| // Fetch room details on mount | ||
| useEffect(() => { | ||
| if (roomId) { | ||
| fetchRoomDetails(roomId).catch((err) => { | ||
| console.error("Failed to fetch room details:", err); | ||
| }); | ||
| } | ||
|
|
||
| // Cleanup on unmount | ||
| return () => { | ||
| reset(); | ||
| }; | ||
| }, [fetchRoomDetails, reset, roomId]); | ||
|
|
||
| // Handle leave session | ||
| const handleLeaveSession = () => { | ||
| // Simply redirect to home page | ||
| router.push("/"); | ||
| }; | ||
|
|
||
| // Loading state | ||
| if (isLoading) { | ||
| return ( | ||
| <div className="h-screen w-full flex items-center justify-center"> | ||
| <div className="flex flex-col items-center gap-4"> | ||
| <Spinner /> | ||
| <p className="text-muted-foreground">Loading collaboration room...</p> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Error state | ||
| if (error || !roomDetails) { | ||
| return ( | ||
| <div className="h-screen w-full flex items-center justify-center"> | ||
| <div className="flex flex-col items-center gap-4 text-center"> | ||
| <p className="text-destructive font-semibold">Failed to load room</p> | ||
| <p className="text-muted-foreground">{error || "Room not found"}</p> | ||
| <Button onClick={() => router.push("/")}>Go Back Home</Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Read-only mode (room is closed) | ||
| const isReadOnly = !roomDetails.isActive; | ||
|
|
||
| return ( | ||
| <div className="h-screen w-full flex flex-col"> | ||
| <Header> | ||
| <div className="flex items-center gap-4"> | ||
| <Button variant={"destructive"} onClick={handleLeaveSession}> | ||
| Leave Room | ||
| </Button> | ||
| </div> | ||
| </Header> | ||
|
|
||
| <div className="flex-1"> | ||
| {isReadOnly ? ( | ||
| // Read-only layout: Only question and read-only code editor | ||
| <ResizablePanelGroup direction="horizontal" className="h-full w-full"> | ||
| {/* Left Panel */} | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <QuestionPanel /> | ||
| </div> | ||
| </ResizablePanel> | ||
|
|
||
| <ResizableHandle className="bg-gray-400 hover:bg-gray-600 w-1 cursor-col-resize" /> | ||
|
|
||
| {/* Right Panel */} | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <CodeEditorPanel readOnly={true} /> | ||
| </div> | ||
| </ResizablePanel> | ||
| </ResizablePanelGroup> | ||
| ) : ( | ||
| // Full layout with all panels | ||
| <ResizablePanelGroup direction="horizontal" className="h-full w-full"> | ||
| {/* Left Panel */} | ||
| <ResizablePanel> | ||
| <ResizablePanelGroup direction="vertical"> | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <QuestionPanel /> | ||
| </div> | ||
| </ResizablePanel> | ||
| <ResizableHandle className="bg-gray-400 hover:bg-gray-600 w-1 cursor-col-resize" /> | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <CommunicationPanel /> | ||
| </div> | ||
| </ResizablePanel> | ||
| </ResizablePanelGroup> | ||
| </ResizablePanel> | ||
|
|
||
| <ResizableHandle className="bg-gray-400 hover:bg-gray-600 w-1 cursor-col-resize" /> | ||
|
|
||
| {/* Right Panel */} | ||
| <ResizablePanel> | ||
| <ResizablePanelGroup direction="vertical"> | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <CodeEditorPanel readOnly={false} /> | ||
| </div> | ||
| </ResizablePanel> | ||
| <ResizableHandle className="bg-gray-400 hover:bg-gray-600 w-1 cursor-col-resize" /> | ||
| <ResizablePanel> | ||
| <div className="h-full overflow-y-auto"> | ||
| <CodeOutputPanel /> | ||
| </div> | ||
| </ResizablePanel> | ||
| </ResizablePanelGroup> | ||
| </ResizablePanel> | ||
| </ResizablePanelGroup> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.