Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/app/room/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useEffect, useRef, useState, useCallback, Suspense } from "react";
import { useSearchParams, useRouter } from "next/navigation";
import { io, type Socket } from "socket.io-client";
import { Download, PanelRightClose, Square, X } from "lucide-react";
import { Download, Maximize, PanelRightClose, Square, X } from "lucide-react";
import type { ImperativePanelHandle } from "react-resizable-panels";

import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";
Expand Down Expand Up @@ -169,6 +169,7 @@ function RoomInner() {
const [endingSession, setEndingSession] = useState(false);
const chatHistoryRef = useRef<Question[]>([]);
const chatPanelRef = useRef<ImperativePanelHandle>(null);
const [isPresenting, setIsPresenting] = useState(false);
const slideContextRef = useRef<SlideContextSnapshot>({
slidePageIndex: null,
slideSetId: null,
Expand Down Expand Up @@ -403,6 +404,8 @@ function RoomInner() {
onEndLecture={isProfessor ? () => setShowEndModal(true) : undefined}
onSlideContextChange={handleSlideContextChange}
slideNavTarget={slideNavTarget}
isPresenting={isPresenting}
onExitPresenting={() => setIsPresenting(false)}
/>
</ResizablePanel>
<ResizableHandle withHandle className={isChatVisible ? "" : "invisible"} />
Expand All @@ -425,14 +428,24 @@ function RoomInner() {
</ResizablePanel>
</ResizablePanelGroup>
{!isChatVisible && (
<button
onClick={() => chatPanelRef.current?.expand()}
title="Show chat"
aria-label="Show chat"
className="absolute top-2 right-2 z-20 w-9 h-9 flex items-center justify-center rounded-md bg-secondary/90 text-muted-foreground shadow-sm border border-border hover:bg-accent hover:text-accent-foreground transition-colors"
>
<PanelRightClose className={`w-5 h-5 ${isMdSize ? "rotate-180" : "rotate-270"}`} />
</button>
<div className="absolute top-2 right-2 z-20 flex flex-col gap-2">
<button
onClick={() => chatPanelRef.current?.expand()}
title="Show chat"
aria-label="Show chat"
className="w-9 h-9 flex items-center justify-center rounded-md bg-secondary/90 text-muted-foreground shadow-sm border border-border hover:bg-accent hover:text-accent-foreground transition-colors"
>
<PanelRightClose className={`w-5 h-5 ${isMdSize ? "rotate-180" : "rotate-270"}`} />
</button>
<button
onClick={() => setIsPresenting(true)}
title="Presenter view (Esc to exit)"
aria-label="Presenter view"
className="w-9 h-9 flex items-center justify-center rounded-md bg-secondary/90 text-muted-foreground shadow-sm border border-border hover:bg-accent hover:text-accent-foreground transition-colors"
>
<Maximize className="w-5 h-5" />
</button>
</div>
)}
</div>

Expand Down
55 changes: 52 additions & 3 deletions src/app/room/slideViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SquareMousePointer,
Upload,
LogOut,
Minimize,
Unlink,
Undo2,
} from "lucide-react";
Expand Down Expand Up @@ -38,6 +39,8 @@ interface SlideViewerProps {
onEndLecture?: () => void;
onSlideContextChange?: (ctx: SlideContextSnapshot) => void;
slideNavTarget?: SlideContextSnapshot | null;
isPresenting?: boolean;
onExitPresenting?: () => void;
}

// ---------------------------------------------------------------------------
Expand All @@ -64,6 +67,8 @@ interface SlideUIProps {
onSlideContextChange?: (ctx: SlideContextSnapshot) => void;
onReplaceSlides?: (file: File) => void;
onEndLecture?: () => void;
isPresenting?: boolean;
onExitPresenting?: () => void;
}

function SlideUI({
Expand All @@ -74,6 +79,8 @@ function SlideUI({
onSlideContextChange,
onReplaceSlides,
onEndLecture,
isPresenting,
onExitPresenting,
}: SlideUIProps) {
const { socket, sessionId, userId, role, slideReturnTarget, goBackToPreviousSlide } = useRoom();
const router = useRouter();
Expand Down Expand Up @@ -239,6 +246,26 @@ function SlideUI({
[pageCount, navigateToLocal, isControlling, socket, sessionId]
);

// -------------------------------------------------------------------------
// Presenter view — slides fill the tab
// -------------------------------------------------------------------------

// The controls bar is hidden while presenting, so a follower has no "Back to
// Live" — leave them following rather than silently detaching them.
const canStep = isPresenting && (isControlling || mode === "browsing");

useEffect(() => {
if (!isPresenting) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") onExitPresenting?.();
else if (!canStep) return;
else if (e.key === "ArrowRight") navigateTo(pageIndex + 1);
else if (e.key === "ArrowLeft") navigateTo(pageIndex - 1);
};
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, [isPresenting, canStep, onExitPresenting, navigateTo, pageIndex]);

// Question-badge jump: the person driving takes the room with them; everyone
// else detaches and looks on their own.
useEffect(() => {
Expand Down Expand Up @@ -337,7 +364,23 @@ function SlideUI({
// -------------------------------------------------------------------------

return (
<div className="flex flex-col flex-1 w-full min-h-0">
<div
onClick={canStep ? () => navigateTo(pageIndex + 1) : undefined}
className={`flex flex-col w-full min-h-0 ${isPresenting ? "fixed inset-0 z-50 bg-black" : "flex-1"}`}
>
{isPresenting && (
<button
onClick={(e) => {
e.stopPropagation();
onExitPresenting?.();
}}
title="Exit presenter view (Esc)"
aria-label="Exit presenter view"
className="absolute top-2 right-2 z-10 w-9 h-9 flex items-center justify-center rounded-md bg-white/10 text-white/70 hover:bg-white/20 hover:text-white transition-colors cursor-pointer"
>
<Minimize className="w-5 h-5" />
</button>
)}
{/* Slide canvas */}
{activeDocumentId ? (
<DocumentContent documentId={activeDocumentId}>
Expand All @@ -364,8 +407,10 @@ function SlideUI({
</div>
)}

{/* Controls bar — always rendered */}
<div className="shrink-0 w-full overflow-x-auto overscroll-x-contain">
{/* Controls bar — always rendered, hidden while presenting */}
<div
className={`shrink-0 w-full overflow-x-auto overscroll-x-contain ${isPresenting ? "hidden" : ""}`}
>
<div className="flex w-max min-w-full items-center justify-center gap-3 px-4 py-4 whitespace-nowrap">
{slideReturnTarget?.slidePageIndex != null && (
<>
Expand Down Expand Up @@ -651,6 +696,8 @@ export default function SlideViewer({
onEndLecture,
onSlideContextChange,
slideNavTarget,
isPresenting,
onExitPresenting,
}: SlideViewerProps) {
const { engine, isLoading: engineLoading } = usePdfiumEngine();
const { sessionId, socket } = useRoom();
Expand Down Expand Up @@ -850,6 +897,8 @@ export default function SlideViewer({
onSlideContextChange={onSlideContextChange}
onReplaceSlides={isProfessor ? handleUpload : undefined}
onEndLecture={isProfessor ? onEndLecture : undefined}
isPresenting={isPresenting}
onExitPresenting={onExitPresenting}
/>
)}
</EmbedPDF>
Expand Down
Loading