Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion app/components/list-books.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
<div class="alert alert-warning mx-auto" role="alert" data-test="no-books">
There are no books to be displayed. Try looking on {{#link-to "books" class="alert-link"}}homepage{{/link-to}} for more awesome books!
</div>
{{/each}}
{{/each}}

{{#if @model }}
<InfinityLoader @infinityModel={{ @model }}>
<img src="spinner.gif" title="spinner" />
</InfinityLoader>
{{/if}}
13 changes: 8 additions & 5 deletions app/routes/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import ENV from 'bigriver-bookstore/config/environment'

export default class BooksRoute extends Route {
@service store;
@service infinity;

model() {
return this.store.query('book', {
page: {
size: ENV.BOOKS_PER_PAGE
},
include: 'author,photos'
return this.infinity.model('book', {
include: 'author,photos',
perPage: ENV.BOOKS_PER_PAGE,
startingPage: 1,
perPageParam: 'page[size]',
pageParam: 'page[number]',
countParam: 'meta.total_resources'
});
}
}
13 changes: 8 additions & 5 deletions app/routes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ENV from 'bigriver-bookstore/config/environment'

export default class SearchRoute extends Route {
@service store;
@service infinity;

queryParams = {
query: {
Expand All @@ -14,14 +15,16 @@ export default class SearchRoute extends Route {
model(params) {
const query = params.query ? params.query : '';

return this.store.query('book', {
page: {
size: ENV.BOOKS_PER_PAGE,
},
return this.infinity.model('book', {
filter: {
'author.name': query
},
include: 'author,photos'
include: 'author,photos',
perPage: ENV.BOOKS_PER_PAGE,
startingPage: 1,
perPageParam: 'page[size]',
pageParam: 'page[number]',
countParam: 'meta.total_resources'
});
Comment on lines -17 to 28

Choose a reason for hiding this comment

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

This looks very similar with a query made in the books, maybe we can find a way to remove duplication.

}
}
15 changes: 14 additions & 1 deletion app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ h1 {
bottom: 0;
left: 0;
background-color: #ccc;
background-image: url('http://placehold.it/400x300?text=Loading Image');
background-image: url('/loading-img.png');
background-repeat: no-repeat;
background-size: 100%;
}
Expand All @@ -39,4 +39,17 @@ h1 {

footer .badge {
font-size: 0.9rem;
}

.infinity-loader {
margin-right: auto;
margin-left: auto;
}

.infinity-loader img {
width: 100px;
}

.infinity-loader.reached-infinity img {
display: none;
}
122 changes: 122 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ember-cli-uglify": "^3.0.0",
"ember-data": "~3.14.0",
"ember-export-application-global": "^2.0.0",
"ember-infinity": "^2.1.1",
"ember-load-initializers": "^2.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-qunit": "^4.4.1",
Expand Down
Binary file added public/loading-img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion tests/acceptance/books-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { visit, currentURL, waitUntil } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import page from 'bigriver-bookstore/tests/pages/books';

Expand All @@ -25,4 +25,18 @@ module('Acceptance | books', function(hooks) {
assert.ok(page.books(0).hasAuthor);
assert.ok(page.books(0).hasImage);
});

test('fetch more data when scrolled down', async function(assert) {
await page.visit();

assert.equal(page.books().count, 9);

document.querySelector(page.loaderClass).scrollIntoView();

await waitUntil(() => {
return page.books().count === 18;
});

assert.equal(page.books().count, 18);
});
Comment on lines +28 to +41
Copy link
Member

Choose a reason for hiding this comment

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

The tests seem to use the actual api, meaning that they will hit the api every time the test runs.

Can you think of why this might not be a good idea in real live app and what are some alternatives?

});
1 change: 1 addition & 0 deletions tests/pages/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export default create({
searchDisabledPresent: isPresent('[data-test="search-btn"]:disabled'),
fillInSearchInput: fillable('input', { scope: '[data-test="search-by-author-form"]' }),
fancyPlaceholder: isPresent('[data-test="fancy-placeholder"]'),
loaderClass: '.infinity-loader',
});