Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 Sep 15, 2020
84afd2d
added title logic from old extension
realPrimoh Sep 15, 2020
7323d80
ran prettier
realPrimoh Sep 15, 2020
a3d66a8
Made changes.
realPrimoh Sep 15, 2020
0829f30
Deleted unnecessary CSS file
realPrimoh Sep 16, 2020
f2ce1cf
Made changes based on suggestions. Updated build-system
realPrimoh Sep 16, 2020
6081657
Addressed nits
realPrimoh Sep 16, 2020
f5dd5e0
Made changes to title
realPrimoh Sep 17, 2020
2b2866c
cleared some build errors
realPrimoh Sep 17, 2020
43c45a3
addressed more travis errors
realPrimoh Sep 18, 2020
95538f7
Should pass travis now.
realPrimoh Sep 18, 2020
b75a826
Added intermediate height variable.
realPrimoh Sep 18, 2020
bd35235
Initialize heightStyle to prop.
realPrimoh Sep 18, 2020
7e62622
initial test
realPrimoh Sep 18, 2020
a4d58a6
Added some working Preact tests
realPrimoh Sep 21, 2020
5b598ef
Made non-test changes
realPrimoh Sep 22, 2020
47fad0f
Updated tests
realPrimoh Sep 22, 2020
9e0eb24
Preliminary resize function test.
realPrimoh Sep 22, 2020
793d2c3
Preact tests complete.
realPrimoh Sep 22, 2020
0f725d2
Updated amp-instagram test (Trial)
realPrimoh Sep 22, 2020
eb12c6d
Added test-amp-instagram tests
realPrimoh Sep 23, 2020
0c06dcc
fixed height jsc compiler error
realPrimoh Sep 23, 2020
da8c3fc
Can't pass in resize prop for amp component
realPrimoh Sep 23, 2020
e0aabb9
Removed shortcode error handling
realPrimoh Sep 23, 2020
e12af15
Used dict() to bypass JSC compiler error w/ useState
realPrimoh Sep 23, 2020
9368a8d
Remove unnecessary requestResize
realPrimoh Sep 23, 2020
b07bd0a
Removed style prop and added onLoad to iframe
realPrimoh Sep 23, 2020
e3adb07
Merge branch 'bento-amp-instagram' of https://github.com/realPrimoh/a…
realPrimoh Sep 23, 2020
2f5df8c
addressed all comments except for testing changes
realPrimoh Sep 25, 2020
5a92d86
Modularized Preact component to make it easier to test
realPrimoh Sep 26, 2020
53485f1
Addressed comment.
realPrimoh Sep 28, 2020
b63f2d5
Addressed new comments.
realPrimoh Sep 29, 2020
7c07c01
Draft PR: testing on travis
realPrimoh Oct 1, 2020
d8cbb40
Added waitForPromise to fix any race conditions
realPrimoh Oct 2, 2020
6440e3e
Addressed comments
realPrimoh Oct 2, 2020
dcff08f
Some finishing touches to the tests.
realPrimoh Oct 2, 2020
6dd1e4d
Used createElementWithAttributes (optional nit)
realPrimoh Oct 7, 2020
51fd38e
Preact version of amp-instagram (first pass)
realPrimoh Sep 15, 2020
c0e3ece
added title logic from old extension
realPrimoh Sep 15, 2020
cd2c07a
ran prettier
realPrimoh Sep 15, 2020
4f87214
Made changes.
realPrimoh Sep 15, 2020
b262a9b
Deleted unnecessary CSS file
realPrimoh Sep 16, 2020
56ab186
Made changes based on suggestions. Updated build-system
realPrimoh Sep 16, 2020
d584be7
Addressed nits
realPrimoh Sep 16, 2020
e877cde
Made changes to title
realPrimoh Sep 17, 2020
abf0f77
cleared some build errors
realPrimoh Sep 17, 2020
f586687
addressed more travis errors
realPrimoh Sep 18, 2020
cfb3387
Should pass travis now.
realPrimoh Sep 18, 2020
8668d15
Added intermediate height variable.
realPrimoh Sep 18, 2020
9ff9897
Initialize heightStyle to prop.
realPrimoh Sep 18, 2020
5d9a744
initial test
realPrimoh Sep 18, 2020
6375fb7
Added some working Preact tests
realPrimoh Sep 21, 2020
d9616d1
Made non-test changes
realPrimoh Sep 22, 2020
dba078d
Updated tests
realPrimoh Sep 22, 2020
41b16e5
Preliminary resize function test.
realPrimoh Sep 22, 2020
9f782a6
Preact tests complete.
realPrimoh Sep 22, 2020
6a0db5a
Updated amp-instagram test (Trial)
realPrimoh Sep 22, 2020
d558cdc
Added test-amp-instagram tests
realPrimoh Sep 23, 2020
89a5e8e
fixed height jsc compiler error
realPrimoh Sep 23, 2020
d897e8f
Can't pass in resize prop for amp component
realPrimoh Sep 23, 2020
0d7a1ce
Removed shortcode error handling
realPrimoh Sep 23, 2020
deca0d3
Used dict() to bypass JSC compiler error w/ useState
realPrimoh Sep 23, 2020
1aeda51
Remove unnecessary requestResize
realPrimoh Sep 23, 2020
acb33d3
Removed style prop and added onLoad to iframe
realPrimoh Sep 23, 2020
4c6a5d3
addressed all comments except for testing changes
realPrimoh Sep 25, 2020
972c9b9
Modularized Preact component to make it easier to test
realPrimoh Sep 26, 2020
61f7a2d
Addressed comment.
realPrimoh Sep 28, 2020
a4659fd
Addressed new comments.
realPrimoh Sep 29, 2020
e7a5477
Draft PR: testing on travis
realPrimoh Oct 1, 2020
82c8009
Added waitForPromise to fix any race conditions
realPrimoh Oct 2, 2020
bd3f1af
Addressed comments
realPrimoh Oct 2, 2020
a6fdf0d
Some finishing touches to the tests.
realPrimoh Oct 2, 2020
c81cec5
Used createElementWithAttributes (optional nit)
realPrimoh Oct 7, 2020
86066e1
Merge branch 'bento-amp-instagram' of https://github.com/realPrimoh/a…
realPrimoh Oct 7, 2020
419c14d
Merge branch 'master' into bento-amp-instagram
realPrimoh Oct 7, 2020
bbd0944
Removed unnecessary isLayoutSupported
realPrimoh Oct 8, 2020
e13300d
Addressed comments
realPrimoh Oct 8, 2020
f8abef9
Addressed comments. Removed unnecessary attachments from tests.
realPrimoh Oct 13, 2020
2a2be97
re-pushing for travis build to re-run
realPrimoh Oct 29, 2020
209b085
Merge branch 'master' into bento-amp-instagram
realPrimoh Oct 29, 2020
5c35c67
re-pushing due to unrelated visual test error
realPrimoh Oct 29, 2020
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 build-system/compile/bundles.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ exports.extensionBundles = [
options: {hasCss: true},
type: TYPES.MISC,
},
{
name: 'amp-instagram',
version: '1.0',
latestVersion: '0.1',
type: TYPES.MISC,
},
{
name: 'amp-install-serviceworker',
version: '0.1',
Expand Down
2 changes: 1 addition & 1 deletion examples/instagram.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="canonical" href="amps.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
<script async custom-element="amp-instagram" src="https://cdn.ampproject.org/v0/amp-instagram-0.1.js"></script>
<script async custom-element="amp-instagram" src="https://cdn.ampproject.org/v0/amp-instagram-1.0.js"></script>
<style amp-custom>
body {
background-color: white;
Expand Down
55 changes: 55 additions & 0 deletions extensions/amp-instagram/1.0/amp-instagram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* 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 {isLayoutSizeDefined} from '../../../src/layout';

/** @const {string} */
const TAG = 'amp-instagram';

class AmpInstagram extends PreactBaseElement {
/** @override */
init() {
return {
resize: (height) => {
this.forceChangeHeight(height);
},
};
}

/** @override */
isLayoutSupported(layout) {
return isLayoutSizeDefined(layout);
}
}

/** @override */
AmpInstagram['Component'] = Instagram;

/** @override */
AmpInstagram['props'] = {
'shortcode': {attr: 'data-shortcode'},
'captioned': {attr: 'data-captioned'},
'alt': {attr: 'alt'},
};

/** @override */
AmpInstagram['layoutSizeDefined'] = true;

AMP.extension(TAG, '1.0', (AMP) => {
AMP.registerElement(TAG, AmpInstagram);
});
89 changes: 89 additions & 0 deletions extensions/amp-instagram/1.0/instagram.js
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 {useMountEffect} from '../../../src/preact/utils';
import {useRef, useState} from '../../../src/preact';

/**
* @param {!InstagramProps} props
* @return {PreactDef.Renderable}
*/
export function Instagram({shortcode, captioned, style, alt, resize}) {
const iframeRef = useRef(null);
const [heightStyle, setHeightStyle] = useState(null);
const [opacity, setOpacity] = useState(0);

/**
* Upon component mount, the Instagram post's height is received and applied.
*/
useMountEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you use resize inside, you can't use useMountEffect and instead you should use useEffect(() => {}, [resize]).

/**
* @param {Event} event
*/
function handleMessage(event) {
if (
event.origin != 'https://www.instagram.com' ||
event.source != iframeRef.current.contentWindow
) {
return;
}

const data = JSON.parse(getData(event));

if (data['type'] == 'MEASURE') {
if (typeof resize === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just if (resize) is enough.

resize(data['details']['height']);
} else {
setHeightStyle({'height': data['details']['height']});
}
setOpacity(1);
}
}

window.addEventListener('message', handleMessage);

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') +
'/embed/' +
(captioned ? 'captioned/' : '') +
'?cr=1&v=12'
}
scrolling="no"
frameborder="0"
allowtransparency
title={alt}
style={{
width: '100%',
height: '100%',
opacity,
}}
/>
</ContainWrapper>
);
}
28 changes: 28 additions & 0 deletions extensions/amp-instagram/1.0/instagram.type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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),
* alt: (string|undefined)
* resize: (function|undefined)
* }}
*/
var InstagramProps;
47 changes: 47 additions & 0 deletions extensions/amp-instagram/1.0/storybook/Basic.amp.js
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)
.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}
height={height}
layout={layout}
></amp-instagram>
);
});
42 changes: 42 additions & 0 deletions extensions/amp-instagram/1.0/storybook/Basic.js
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 (
<Instagram
shortcode={shortcode}
style={{width, height}}
captioned={captioned}
alt="AMP Instagram Storybook Preact Example"
></Instagram>
);
};