-
Notifications
You must be signed in to change notification settings - Fork 4.1k
✨ Bento port of amp-instagram #30230
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
Merged
kristoferbaxter
merged 81 commits into
ampproject:master
from
realPrimoh:bento-amp-instagram
Oct 29, 2020
Merged
Changes from 10 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
2a1090d
Preact version of amp-instagram (first pass)
realPrimoh 84afd2d
added title logic from old extension
realPrimoh 7323d80
ran prettier
realPrimoh a3d66a8
Made changes.
realPrimoh 0829f30
Deleted unnecessary CSS file
realPrimoh f2ce1cf
Made changes based on suggestions. Updated build-system
realPrimoh 6081657
Addressed nits
realPrimoh f5dd5e0
Made changes to title
realPrimoh 2b2866c
cleared some build errors
realPrimoh 43c45a3
addressed more travis errors
realPrimoh 95538f7
Should pass travis now.
realPrimoh b75a826
Added intermediate height variable.
realPrimoh bd35235
Initialize heightStyle to prop.
realPrimoh 7e62622
initial test
realPrimoh a4d58a6
Added some working Preact tests
realPrimoh 5b598ef
Made non-test changes
realPrimoh 47fad0f
Updated tests
realPrimoh 9e0eb24
Preliminary resize function test.
realPrimoh 793d2c3
Preact tests complete.
realPrimoh 0f725d2
Updated amp-instagram test (Trial)
realPrimoh eb12c6d
Added test-amp-instagram tests
realPrimoh 0c06dcc
fixed height jsc compiler error
realPrimoh da8c3fc
Can't pass in resize prop for amp component
realPrimoh e0aabb9
Removed shortcode error handling
realPrimoh e12af15
Used dict() to bypass JSC compiler error w/ useState
realPrimoh 9368a8d
Remove unnecessary requestResize
realPrimoh b07bd0a
Removed style prop and added onLoad to iframe
realPrimoh e3adb07
Merge branch 'bento-amp-instagram' of https://github.com/realPrimoh/a…
realPrimoh 2f5df8c
addressed all comments except for testing changes
realPrimoh 5a92d86
Modularized Preact component to make it easier to test
realPrimoh 53485f1
Addressed comment.
realPrimoh b63f2d5
Addressed new comments.
realPrimoh 7c07c01
Draft PR: testing on travis
realPrimoh d8cbb40
Added waitForPromise to fix any race conditions
realPrimoh 6440e3e
Addressed comments
realPrimoh dcff08f
Some finishing touches to the tests.
realPrimoh 6dd1e4d
Used createElementWithAttributes (optional nit)
realPrimoh 51fd38e
Preact version of amp-instagram (first pass)
realPrimoh c0e3ece
added title logic from old extension
realPrimoh cd2c07a
ran prettier
realPrimoh 4f87214
Made changes.
realPrimoh b262a9b
Deleted unnecessary CSS file
realPrimoh 56ab186
Made changes based on suggestions. Updated build-system
realPrimoh d584be7
Addressed nits
realPrimoh e877cde
Made changes to title
realPrimoh abf0f77
cleared some build errors
realPrimoh f586687
addressed more travis errors
realPrimoh cfb3387
Should pass travis now.
realPrimoh 8668d15
Added intermediate height variable.
realPrimoh 9ff9897
Initialize heightStyle to prop.
realPrimoh 5d9a744
initial test
realPrimoh 6375fb7
Added some working Preact tests
realPrimoh d9616d1
Made non-test changes
realPrimoh dba078d
Updated tests
realPrimoh 41b16e5
Preliminary resize function test.
realPrimoh 9f782a6
Preact tests complete.
realPrimoh 6a0db5a
Updated amp-instagram test (Trial)
realPrimoh d558cdc
Added test-amp-instagram tests
realPrimoh 89a5e8e
fixed height jsc compiler error
realPrimoh d897e8f
Can't pass in resize prop for amp component
realPrimoh 0d7a1ce
Removed shortcode error handling
realPrimoh deca0d3
Used dict() to bypass JSC compiler error w/ useState
realPrimoh 1aeda51
Remove unnecessary requestResize
realPrimoh acb33d3
Removed style prop and added onLoad to iframe
realPrimoh 4c6a5d3
addressed all comments except for testing changes
realPrimoh 972c9b9
Modularized Preact component to make it easier to test
realPrimoh 61f7a2d
Addressed comment.
realPrimoh a4659fd
Addressed new comments.
realPrimoh e7a5477
Draft PR: testing on travis
realPrimoh 82c8009
Added waitForPromise to fix any race conditions
realPrimoh bd3f1af
Addressed comments
realPrimoh a6fdf0d
Some finishing touches to the tests.
realPrimoh c81cec5
Used createElementWithAttributes (optional nit)
realPrimoh 86066e1
Merge branch 'bento-amp-instagram' of https://github.com/realPrimoh/a…
realPrimoh 419c14d
Merge branch 'master' into bento-amp-instagram
realPrimoh bbd0944
Removed unnecessary isLayoutSupported
realPrimoh e13300d
Addressed comments
realPrimoh f8abef9
Addressed comments. Removed unnecessary attachments from tests.
realPrimoh 2a2be97
re-pushing for travis build to re-run
realPrimoh 209b085
Merge branch 'master' into bento-amp-instagram
realPrimoh 5c35c67
re-pushing due to unrelated visual test error
realPrimoh 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
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,56 @@ | ||
| /** | ||
| * Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS-IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import {Instagram} from './instagram'; | ||
| import {PreactBaseElement} from '../../../src/preact/base-element'; | ||
| import {dict} from '../../../src/utils/object'; | ||
| import {isLayoutSizeDefined} from '../../../src/layout'; | ||
|
|
||
| /** @const {string} */ | ||
| const TAG = 'amp-instagram'; | ||
|
|
||
| class AmpInstagram extends PreactBaseElement { | ||
| /** @override */ | ||
| init() { | ||
| return dict({ | ||
| 'resize': (height) => { | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.forceChangeHeight(height); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** @override */ | ||
| isLayoutSupported(layout) { | ||
| return isLayoutSizeDefined(layout); | ||
| } | ||
| } | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** @override */ | ||
| AmpInstagram['Component'] = Instagram; | ||
|
|
||
| /** @override */ | ||
| AmpInstagram['props'] = { | ||
| 'shortcode': {attr: 'data-shortcode'}, | ||
| 'captioned': {attr: 'data-captioned'}, | ||
| 'title': {attr: 'title'}, | ||
| }; | ||
|
|
||
| /** @override */ | ||
| AmpInstagram['layoutSizeDefined'] = true; | ||
realPrimoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| AMP.extension(TAG, '1.0', (AMP) => { | ||
| AMP.registerElement(TAG, AmpInstagram); | ||
| }); | ||
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,89 @@ | ||
| /** | ||
| * Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS-IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as Preact from '../../../src/preact'; | ||
| import {ContainWrapper} from '../../../src/preact/component'; | ||
| import {getData} from '../../../src/event-helper'; | ||
| import {parseJson} from '../../../src/json'; | ||
| import {useMountEffect} from '../../../src/preact/utils'; | ||
| import {useRef, useState} from '../../../src/preact'; | ||
|
|
||
| /** | ||
| * @param {!InstagramPropsDef} props | ||
| * @return {PreactDef.Renderable} | ||
| */ | ||
| export function Instagram({shortcode, captioned, style, title, resize}) { | ||
| const iframeRef = useRef(null); | ||
| const [heightStyle, setHeightStyle] = useState(null); | ||
| const [opacity, setOpacity] = useState(0); | ||
|
|
||
| useMountEffect(() => { | ||
|
||
| /** | ||
| * @param {Event} event | ||
| */ | ||
| function handleMessage(event) { | ||
| if ( | ||
| event.origin != 'https://www.instagram.com' || | ||
| event.source != iframeRef.current.contentWindow | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const data = parseJson(getData(event)); | ||
|
|
||
| if (data['type'] == 'MEASURE') { | ||
| if (typeof resize === 'function') { | ||
|
||
| resize(data['details']['height']); | ||
| } else { | ||
| setHeightStyle({ | ||
| 'height': data['details']['height'], | ||
| }); | ||
| } | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setOpacity(1); | ||
realPrimoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| window.addEventListener('message', handleMessage); | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return () => { | ||
| window.removeEventListener('message', handleMessage); | ||
| }; | ||
| }); | ||
|
|
||
| return ( | ||
| <ContainWrapper style={{...style, ...heightStyle}} layout size paint> | ||
| <iframe | ||
| ref={iframeRef} | ||
| src={ | ||
| 'https://www.instagram.com/p/' + | ||
| (encodeURIComponent(shortcode) || 'error') + | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| '/embed/' + | ||
| (captioned ? 'captioned/' : '') + | ||
| '?cr=1&v=12' | ||
| } | ||
| scrolling="no" | ||
| frameborder="0" | ||
| allowtransparency | ||
| title={title} | ||
| style={{ | ||
| width: '100%', | ||
| height: '100%', | ||
| opacity, | ||
realPrimoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| /> | ||
| </ContainWrapper> | ||
| ); | ||
| } | ||
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,27 @@ | ||
| /** | ||
| * Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS-IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** @externs */ | ||
|
|
||
| /** @typedef {{ | ||
| * shortcode: string, | ||
| * captioned: (boolean|undefined), | ||
| * style: (Object|undefined), | ||
| * title: (string|undefined), | ||
| * resize: (function(number):*|undefined), | ||
| * }} | ||
| */ | ||
| var InstagramPropsDef; |
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,47 @@ | ||
| /** | ||
| * Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS-IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as Preact from '../../../../src/preact'; | ||
| import {boolean, number, text, withKnobs} from '@storybook/addon-knobs'; | ||
| import {storiesOf} from '@storybook/preact'; | ||
| import {withA11y} from '@storybook/addon-a11y'; | ||
| import {withAmp} from '@ampproject/storybook-addon'; | ||
|
|
||
| // eslint-disable-next-line | ||
| storiesOf('amp-instagram', module) | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .addDecorator(withKnobs) | ||
| .addDecorator(withA11y) | ||
| .addDecorator(withAmp) | ||
| .addParameters({ | ||
| extensions: [{name: 'amp-instagram', version: '1.0'}], | ||
| }) | ||
| .add('Default', () => { | ||
| const width = number('width', 500); | ||
| const height = number('height', 600); | ||
| const shortcode = text('shortcode', 'B8QaZW4AQY_'); | ||
| const captioned = boolean('captioned'); | ||
| const layout = text('layout', 'fixed'); | ||
|
|
||
| return ( | ||
| <amp-instagram | ||
| data-shortcode={shortcode} | ||
| data-captioned={captioned} | ||
| width={width} | ||
realPrimoh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| height={height} | ||
| layout={layout} | ||
| ></amp-instagram> | ||
| ); | ||
| }); | ||
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,42 @@ | ||
| /** | ||
| * Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS-IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as Preact from '../../../../src/preact'; | ||
| import {Instagram} from '../instagram'; | ||
| import {boolean, number, text, withKnobs} from '@storybook/addon-knobs'; | ||
| import {withA11y} from '@storybook/addon-a11y'; | ||
|
|
||
| export default { | ||
| title: 'Instagram', | ||
| component: Instagram, | ||
| decorators: [withA11y, withKnobs], | ||
| }; | ||
|
|
||
| export const _default = () => { | ||
| const width = number('width', 500); | ||
| const height = number('height', 600); | ||
| const shortcode = text('shortcode', 'B8QaZW4AQY_'); | ||
| const captioned = boolean('captioned'); | ||
|
|
||
| return ( | ||
| shortcode={shortcode} | ||
| style={{width, height}} | ||
| captioned={captioned} | ||
| alt="AMP Instagram Storybook Preact Example" | ||
| ></Instagram> | ||
| ); | ||
| }; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.