Skip to content
Permalink
Browse files

Add option to add items to history with release date (#109)

  • Loading branch information...
rafaelgssa committed Jul 24, 2019
1 parent 5ac74b1 commit 088390288976b63f061f51a1adbf04ff2ddd4fec
@@ -62,6 +62,9 @@
"selectAll": {
"message": "Select all"
},
"addWithReleaseDate": {
"message": "Add with release date"
},
"syncNow": {
"message": "Sync now"
},
@@ -62,6 +62,9 @@
"selectAll": {
"message": "Selecionar todos"
},
"addWithReleaseDate": {
"message": "Adicionar com a data de lançamento"
},
"syncNow": {
"message": "Sincronizar agora"
},
@@ -16,12 +16,12 @@ export default class TraktWebAPIUtils {
}
}

static addActivities(activities) {
static addActivities(activities, addWithReleaseDate) {
// noinspection JSIgnoredPromiseFromCall
Request.send({
method: `POST`,
url: URL,
params: TraktWebAPIUtils.activitiesPayload(activities),
params: TraktWebAPIUtils.activitiesPayload(activities, addWithReleaseDate),
success: function (response) {
const json = JSON.parse(response);
/** @property json.added */
@@ -33,21 +33,21 @@ export default class TraktWebAPIUtils {
});
}

static activitiesPayload(activities) {
static activitiesPayload(activities, addWithReleaseDate) {
const activitiesToAdd = activities.filter(activity => activity.add);
const movies = activitiesToAdd
.filter(activity => activity.trakt && activity.trakt.type === `movie`)
.map(TraktWebAPIUtils.activityPayload.bind(TraktWebAPIUtils));
.map(activity => TraktWebAPIUtils.activityPayload(activity, addWithReleaseDate));
const episodes = activitiesToAdd
.filter(activity => activity.trakt && activity.trakt.type === `show`)
.map(TraktWebAPIUtils.activityPayload.bind(TraktWebAPIUtils));
.map(activity => TraktWebAPIUtils.activityPayload(activity, addWithReleaseDate));

return {movies: movies, episodes: episodes};
}

static activityPayload(activity) {
static activityPayload(activity, addWithReleaseDate) {
return {
watched_at: activity.netflix.date,
watched_at: addWithReleaseDate ? `released` : activity.netflix.date,
ids: {
trakt: activity.trakt.ids.trakt
}
@@ -12,7 +12,10 @@ import TraktWebAPIUtils from './TraktWebAPIUtils';

export default class ViewingActivityApp extends React.Component {
getInitialState() {
return Object.assign(this.getStateFromStores(), { pagesToLoad: this.props.pagesToLoad });
return Object.assign(this.getStateFromStores(), {
addWithReleaseDate: this.props.addWithReleaseDate,
pagesToLoad: this.props.pagesToLoad
});
}

getStateFromStores() {
@@ -53,7 +56,7 @@ export default class ViewingActivityApp extends React.Component {
const confirmationMessage = browser.i18n.getMessage(`confirmSync`);
if (confirm(confirmationMessage)) {
this.setState({loading: true});
TraktWebAPIUtils.addActivities(this.state.activities);
TraktWebAPIUtils.addActivities(this.state.activities, this.state.addWithReleaseDate);
}
}

@@ -82,6 +85,18 @@ export default class ViewingActivityApp extends React.Component {
inputs.map(input => input.checked === event.target.checked ? null : input.click());
}

__onToggleReleaseDate(event) {
const addWithReleaseDate = event.target.checked;
BrowserStorage.get(`prefs`).then(storage => {
if (!storage.prefs) {
storage.prefs = {};
}
storage.prefs.addWithReleaseDate = addWithReleaseDate;
BrowserStorage.set({prefs: storage.prefs}, true);
});
this.setState({addWithReleaseDate});
}

showSnackbar() {
const snackbar = document.querySelector('.mdl-js-snackbar');
snackbar.MaterialSnackbar.showSnackbar({message: this.state.message});
@@ -109,6 +124,11 @@ export default class ViewingActivityApp extends React.Component {
onChange={this._onToggleAll.bind(this)}/>
<span className='mdl-switch__label'>{browser.i18n.getMessage(`selectAll`)}</span>
</label>
<label className='mdl-switch mdl-js-switch mdl-js-ripple-effect' htmlFor='add-with-release-date'>
<input type='checkbox' id='add-with-release-date' className='mdl-switch__input'
onChange={this.__onToggleReleaseDate.bind(this)} checked={this.state.addWithReleaseDate}/>
<span className='mdl-switch__label'>{browser.i18n.getMessage(`addWithReleaseDate`)}</span>
</label>
</span>
<TmdbImageContainer>
<ActivityList activities={this.state.activities}/>
@@ -10,6 +10,6 @@ import ViewingActivityApp from '../../class/history-sync/ViewingActivityApp';
Rollbar.init();
BrowserStorage.get(`prefs`).then(storage => {
NetflixApiUtils.getActivities();
ReactDOM.render(<ViewingActivityApp pagesToLoad={(storage.prefs && storage.prefs.pagesToLoad) || `0`}/>, document.getElementById('viewing-activity-app'));
ReactDOM.render(<ViewingActivityApp addWithReleaseDate={(storage.prefs && storage.prefs.addWithReleaseDate) || false} pagesToLoad={(storage.prefs && storage.prefs.pagesToLoad) || `0`}/>, document.getElementById('viewing-activity-app'));
document.getElementById(`viewing-activity-app-title`).textContent = browser.i18n.getMessage(`historyTitle`);
});

0 comments on commit 0883902

Please sign in to comment.
You can’t perform that action at this time.