Skip to content
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

Extension for the Media component. Adding default youtube videos. #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/components/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const Media: FunctionComponent<IMediaProps> = (props) => {
if (type === "video") {
return <video {...componentProps} autoPlay={false} controls />
}
if (type === "youtube") {
const youtubeDefaultwidth = componentProps.width ? componentProps.width : 560;
const youtubeDefaultheight = componentProps.height ? componentProps.height : 315;
const srcLink = componentProps.src.split('/')[3].split('v=')[1];
return <iframe width={youtubeDefaultwidth} height={youtubeDefaultheight} src={`https://www.youtube.com/embed/${srcLink}`} frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
}
return null
}

Expand Down
64 changes: 36 additions & 28 deletions src/components/UrlPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import InsertPhotoIcon from '@material-ui/icons/InsertPhoto'
import MovieIcon from '@material-ui/icons/Movie'
import CheckIcon from '@material-ui/icons/Check'
import DeleteIcon from '@material-ui/icons/DeleteOutline'
import YouTubeIcon from '@material-ui/icons/YouTube';
import FormatAlignCenter from '@material-ui/icons/FormatAlignCenter'
import FormatAlignLeft from '@material-ui/icons/FormatAlignLeft'
import FormatAlignRight from '@material-ui/icons/FormatAlignRight'

export type TAlignment = "left" | "center" | "right"

export type TMediaType = "image" | "video"
export type TMediaType = "image" | "video" | "youtube"

export type TUrlData = {
url?: string
Expand Down Expand Up @@ -84,7 +85,7 @@ const UrlPopover: FunctionComponent<IUrlPopoverStateProps> = (props) => {
<Grid item xs={12}>
<TextField
className={classes.linkTextField}
onChange={(event) => setData({...data, url: event.target.value})}
onChange={(event) => setData({ ...data, url: event.target.value })}
label="URL"
defaultValue={props.data && props.data.url}
autoFocus={true}
Expand All @@ -97,20 +98,27 @@ const UrlPopover: FunctionComponent<IUrlPopoverStateProps> = (props) => {
<>
<Grid item xs={12}>
<ButtonGroup fullWidth>
<Button
color={(!data.type || data.type === "image") ? "primary" : "default"}
size="small"
onClick={() => setData({...data, type: "image"})}
<Button
color={(!data.type || data.type === "image") ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, type: "image" })}
>
<InsertPhotoIcon />
</Button>
<Button
color={data.type === "video" ? "primary" : "default"}
size="small"
onClick={() => setData({...data, type: "video"})}
<Button
color={data.type === "video" ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, type: "video" })}
>
<MovieIcon />
</Button>
<Button
color={data.type === "youtube" ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, type: "youtube" })}
>
<YouTubeIcon />
</Button>
</ButtonGroup>
</Grid>
<Grid item xs={6}>
Expand All @@ -135,24 +143,24 @@ const UrlPopover: FunctionComponent<IUrlPopoverStateProps> = (props) => {
</Grid>
<Grid item xs={12}>
<ButtonGroup fullWidth>
<Button
color={data.alignment === "left" ? "primary" : "default"}
size="small"
onClick={() => setData({...data, alignment: "left"})}
<Button
color={data.alignment === "left" ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, alignment: "left" })}
>
<FormatAlignLeft />
</Button>
<Button
color={data.alignment === "center" ? "primary" : "default"}
size="small"
onClick={() => setData({...data, alignment: "center"})}
<Button
color={data.alignment === "center" ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, alignment: "center" })}
>
<FormatAlignCenter />
</Button>
<Button
color={data.alignment === "right" ? "primary" : "default"}
size="small"
onClick={() => setData({...data, alignment: "right"})}>
<Button
color={data.alignment === "right" ? "primary" : "default"}
size="small"
onClick={() => setData({ ...data, alignment: "right" })}>
<FormatAlignRight />
</Button>
</ButtonGroup>
Expand All @@ -162,12 +170,12 @@ const UrlPopover: FunctionComponent<IUrlPopoverStateProps> = (props) => {
</Grid>
<Grid container item xs={12} direction="row" justify="flex-end">
{props.data && props.data.url ?
<Button
onClick={() => props.onConfirm(props.isMedia, "")}
>
<DeleteIcon />
</Button>
: null }
<Button
onClick={() => props.onConfirm(props.isMedia, "")}
>
<DeleteIcon />
</Button>
: null}
<Button
onClick={() => props.onConfirm(props.isMedia, data.url, data.width, data.height, data.alignment, data.type)}
>
Expand Down