Skip to content

Commit 3fb3c3a

Browse files
author
Rajat
committed
Removed embedded iframe in scorm viewer
1 parent 216856b commit 3fb3c3a

File tree

1 file changed

+8
-80
lines changed

1 file changed

+8
-80
lines changed

apps/web/components/public/lesson-viewer/scorm-viewer.tsx

Lines changed: 8 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use client";
22

3-
import { useEffect, useRef, useCallback, useState } from "react";
3+
import { useEffect, useRef, useCallback, useState, useContext } from "react";
44
import { debounce } from "@courselit/utils";
5+
import { Button } from "@courselit/page-primitives";
6+
import { ThemeContext } from "@components/contexts";
57

68
interface ScormViewerProps {
79
lessonId: string;
@@ -13,13 +15,11 @@ interface CMIData {
1315
}
1416

1517
export function ScormViewer({ lessonId, launchUrl }: ScormViewerProps) {
16-
const iframeRef = useRef<HTMLIFrameElement>(null);
17-
const [error, setError] = useState<string | null>(null);
18-
const [loading, setLoading] = useState(true);
1918
const [isDataLoaded, setIsDataLoaded] = useState(false);
2019
const scormState = useRef<CMIData>({});
2120
const pendingUpdates = useRef<Map<string, unknown>>(new Map());
2221
const sessionActive = useRef(false);
22+
const { theme } = useContext(ThemeContext);
2323

2424
// Centralized GetValue logic
2525
const getValue = useCallback((element: string): string => {
@@ -203,7 +203,6 @@ export function ScormViewer({ lessonId, launchUrl }: ScormViewerProps) {
203203
const API = {
204204
LMSInitialize: () => {
205205
sessionActive.current = true;
206-
setLoading(false);
207206
return "true";
208207
},
209208
LMSGetValue: (element: string) => getValue(element),
@@ -248,7 +247,6 @@ export function ScormViewer({ lessonId, launchUrl }: ScormViewerProps) {
248247
const API_1484_11 = {
249248
Initialize: () => {
250249
sessionActive.current = true;
251-
setLoading(false);
252250
return "true";
253251
},
254252
GetValue: (element: string) => getValue(element),
@@ -282,23 +280,6 @@ export function ScormViewer({ lessonId, launchUrl }: ScormViewerProps) {
282280
};
283281
}, [isDataLoaded, getValue, setValue, commitToServer, forceFlush]);
284282

285-
const handleIframeLoad = () => {
286-
setLoading(false);
287-
};
288-
289-
const handleIframeError = () => {
290-
setError("Failed to load SCORM content");
291-
setLoading(false);
292-
};
293-
294-
const handleRetry = () => {
295-
setError(null);
296-
setLoading(true);
297-
if (iframeRef.current) {
298-
iframeRef.current.src = iframeRef.current.src;
299-
}
300-
};
301-
302283
// Open in popup window
303284
const openInPopup = useCallback(() => {
304285
const url = `/api/scorm/lesson/${lessonId}/content/${launchUrl}`;
@@ -314,64 +295,11 @@ export function ScormViewer({ lessonId, launchUrl }: ScormViewerProps) {
314295
);
315296
}, [lessonId, launchUrl]);
316297

317-
if (error) {
318-
return (
319-
<div className="flex flex-col items-center justify-center h-full p-8 bg-muted rounded-lg">
320-
<p className="text-destructive mb-4">{error}</p>
321-
<button
322-
onClick={handleRetry}
323-
className="px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90"
324-
>
325-
Retry
326-
</button>
327-
</div>
328-
);
329-
}
330-
331298
return (
332-
<div className="relative w-full h-[85vh] rounded-lg shadow-sm overflow-hidden border bg-background">
333-
{/* Toolbar with open in popup button */}
334-
<div className="absolute top-2 right-2 z-20 flex gap-2">
335-
<button
336-
onClick={openInPopup}
337-
className="flex items-center gap-1 px-3 py-1.5 text-xs font-medium bg-background/90 border rounded-md hover:bg-muted transition-colors shadow-sm"
338-
title="Open in fullscreen window"
339-
>
340-
<svg
341-
xmlns="http://www.w3.org/2000/svg"
342-
width="14"
343-
height="14"
344-
viewBox="0 0 24 24"
345-
fill="none"
346-
stroke="currentColor"
347-
strokeWidth="2"
348-
strokeLinecap="round"
349-
strokeLinejoin="round"
350-
>
351-
<polyline points="15 3 21 3 21 9" />
352-
<polyline points="9 21 3 21 3 15" />
353-
<line x1="21" y1="3" x2="14" y2="10" />
354-
<line x1="3" y1="21" x2="10" y2="14" />
355-
</svg>
356-
Open Fullscreen
357-
</button>
358-
</div>
359-
{loading && (
360-
<div className="absolute inset-0 flex items-center justify-center bg-background/80 z-10">
361-
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary" />
362-
</div>
363-
)}
364-
{isDataLoaded && (
365-
<iframe
366-
ref={iframeRef}
367-
src={`/api/scorm/lesson/${lessonId}/content/${launchUrl}`}
368-
className="w-full h-full border-0"
369-
sandbox="allow-scripts allow-forms allow-same-origin allow-popups"
370-
onLoad={handleIframeLoad}
371-
onError={handleIframeError}
372-
title="SCORM Content"
373-
/>
374-
)}
299+
<div>
300+
<Button theme={theme.theme} onClick={openInPopup}>
301+
Enter
302+
</Button>
375303
</div>
376304
);
377305
}

0 commit comments

Comments
 (0)