Skip to content

Commit c95d7bf

Browse files
Ahtesham QuraishAhtesham Quraish
authored andcommitted
addressed the comments on PR
1 parent e2e72fd commit c95d7bf

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

frontends/ol-components/src/components/TiptapEditor/TiptapEditor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const StyledEditorContent = styled(EditorContent)<{ readOnly: boolean }>(
4848
backgroundColor: theme.custom.colors.white,
4949
borderRadius: "10px",
5050
margin: "20px auto",
51+
".tiptap.ProseMirror.simple-editor": {
52+
padding: "3rem 3rem 5vh",
53+
},
5154
...(readOnly
5255
? {
5356
maxWidth: "1000px",

frontends/ol-components/src/components/TiptapEditor/components/tiptap-node/media-embed/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
.media-container {
9090
position: relative;
9191
width: 100%;
92-
height: 100vh; // ✅ add height here
92+
aspect-ratio: 16 / 9;
9393
overflow: hidden;
9494
}
9595

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { useState, useCallback } from "react"
2+
import NiceModal, { muiDialogV5 } from "@ebay/nice-modal-react"
3+
import { TextField, Alert } from "@mitodl/smoot-design"
4+
import { FormDialog } from "ol-components"
5+
6+
const MediaUrlInputDialog = NiceModal.create(() => {
7+
const modal = NiceModal.useModal()
8+
const [url, setUrl] = useState("")
9+
const [error, setError] = useState<string | null>(null)
10+
11+
const handleSubmit = (e?: any) => {
12+
e?.preventDefault()
13+
14+
if (!url.trim()) {
15+
setError("URL is required")
16+
return
17+
}
18+
modal.resolve(url)
19+
modal.hide()
20+
}
21+
22+
const handleReset = useCallback(() => {
23+
setUrl("")
24+
setError(null)
25+
}, [setUrl, setError])
26+
27+
return (
28+
<FormDialog
29+
{...muiDialogV5(modal)}
30+
title="Embed Media"
31+
confirmText="Insert"
32+
onSubmit={handleSubmit}
33+
onReset={handleReset}
34+
noValidate
35+
fullWidth
36+
>
37+
<TextField
38+
name="mediaUrl"
39+
label="Media URL"
40+
placeholder="https://youtube.com/..."
41+
value={url}
42+
error={!!error}
43+
errorText={error ?? ""}
44+
onChange={(e: any) => {
45+
setError(null)
46+
setUrl(e.target.value)
47+
}}
48+
fullWidth
49+
/>
50+
51+
{error && <Alert severity="error">{error}</Alert>}
52+
</FormDialog>
53+
)
54+
})
55+
56+
export default MediaUrlInputDialog

frontends/ol-components/src/components/TiptapEditor/components/tiptap-ui/media-embed/lib.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@ export function convertToEmbedUrl(url: string): string {
1515
return videoId ? `https://www.youtube.com/embed/${videoId}` : url
1616
}
1717

18-
// --- YOUTUBE SHORT ---
18+
// --- YOUTUBE SHORTS ---
19+
if (hostname === "youtube.com" && parsed.pathname.startsWith("/shorts/")) {
20+
const id = parsed.pathname.split("/shorts/")[1]
21+
return id ? `https://www.youtube.com/embed/${id}` : url
22+
}
23+
24+
// --- YOUTUBE SHORT youtu.be/shorts/??? (rare but possible) ---
25+
if (hostname === "youtu.be" && parsed.pathname.startsWith("/shorts/")) {
26+
const id = parsed.pathname.split("/shorts/")[1]
27+
return id ? `https://www.youtube.com/embed/${id}` : url
28+
}
29+
30+
// --- YOUTUBE SHORT youtu.be/VIDEO_ID ---
1931
if (hostname === "youtu.be") {
2032
const id = parsed.pathname.slice(1)
2133
return id ? `https://www.youtube.com/embed/${id}` : url
2234
}
2335

24-
// --- YOUTUBE /embed or other formats keep as is ---
36+
// --- YOUTUBE EMBED (leave as-is) ---
2537
if (hostname === "youtube.com" && parsed.pathname.startsWith("/embed/")) {
2638
return url
2739
}

frontends/ol-components/src/components/TiptapEditor/components/tiptap-ui/media-embed/useMediaEmbed.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useCallback, useMemo } from "react"
22
import type { Editor } from "@tiptap/react"
33
import { useTiptapEditor } from "../../../hooks/use-tiptap-editor"
44
import { convertToEmbedUrl } from "./lib"
5+
import NiceModal from "@ebay/nice-modal-react"
6+
import MediaUrlInputDialog from "./MediaUrlInputDialog"
57
import { Icon } from "./Icon"
68

79
export const MEDIA_EMBED_SHORTCUT_KEY = "Mod+Shift+E"
@@ -14,11 +16,16 @@ export function useMediaEmbed(editor?: Editor | null) {
1416

1517
const label = "Embed Media"
1618

17-
const handleEmbed = useCallback(() => {
18-
const url = prompt("Enter a media URL (YouTube, Vimeo, etc)")
19-
if (!url) return
19+
const handleEmbed = useCallback(async () => {
20+
try {
21+
const url: string = await NiceModal.show(MediaUrlInputDialog)
22+
console.log("URL received from modal:", url)
23+
if (!url) return
2024

21-
resolved?.commands.insertMedia(convertToEmbedUrl(url))
25+
resolved?.commands.insertMedia(convertToEmbedUrl(url))
26+
} catch {
27+
// modal was closed / cancelled
28+
}
2229
}, [resolved])
2330

2431
return {

0 commit comments

Comments
 (0)