Skip to content

Commit

Permalink
[Upd #149] Refactor iframe parameter in options
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope authored and blcham committed Oct 16, 2022
1 parent 49ff881 commit 61f3074
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const globalTypes = {
defaultValue: false,
control: { type: "boolean" },
},
isIframe: {
name: "IFrame",
unifyMediaContent: {
name: "Unify media content",
description: "Set IFrame to eligible media contents",
defaultValue: false,
control: { type: "boolean" },
Expand All @@ -73,7 +73,7 @@ const options = {
wizardStepButtons: true,
enableForwardSkip: true,
startingStep: 1,
isIframe: false,
unifyMediaContent: true,
debugMode: false,
users: [
{ id: "http://fel.cvut.cz/people/max-chopart", label: "Max Chopart" },
Expand Down
11 changes: 7 additions & 4 deletions src/components/MediaContent.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import React, { useContext } from "react";
import Constants from "../constants/Constants";
import LinkIcon from "./LinkIcon";
// @ts-ignore
import ImageZoom from "react-image-zooom";
import { ConfigurationContext } from "../contexts/ConfigurationContext";

interface Props {
question: object;
isIframe?: boolean;
}

const YOUTUBE_URL = "https://www.youtube.com/";
Expand All @@ -16,7 +16,10 @@ const EMBED_URL_PARAMETER = "embed/";
const GOOGLE_DRIVE_FILE_PATH = "/file/d/";
const GOOGLE_DRIVE = "uc?export=view&id=";

const MediaContent = ({ question, isIframe = true }: Props) => {
const MediaContent = ({ question }: Props) => {
// @ts-ignore
const { options } = useContext(ConfigurationContext);

const isGoogleDriveImage = (mediaContentUrl: string) => {
return (
mediaContentUrl.includes(GOOGLE_DRIVE_FILE_PATH) &&
Expand Down Expand Up @@ -64,7 +67,7 @@ const MediaContent = ({ question, isIframe = true }: Props) => {
const getMediaType = (mediaContentUrl: string) => {
if (
isYoutubeVideo(mediaContentUrl) ||
(isGoogleDriveImage(mediaContentUrl) && isIframe)
(isGoogleDriveImage(mediaContentUrl) && options.unifyMediaContent)
) {
return (
<div className="media-content-image">
Expand Down
17 changes: 13 additions & 4 deletions src/stories/MediaContent.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";
import MediaContent from "../components/MediaContent";
import { ComponentMeta, ComponentStory } from "@storybook/react";

import questionWithMedia from "./assets/question/questionWithMedia.json";
import { ConfigurationContextProvider } from "../contexts/ConfigurationContext";

const question = {
"@id": "job-9002",
Expand All @@ -23,8 +22,18 @@ export default {
component: MediaContent,
} as ComponentMeta<typeof MediaContent>;

const Template: ComponentStory<typeof MediaContent> = (args) => {
return <MediaContent {...args} />;
const Template: ComponentStory<typeof MediaContent> = (
args,
{ globals: { unifyMediaContent } }
) => {
const options = {
unifyMediaContent: unifyMediaContent,
};
return (
<ConfigurationContextProvider options={options}>
<MediaContent {...args} />
</ConfigurationContextProvider>
);
};

export const Default = Template.bind({});
Expand Down

0 comments on commit 61f3074

Please sign in to comment.