-
Notifications
You must be signed in to change notification settings - Fork 1
Amp support for Tiktok Videos #469
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
Open
VeenaYemmiganur
wants to merge
6
commits into
master
Choose a base branch
from
tiktok-task
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−6
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c5c5fb
Add. tiktok story element
VeenaYemmiganur f9cf1da
refactor. remove unwanted code
VeenaYemmiganur 4330110
chore(release): 2.18.3-tiktok-task.0
VeenaYemmiganur 94347fa
Merge master to branch
VeenaYemmiganur 040b303
Refactor. move tiktok const to fixtures
VeenaYemmiganur 0cb127a
chore(release): 2.20.0-tiktok-task.0
VeenaYemmiganur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const tiktokElement = { | ||
| description: "", | ||
| "embed-js": | ||
| "PGJsb2NrcXVvdGUgY2xhc3M9InRpa3Rvay1lbWJlZCIgY2l0ZT0iaHR0cHM6Ly93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xhIHRpdGxlPSJhc21yIiB0YXJnZXQ9Il9ibGFuayIgaHJlZj0iaHR0cHM6Ly93d3cudGlrdG9rLmNvbS90YWcvYXNtcj9yZWZlcj1lbWJlZCI+I2FzbXI8L2E+IDxhIHRpdGxlPSJydWdjbGVhbmluZyIgdGFyZ2V0PSJfYmxhbmsiIGhyZWY9Imh0dHBzOi8vd3d3LnRpa3Rvay5jb20vdGFnL3J1Z2NsZWFuaW5nP3JlZmVyPWVtYmVkIj4jcnVnY2xlYW5pbmc8L2E+IDxhIHRpdGxlPSJkaGFybWFubiIgdGFyZ2V0PSJfYmxhbmsiIGhyZWY9Imh0dHBzOi8vd3d3LnRpa3Rvay5jb20vdGFnL2RoYXJtYW5uP3JlZmVyPWVtYmVkIj4jZGhhcm1hbm48L2E+PC9wPiA8YSB0YXJnZXQ9Il9ibGFuayIgdGl0bGU9IuKZrCBvcmlnaW5hbCBzb3VuZCAtIERoYXJXb21hbiAtIFRoZSBWaXJhbCBWaWRlb3MiIGhyZWY9Imh0dHBzOi8vd3d3LnRpa3Rvay5jb20vbXVzaWMvb3JpZ2luYWwtc291bmQtRGhhcldvbWFuLTczNjE2MzE4Njk0ODc1NDkyMTY/cmVmZXI9ZW1iZWQiPuKZrCBvcmlnaW5hbCBzb3VuZCAtIERoYXJXb21hbiAtIFRoZSBWaXJhbCBWaWRlb3M8L2E+IDwvc2VjdGlvbj4gPC9ibG9ja3F1b3RlPiA8c2NyaXB0IGFzeW5jIHNyYz0iaHR0cHM6Ly93d3cudGlrdG9rLmNvbS9lbWJlZC5qcyI+PC9zY3JpcHQ+", | ||
| "page-url": "/story/872a1a37-47dd-4c66-88c2-7fa87887652f/element/55cc4513-d602-4d8f-abbd-e8804fa6ad81", | ||
| type: "jsembed", | ||
| "family-id": "f764a562-a7a2-41b3-8d76-2fe4e0c123a5", | ||
| title: "", | ||
| id: "c4fba672-a3c8-462c-9cd5-0a341bf681d9", | ||
| metadata: { | ||
| "tiktok-video-url": "https://www.tiktok.com/@dharwmans/video/7361631790051642657", | ||
| provider: "tiktok", | ||
| "tiktok-video-id": "7361631790051642657" | ||
| }, | ||
| subtype: "tiktok-video" | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import { TiktokElement } from "./tiktok-element"; | ||
| export { TiktokElement }; |
19 changes: 19 additions & 0 deletions
19
src/atoms/story-elements/tiktok-element/tiktok-element.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from "react"; | ||
| import { storiesOf } from "@storybook/react"; | ||
| import { config, textStory, tiktokElement } from "../../../__fixtures__"; | ||
| import { Layout } from "../../layout"; | ||
| import { TiktokElement } from "./tiktok-element"; | ||
|
|
||
| const { metadata, ...sampleTiktokElementWithoutMetadata } = tiktokElement; | ||
|
|
||
| storiesOf("Tiktok Element", module) | ||
| .addDecorator((story) => ( | ||
| <Layout story={textStory} config={config}> | ||
| {story()} | ||
| </Layout> | ||
| )) | ||
| .add("Default", () => <TiktokElement element={tiktokElement} />) | ||
| .add("With a square different layout", () => ( | ||
| <TiktokElement element={tiktokElement} layout="fixed" width="400" height="400" /> | ||
| )) | ||
| .add("Tiktok without metadata", () => <TiktokElement element={sampleTiktokElementWithoutMetadata} />); |
24 changes: 24 additions & 0 deletions
24
src/atoms/story-elements/tiktok-element/tiktok-element.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from "react"; | ||
| import { mount, shallow } from "enzyme"; | ||
| import { config, textStory, tiktokElement } from "../../../__fixtures__"; | ||
| import { TiktokElement, TiktokElementBase } from "./tiktok-element"; | ||
|
|
||
| const { metadata, ...sampleTiktokElementWithoutMetadata } = tiktokElement; | ||
|
|
||
| describe("Tiktok Element", () => { | ||
| it("should render Tiktok", () => { | ||
| const wrapper = mount(<TiktokElement element={tiktokElement} />); | ||
| expect(wrapper.find("amp-tiktok").length).toBe(1); | ||
| }); | ||
| it("should call tiktokElementRender prop when passed to opts", () => { | ||
| const tiktokElementRender = jest.fn(); | ||
| const modifiedConfig = { ...config, opts: { render: { storyElementRender: { tiktokElementRender } } } }; | ||
| const wrapper = shallow(<TiktokElementBase element={tiktokElement} story={textStory} config={modifiedConfig} />); | ||
| expect(tiktokElementRender.mock.calls.length).toBe(1); | ||
| expect(wrapper.find(TiktokElement).length).toBe(0); | ||
| }); | ||
| it("shouldn't render Tiktok", () => { | ||
| const wrapper = mount(<TiktokElement element={sampleTiktokElementWithoutMetadata} />); | ||
| expect(wrapper.find("amp-tiktok").length).toBe(0); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
src/atoms/story-elements/tiktok-element/tiktok-element.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import React, { Fragment } from "react"; | ||
| import get from "lodash.get"; | ||
| import Helmet from "react-helmet"; | ||
| import { withStoryAndConfig } from "../../../context"; | ||
| import { StoryElementProps } from "../types"; | ||
| import { TiktokTypes } from "./types"; | ||
| type TiktokElementProps = StoryElementProps & Omit<TiktokTypes, "data-src">; | ||
|
|
||
| export const Tiktok = (props: TiktokTypes) => { | ||
| const { width, height } = props; | ||
| const setDefaultLayout = !width || !height; | ||
| const componentProps: TiktokTypes = setDefaultLayout | ||
| ? { | ||
| ...props, | ||
| width: "325", | ||
| height: "575" | ||
| } | ||
| : props; | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| <Helmet> | ||
| <script async={undefined} custom-element="amp-tiktok" src="https://cdn.ampproject.org/v0/amp-tiktok-0.1.js" /> | ||
| </Helmet> | ||
| <amp-tiktok {...componentProps} /> | ||
| </Fragment> | ||
| ); | ||
| }; | ||
|
|
||
| export const TiktokElementBase = ({ element, story, config, ...props }: TiktokElementProps) => { | ||
| const { metadata } = element; | ||
| const tiktokElementRender = get(config, ["opts", "render", "storyElementRender", "tiktokElementRender"], null); | ||
| if (!(metadata && metadata["tiktok-video-id"])) return null; | ||
|
|
||
| return tiktokElementRender ? ( | ||
| tiktokElementRender({ story, config, element }) | ||
| ) : ( | ||
| <Tiktok data-src={metadata["tiktok-video-id"]} {...props} /> | ||
| ); | ||
| }; | ||
| /** | ||
| * TiktokElement is a story element. | ||
| * The look of the TiktokElement can be changed using the render prop tiktokElementRender. In case tiktokElementRender is passed in the config, it is rendered. Otherwise a default TiktokElement is rendered. | ||
| * | ||
| * @param {Object} params object containing parameters passed to the render prop | ||
| * @param {Object} params.story story object | ||
| * @param {Object} params.config config object | ||
| * @param {Object} params.element the story element. This is same as the story element found in the story API response | ||
| * | ||
| * ```javascript | ||
| * ... | ||
| * ampRoutes(app, { | ||
| * render: { | ||
| * storyElementRender: { | ||
| * tiktokElementRender: ({ story, config, element }) => <MyCustomTiktokElement story={story} config={config} storyElement={element} /> | ||
| * } | ||
| * } | ||
| * }) | ||
| * ... | ||
| * ``` | ||
| * | ||
| * @category StoryElements | ||
| * @module TiktokElement | ||
| * @component | ||
| */ | ||
| export const TiktokElement = withStoryAndConfig(TiktokElementBase); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Common } from "../../../atoms/common-types"; | ||
|
|
||
| export interface TiktokTypes extends Common { | ||
| "data-src": string; | ||
| children?: any; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we give 9/16 instead of this?