This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
158 additions
and
28 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,30 +1,22 @@ | ||
'use strict'; | ||
|
||
var React = require('react'); | ||
var TmdbImageContainer = require('../../tmdb-image-container.js'); | ||
var TmdbImage = require('../../tmdb-image.js'); | ||
|
||
module.exports = React.createClass({ | ||
thumbUrl: function() { | ||
if (this.props.item.images.poster) { | ||
return this.props.item.images.poster.thumb; | ||
} else { | ||
return this.props.item.images.screenshot.thumb; | ||
} | ||
}, | ||
thumbStyle: function() { | ||
return { | ||
backgroundImage: 'url(' + this.thumbUrl() + ')' | ||
} | ||
}, | ||
render: function() { | ||
chrome.runtime.sendMessage({ type: 'sendAppView', view: 'Watching ' + this.props.item.title }); | ||
|
||
return( | ||
<div className='mdl-card mdl-shadow--2dp watching-card-thumb' style={this.thumbStyle()}> | ||
<div className='mdl-card__title mdl-card--expand'></div> | ||
<div className='mdl-card__actions'> | ||
<span className='watching-card-thumb__title'>{this.props.item.title}</span> | ||
</div> | ||
</div> | ||
<TmdbImageContainer> | ||
<TmdbImage className='mdl-card mdl-shadow--2dp watching-card-thumb' item={this.props.item}> | ||
<div className='mdl-card__title mdl-card--expand'></div> | ||
<div className='mdl-card__actions'> | ||
<span className='watching-card-thumb__title'>{this.props.item.title}</span> | ||
</div> | ||
</TmdbImage> | ||
</TmdbImageContainer> | ||
); | ||
} | ||
}); | ||
}); |
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,38 @@ | ||
'use strict'; | ||
|
||
var React = require('react'); | ||
var Settings = require('./settings.js'); | ||
|
||
module.exports = React.createClass({ | ||
getInitialState: function() { | ||
return { | ||
imageHost: null, | ||
imageWidth: { | ||
show: null, | ||
movie: null | ||
} | ||
} | ||
}, | ||
componentDidMount: function() { | ||
fetch('https://api.themoviedb.org/3/configuration?api_key=' + Settings.tmdbApiKey).then(this.parseJsonResponse).then(this.onConfigLoaded); | ||
}, | ||
parseJsonResponse: function(response) { | ||
return response.json(); | ||
}, | ||
onConfigLoaded: function(response) { | ||
this.setState({ | ||
imageHost: response.images.secure_base_url, | ||
imageWidth: { show: response.images.still_sizes[2], movie: response.images.poster_sizes[2] } | ||
}); | ||
}, | ||
render: function() { | ||
return( | ||
<div> | ||
{this.props.children && React.cloneElement(this.props.children, { | ||
imageHost: this.state.imageHost, | ||
imageWidth: this.state.imageWidth | ||
})} | ||
</div> | ||
); | ||
} | ||
}); |
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,79 @@ | ||
'use strict'; | ||
|
||
var React = require('react'); | ||
var Settings = require('./settings.js'); | ||
|
||
module.exports = React.createClass({ | ||
getInitialState: function() { | ||
return { | ||
imageUrl: 'https://trakt.tv/assets/placeholders/thumb/poster-2d5709c1b640929ca1ab60137044b152.png' | ||
} | ||
}, | ||
componentDidMount: function() { | ||
if (this.props.item && this.props.imageHost) { | ||
this.getItemFromTmdb(); | ||
} | ||
}, | ||
componentDidUpdate: function(prevProps) { | ||
var shouldUpdate = false; | ||
|
||
if (!prevProps.item && this.props.item) { | ||
shouldUpdate = true; | ||
} else if (prevProps.item && this.props.item) { | ||
if (prevProps.imageHost !== this.props.imageHost) { | ||
shouldUpdate = true; | ||
} else if (prevProps.item.ids.tmdb !== this.props.item.ids.tmdb) { | ||
shouldUpdate = true; | ||
} else if (prevProps.item.show && this.props.item.show && prevProps.item.show.ids.tmdb !== this.props.item.show.ids.tmdb) { | ||
shouldUpdate = true; | ||
} | ||
} | ||
|
||
if (shouldUpdate) { | ||
this.getItemFromTmdb(); | ||
} | ||
}, | ||
getItemFromTmdb: function() { | ||
fetch(this.getApiUrl()).then(this.parseJsonResponse).then(this.onItemLoaded); | ||
}, | ||
getApiUrl: function() { | ||
var type = this.props.item.type === 'show' ? 'tv' : 'movie'; | ||
var path = this.props.item.ids.tmdb; | ||
|
||
if (this.props.item.type === 'show') { | ||
path = this.props.item.show.ids.tmdb + '/season/' + this.props.item.season + '/episode/' + this.props.item.number; | ||
} | ||
|
||
return 'https://api.themoviedb.org/3/' + type + '/' + path + '/images?api_key=' + Settings.tmdbApiKey; | ||
}, | ||
parseJsonResponse: function(response) { | ||
return response.json(); | ||
}, | ||
onItemLoaded: function(response) { | ||
clearTimeout(this.requestTimeout); | ||
|
||
if (response.status_code && response.status_code === 25) { | ||
// we've reached the API limit | ||
this.onItemFailed(); | ||
} else { | ||
var imageKey = this.props.item.type === 'show' ? 'stills' : 'posters'; | ||
this.setState({ imageUrl: this.props.imageHost + this.props.imageWidth[this.props.item.type] + response[imageKey][0].file_path }); | ||
} | ||
}, | ||
onItemFailed: function() { | ||
this.requestTimeout = setTimeout(this.getItemFromTmdb, 10000); | ||
}, | ||
thumbStyle: function() { | ||
return { | ||
backgroundImage: 'url(' + this.state.imageUrl + ')', | ||
backgroundSize: 'cover' | ||
} | ||
}, | ||
render: function() { | ||
return( | ||
<div className={this.props.className} style={this.thumbStyle()}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
}); |
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