Skip to content

Conversation

bramanudom
Copy link
Contributor

#20083
Clicking on an element with this action should bring the user to another page within the same story.

Note that there will be a follow-up PR to handle changes to navigation, per UX requirement . Currently, after jumping to a new non-adjacent page, navigating to the previous page does not bring you back to the page you jumped from.

Copy link
Contributor

@newmuis newmuis left a comment

Choose a reason for hiding this comment

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

Wow, this was fast! 😄

this.registerAction('goToPage', invocation => {
const {args} = invocation;
if (args) {
this.switchTo_(args['targetPageId']);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe just id?

Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

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

Nice, LGTM. I'll defer approval to the amp-story reviewers

win.document,
'button',
{'id': 'actionButton',
'on': 'tap:cover.goToPage(id=page-2)'});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question about how publishers will have to use this: it'll have to be tap:${pageId}.goToPage(...)?
Is there a way to make it so they don't have to know the current pageId to write the action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is correct! Unfortunately, because we want this to be an amp action, based on the actions and events documentation, the targetId is required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't the ID be the ID of the button?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be feasible as a future change to implement the action on the <amp-story> element to avoid needing to reference the specific page?

Copy link
Contributor Author

@bramanudom bramanudom Jan 2, 2019

Choose a reason for hiding this comment

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

@newmuis I believe that the targetId should be the dom element that we'd like to execute an action on. The go to action really just switches the page that is currently active which is handled by the amp-story-page element (and then at the amp-story level). I think the action needs to be bound to a page element. Just to be sure, I did a quick test and it doesn't seem to work with the id of the button.

@cvializ I think that would be possible, since the switching method is handled both in the story and page level. Though, I'm not sure how we feel about the fact that this would require giving the amp-story element an id (would users typically do this?), whereas a pageId is always required to make a story.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops, makes sense. One data point here is that amp-carousel has a similar API ("go to slide") which uses the carousel ID. I think semantically the story ID may make more sense ("the story should go to page 5" rather than "page 1 should go to page 5")

.addAdvanceListener(() => this.next(/* opt_isAutomaticAdvance */ true));
this.advancement_
.addProgressListener(progress => this.emitProgress_(progress));
this.registerAction('goToPage', invocation => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized: we can't keep this from going live with validation, because the on="..." syntax is always valid. Maybe we should add an experiment to keep this from launching before we're ready?

See #19699 as an example of setting up an experiment.

@gmajoulet
Copy link
Contributor

You'll need to enable the experiment in your unit test now, and potentially set it back to false?
toggleExperiment(win, 'amp-story-branching', true);

@gmajoulet gmajoulet merged commit 2896b45 into ampproject:master Jan 7, 2019
@cvializ
Copy link
Contributor

cvializ commented Jan 7, 2019

🎉

noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* added the go to page action

* added tests

* fixed tests

* changed action argument name

* go to action should be bound to the story and not the page

* enable amp-story-branching experiment

* oops, commas to separate arguments is a good thing

* fixed tests

* re-add removed line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants