-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from TriPSs/improvements
Improvements
- Loading branch information
Showing
29 changed files
with
495 additions
and
122 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import DefaultBookmarkAdapter from 'popcorn-sdk/BookmarkAdapter' | ||
|
||
import Bookmarks from '../db/Bookmarks' | ||
|
||
export default new (class BookmarkAdapter extends DefaultBookmarkAdapter { | ||
|
||
getAll = Bookmarks.getAll | ||
|
||
checkMovie = movie => new Promise(async(resolve) => { | ||
const bookmarks = await Bookmarks.getAllMovies() | ||
|
||
resolve({ | ||
...movie, | ||
bookmarked: bookmarks.filter(bookmark => bookmark.id === movie.id).length === 1, | ||
}) | ||
}) | ||
|
||
checkShow = show => new Promise(async(resolve) => { | ||
const bookmarks = await Bookmarks.getAllShows() | ||
|
||
resolve({ | ||
...show, | ||
bookmarked: bookmarks.filter(bookmark => bookmark.id === show.id).length === 1, | ||
}) | ||
}) | ||
|
||
addItem = Bookmarks.addItem | ||
|
||
removeItem = Bookmarks.removeItem | ||
|
||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './BookmarkAdapter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Popcorn from 'popcorn-sdk' | ||
|
||
import BookmarkAdapter from './BookmarkAdapter' | ||
|
||
const SDK = Popcorn | ||
SDK.setBookmarkAdapter(BookmarkAdapter) | ||
|
||
export default SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Constants } from 'popcorn-sdk' | ||
import Base from './Base' | ||
|
||
export default new (class BookmarksDB extends Base { | ||
|
||
KEY_BOOKMARKS = '@Popcorn:Bookmarks' | ||
|
||
bookmarks = [] | ||
|
||
getAll = async() => { | ||
if (this.bookmarks.length > 0) { | ||
return this.bookmarks | ||
} | ||
|
||
const bookmarks = await this.getItem(this.KEY_BOOKMARKS) | ||
|
||
if (bookmarks) { | ||
this.bookmarks = JSON.parse(bookmarks) | ||
console.log('this.bookmarks', this.bookmarks) | ||
return this.bookmarks | ||
} | ||
|
||
return this.bookmarks | ||
} | ||
|
||
getAllMovies = async() => { | ||
await this.getAll() | ||
|
||
return this.bookmarks.filter(bookmark => bookmark.type === Constants.TYPE_MOVIE) | ||
} | ||
|
||
getAllShows = async() => { | ||
await this.getAll() | ||
|
||
return this.bookmarks.filter(bookmark => bookmark.type === Constants.TYPE_SHOW) | ||
} | ||
|
||
addItem = ({ id, title, type, images }) => { | ||
this.bookmarks.push({ | ||
id, | ||
title, | ||
type, | ||
images, | ||
}) | ||
|
||
this.setItem(this.KEY_BOOKMARKS, JSON.stringify(this.bookmarks)) | ||
} | ||
|
||
removeItem = ({ id }) => { | ||
this.bookmarks = this.bookmarks.filter(bookmark => bookmark.id !== id) | ||
|
||
this.setItem(this.KEY_BOOKMARKS, JSON.stringify(this.bookmarks)) | ||
} | ||
|
||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.