Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onImportButtonPressed = async () => {
const { accessToken, currentUser, navigation } = this.props;
const item = navigation.state.params.item;
setToken(accessToken);
const kind = item.title === 'MyAnimeList' ? 'my-anime-list' : 'anilist';
this.setState({ loading: true });
try {
const res = await Kitsu.create('listImports', {
user: { id: currentUser.id },
inputText: this.state.username,
strategy: 'greater',
kind,
});
this.setState({
showModal: true,
loading: false,
errMessage: res.errorMessage,
});
} catch (e) {
// TODO: we may have crashes here.
removeRating = async () => {
const { currentIndex, topMedia } = this.state;
const { accessToken, userId, type } = this.props;
const id = topMedia[currentIndex].id;
const libraryEntryId = topMedia[currentIndex].libraryEntryId;
setToken(accessToken);
let updatedTopMedia = topMedia.slice();
updatedTopMedia[currentIndex].isRating = true;
this.setState({
topMedia: updatedTopMedia,
});
try {
let response = null;
// patch the previous rating
response = await Kitsu.update('libraryEntries', {
ratingTwenty: null,
id: libraryEntryId,
[type]: {
id,
type,
getCannySsoKey = async () => {
const { accessToken, currentUser } = this.props;
setToken(accessToken);
this.setState({ loading: true });
try {
// execute request. > will continue later after fixing pr review stuff.
} catch (e) {
// catch.
}
};
onImportButtonPressed = async () => {
const { accessToken, currentUser, item } = this.props;
setToken(accessToken);
const kind = item.title === 'MyAnimeList' ? 'my-anime-list' : 'anilist';
this.setState({ loading: true, errMessage: null });
try {
const res = await Kitsu.create('listImports', {
user: { id: currentUser.id },
inputText: this.state.username,
strategy: 'greater',
kind,
});
this.setState({
showModal: true,
loading: false,
errMessage: res.errorMessage,
});
} catch (e) {
// TODO: we may have crashes here.
onFaveCategory = async (id, index) => {
const { id: userId } = this.props.currentUser;
if (id) {
setToken(this.props.accessToken);
try {
const res = await Kitsu.create('categoryFavorites', {
category: {
id,
},
user: {
id: userId,
},
});
const categories = this.props.favoriteCategories.slice();
categories[index].favoritesId = res.id;
return categories;
} catch (e) {
console.log(e);
}
} else {
export const disconnectFBUser = () => async (dispatch, getState) => {
dispatch({ type: types.DISCONNECT_FBUSER });
const token = getState().auth.tokens.access_token;
const currentUser = getState().user.currentUser;
setToken(token);
try {
await Kitsu.update('users', { id: currentUser.id, facebookId: null });
dispatch({ type: types.DISCONNECT_FBUSER_SUCCESS });
LoginManager.logOut();
} catch (e) {
dispatch({ type: types.DISCONNECT_FBUSER_FAIL, payload: 'Failed to disconnect fb user' });
console.log(e);
}
};
onSavePrivacySettings = async () => {
const { shareToGlobal } = this.state;
const { accessToken, currentUser } = this.props;
setToken(accessToken);
this.setState({ loading: true });
try {
await Kitsu.update('users', { id: currentUser.id, shareToGlobal });
this.setState({
shareToGlobal,
loading: false,
});
} catch (e) {
this.setState({
error: 'Failed to set privacy settings',
loading: false,
});
}
};
export const completeOnboarding = () => async (dispatch, getState) => {
dispatch({ type: types.COMPLETE_ONBOARDING });
const { user, auth } = getState();
const { id } = user.currentUser;
const token = auth.tokens.access_token;
setToken(token);
try {
await Kitsu.update('users', { id, status: 'registered' });
dispatch({ type: types.COMPLETE_ONBOARDING_SUCCESS });
NavigationActions.showMainApp();
} catch (e) {
dispatch({ type: types.COMPLETE_ONBOARDING_FAIL, payload: e });
}
};
onUnblockUser = async (user) => {
const { blocks } = this.state;
const { id } = user;
setToken(this.props.accessToken);
this.setState({ loading: true });
try {
await Kitsu.destroy('blocks', id);
this.setState({
blocks: blocks.filter(v => v.id !== id),
loading: false,
});
} catch (e) {
this.onError(e);
}
};
onDisconnectButtonPressed = async () => {
const { accessToken } = this.props;
const { linkedAccount } = this.state;
setToken(accessToken);
this.setState({ loading: true });
try {
await Kitsu.destroy('linkedAccounts', linkedAccount.id);
this.setState({
hasAccount: false,
loading: false,
});
} catch (e) {
this.setState({
error: e,
loading: false,
});
}
}