Skip to content

Commit b1fb402

Browse files
authored
feat(InfiniteStoryBase): a new property disableSetUrl, when set to true will not execute setUrl (#102)
* introduce a property disableSetUrl, when set to true will not execute maybesetUrl * change option name to doNotChangeUrl * update Readme * add a minor formatting to readme comment
1 parent acc77a3 commit b1fb402

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,18 @@ function StoryPage(props) {
227227

228228
exports.StoryPage = StoryPage;
229229
```
230-
230+
#### doNotChangeUrl
231+
When the next story is focussed on, the url and title of the page will be set to the next story loaded by the Infinite Story Base. If this is not required, it can be disabled by setting the prop doNotChangeUrl={true}.
232+
A valid use case for this: If the after the story, we are showing the snapshots of the next few stories, not the actual stories we dont want to change the url to the current story shown in the snapshot.
233+
While disabling the url updating, Please make sure that GA is not being fired for the next story if doNotChangeUrl is set to true.
234+
An Example:
235+
```javascript
236+
<InfiniteStoryBase {...props}
237+
render={StoryPageBase}
238+
loadItems={storyPageLoadItems}
239+
onItemFocus={(item) => console.log(`Story In View: ${item.story.headline}`)}
240+
doNotChangeUrl={true} />
241+
```
231242
### LazyCollection
232243

233244
This component can be used to render a collection, but with the components being lazy. This takes all the same options as Collection, but with a `lazyAfter` prop.

src/components/infinite-story-base.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export class InfiniteStoryBase extends React.Component {
2020

2121
onFocus(index) {
2222
const item = this.allItems()[index];
23-
global.app.maybeSetUrl("/" + item.story.slug, get(item, ['story', 'seo', 'meta-title'], item.story.headline));
23+
24+
if(!this.props.doNotChangeUrl) {
25+
global.app.maybeSetUrl("/" + item.story.slug, get(item, ['story', 'seo', 'meta-title'], item.story.headline));
26+
}
2427

2528
this.props.onItemFocus && this.props.onItemFocus(item, index);
2629

0 commit comments

Comments
 (0)