diff --git a/.gitignore b/.gitignore index 05b46a0..d751314 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ dev/ config.json *.sqlite* *.db -.dbversion \ No newline at end of file +.dbversion +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 12e1d88..d5b0b4c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ An attempt at a viable alternative to Goodreads - Features we feel are essential to the project. Anything beyond the scope should be discussed for later and not prioritized. - [Dependencies Stack](https://gitlab.com/Alamantus/Readlebee/wikis/Dependencies-Stack) - A list of dependencies used in the project and a short explanation of what each of them are for. -- [Contrubution Guidelines](./CONTRIBUTING.md) +- [Contribution Guidelines](./CONTRIBUTING.md) - Subject to change but important to follow. Includes a basic code of conduct. - [Project chat via Gitter](https://gitter.io/Readlebee) - Real-time discussion about the project. diff --git a/app/views/search/controller.js b/app/views/search/controller.js index 247f040..1277301 100644 --- a/app/views/search/controller.js +++ b/app/views/search/controller.js @@ -1,4 +1,5 @@ import { ViewController } from '../controller'; +import { ShelvesController } from '../shelves/controller'; export class SearchController extends ViewController { constructor(state, emit, i18n) { @@ -13,6 +14,7 @@ export class SearchController extends ViewController { done: true, results: [], openModal: null, + showShelves: false, }); this.emit = emit; @@ -44,6 +46,19 @@ export class SearchController extends ViewController { return this.state.openModal; } + get hasFetchedShelves() { + return typeof this.appState.viewStates.shelves !== 'undefined' + && typeof this.appState.viewStates.shelves.myShelves !== 'undefined' + && this.appState.viewStates.shelves.myShelves.length > 0; + } + + get shelves() { + if (this.hasFetchedShelves) { + return this.appState.viewStates.shelves.myShelves; + } + return []; + } + set openModal(modalId) { this.state.openModal = modalId; } @@ -85,4 +100,29 @@ export class SearchController extends ViewController { return Promise.resolve(); } + + showShelves () { + const shelfController = new ShelvesController(this.appState, this.i18n); + let shelvesPromise; + if (shelfController.state.myShelves.length < 1) { + console.log('getting'); + shelvesPromise = shelfController.getUserShelves(); + } else { + shelvesPromise = Promise.resolve(); + } + shelvesPromise.then(() => { + console.log(shelfController.state.myShelves); + this.showShelves = true; + this.emit('render'); + }); + } + + addToShelf(bookData, shelfId) { + const shelfController = new ShelvesController(this.appState, this.i18n); + shelfController.addItemToShelf(bookData, shelfId).then(result => { + console.log(result); + this.showShelves = false; + this.emit('render'); + }); + } } \ No newline at end of file diff --git a/app/views/search/index.js b/app/views/search/index.js index b1dfe83..dc539ca 100644 --- a/app/views/search/index.js +++ b/app/views/search/index.js @@ -16,7 +16,6 @@ export const searchView = (state, emit, i18n) => { } // Returning an array in a view allows non-shared parent HTML elements. - // This one doesn't have the problem right now, but it's good to remember. return [ html`

${__('search.header')}

`, @@ -45,7 +44,7 @@ export const searchView = (state, emit, i18n) => { // Search Options Section html`
-
+ ${/*
${modal('searchSourceInfo', controller, [ html`

${__('search.search_source.help.text')} @@ -91,7 +90,8 @@ export const searchView = (state, emit, i18n) => { -

+
*/'' // Temporarily comment out the source chooser so I can focus on just Inventaire + }
${__('search.search_by.label')}
diff --git a/app/views/search/resultDetails.js b/app/views/search/resultDetails.js index 82ac38b..099344d 100644 --- a/app/views/search/resultDetails.js +++ b/app/views/search/resultDetails.js @@ -8,21 +8,28 @@ export const resultDetails = (searchController, result, emit = () => {}) => { const { __ } = searchController.i18n; const modalId = `result_${result.uri}`; + const hasReviews = typeof result.averageRating !== 'undefined' && typeof result.numberOfReviews !== 'undefined'; + const buttonHTML = html``; const tabNames = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']; const modalContent = html`
-

Covers

+

${__('search.covers')}

${typeof result.covers === 'undefined' ? html`` : html`
@@ -55,33 +62,41 @@ export const resultDetails = (searchController, result, emit = () => {}) => { }
-

${__('interaction.average_rating')}

- ${starRating(result.averageRating)} + ${!hasReviews + ? html`

${__('search.no_reviews')}

` + : html`

${__('interaction.average_rating')}

+ ${starRating(result.averageRating)} -
- - ${result.reviews.map(review => { - return reviewCard(searchController, review); - })} + ${(typeof result.reviews !== 'undefined' && Array.isArray(result.reviews) ? result.reviews : []).map(review => { + return reviewCard(searchController, review); + })}` + }

- - - +

+ ${!searchController.showShelves ? null : html`
    ${searchController.shelves.map(shelf => { + return html`
  • + +
  • `; + })}
`}

${__('search.see_book_details')} diff --git a/app/views/shelves/controller.js b/app/views/shelves/controller.js index 153f3ea..9c66d1a 100644 --- a/app/views/shelves/controller.js +++ b/app/views/shelves/controller.js @@ -42,4 +42,37 @@ export class ShelvesController extends ViewController { this.state.loadedShelves[this.targetShelf] = shelf; }); } + + async addItemToShelf (book, shelfId) { + let bookId; + if (typeof book.source !== 'undefined' && typeof book.uri !== 'undefined') { + const bookSearchResult = await fetch('/api/books/getId', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(book), + }).then(response => response.json()); + + if (typeof bookSearchResult.error !== 'undefined') { + console.error(bookSearchResult); + return bookSearchResult; + } + + bookId = bookSearchResult; + } else { + bookId = book.id; + } + + return fetch('/api/shelf/addItem', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + shelfId, + bookId, + }), + }) + } } \ No newline at end of file diff --git a/app/views/shelves/shelf.js b/app/views/shelves/shelf.js index 053571b..c2f7e16 100644 --- a/app/views/shelves/shelf.js +++ b/app/views/shelves/shelf.js @@ -71,7 +71,7 @@ export const shelfView = (shelvesController, emit) => { ${__('shelves.owned_by')} ${shelf.user === null ? __('shelves.you') - : `${shelf.user.name}`} + : html`${shelf.user.name}`}

@@ -87,9 +87,7 @@ export const shelfView = (shelvesController, emit) => { return html`