Skip to content
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

Add guide "Create a Calendar Widget" #2687

Merged
merged 13 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docgen/src/data/communityHeader.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
"name": "Create new widgets",
"url": "guides/custom-widget.html"
},
{
"name": "Create a calendar widget",
"url": "guides/calendar-widget.html"
},
{
"name": "Migrate from V1",
"url": "guides/migration.html"
Expand Down
66 changes: 66 additions & 0 deletions docgen/src/examples/calendar-widget/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const ONE_DAY_IN_MS = 3600 * 24 * 1000;

const search = instantsearch({
appId: 'latency',
apiKey: '059c79ddd276568e990286944276464a',
indexName: 'concert_events_instantsearchjs',
});

search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box',
placeholder: 'Search events',
})
);

search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: hit => `
<li class="hit">
<h3>
${hit._highlightResult.name.value}
<small>in ${hit._highlightResult.location.value}</small>
</h3>
<small>on <strong>${moment(hit.date).format(
'dddd MMMM Do YYYY'
)}</strong></small>
</li>
`,
},
})
);

const makeRangeWidget = instantsearch.connectors.connectRange(
(options, isFirstRendering) => {
if (!isFirstRendering) return;

const { refine } = options;

new Calendar({
element: $('#calendar'),
same_day_range: true,
callback: function() {
const start = new Date(this.start_date).getTime();
const end = new Date(this.end_date).getTime();
const actualEnd = start === end ? end + ONE_DAY_IN_MS - 1 : end;

refine([start, actualEnd]);
},
// Some good parameters based on our dataset:
start_date: new Date(),
end_date: new Date('01/01/2020'),
earliest_date: new Date('01/01/2008'),
latest_date: new Date('01/01/2020'),
});
}
);

const dateRangeWidget = makeRangeWidget({
attributeName: 'date',
});

search.addWidget(dateRangeWidget);

search.start();
Loading