How to use the kitsu/config/api.Kitsu.destroy function in kitsu

To help you get started, we’ve selected a few kitsu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hummingbird-me / kitsu-mobile / src / screens / Feed / components / Post / component.js View on Github external
toggleLike = async () => {
    try {
      const { currentUser } = this.props;
      let { like, isLiked, post, postLikesCount } = this.state;

      // Optimistically update our UI
      this.setState({
        isLiked: !isLiked,
        postLikesCount: isLiked ? postLikesCount - 1 : postLikesCount + 1,
      });

      if (like) {
        await Kitsu.destroy('postLikes', like.id);
        FeedCache.deleteLike(post.id);
        this.setState({ like: null });
      } else {
        like = await Kitsu.create('postLikes', {
          post: {
            id: post.id,
            type: 'posts',
          },
          user: {
            id: currentUser.id,
            type: 'users',
          },
        });
        FeedCache.setLike(post.id, like);
        this.setState({ like });
      }
github hummingbird-me / kitsu-mobile / src / screens / Profiles / ProfilePages / index.js View on Github external
handleFollowing = async () => {
    const { userId } = this.props;
    const isCurrentUser = isIdForCurrentUser(userId, this.props.currentUser);
    if (isCurrentUser) { // Edit
      this.setState({ editModalVisible: true });
    } else if (this.state.follow) { // Destroy
      this.setState({ isLoadingFollow: true });
      await Kitsu.destroy('follows', this.state.follow.id);
      this.setState({ follow: null, isLoadingFollow: false });
    } else { // Create
      await this.createFollow(userId);
    }
  }
github hummingbird-me / kitsu-mobile / src / screens / Profiles / components / ReactionBox / component.js View on Github external
async handleVote() {
    const { reaction, currentUser } = this.props;
    const { vote, upVotesCount, hasVoted } = this.state;
    try {
      if (hasVoted) {
        this.setState({ upVotesCount: upVotesCount - 1, hasVoted: false });
        await Kitsu.destroy('mediaReactionVotes', vote.id);
        this.setState({ vote: null });
      } else {
        this.setState({ upVotesCount: upVotesCount + 1, hasVoted: true });
        const vote = await Kitsu.create('mediaReactionVotes', {
          mediaReaction: {
            id: reaction.id
          },
          user: {
            id: currentUser.id
          }
        });
        this.setState({ vote });
      }
    } catch (error) {
      console.log('Error handling reaction vote:', error);
      this.setState({ upVotesCount, hasVoted });
github hummingbird-me / kitsu-mobile / src / screens / Feed / components / Post / component.js View on Github external
deletePost = async () => {
    try {
      const { post } = this.state;
      this.setState({ isDeleted: true });
      await Kitsu.destroy('posts', post.id);
    } catch (err) {
      console.log('Error deleting post:', err);
      this.setState({ isDeleted: false });
      Alert.alert('Sorry', 'There was an issue deleting the post.', [
        { text: 'OK', onPress: null },
      ]);
    }
  };
github hummingbird-me / kitsu-mobile / src / screens / Profiles / MediaPages / index.js View on Github external
onMainButtonOptionsSelected = async (option) => {
    const { libraryEntry } = this.state;
    const { mediaType } = this.props;
    switch (option) {
      case 'current':
      case 'planned':
      case 'completed':
      case 'on_hold':
      case 'dropped': {
        const data = { status: option };
        libraryEntry ? await this.updateLibraryEntry(data) : await this.createLibraryEntry(data);
        break;
      }
      case 'remove':
        this.setState({ loadingLibrary: true });
        await Kitsu.destroy('libraryEntries', libraryEntry.id);
        KitsuLibrary.onLibraryEntryDelete(libraryEntry.id, mediaType, libraryEntry.status, KitsuLibraryEventSource.MEDIA_PAGE);
        this.setState({ libraryEntry: null, loadingLibrary: false });
        break;
      default:
        console.log('unhandled option selected:', option);
        break;
    }
  }
github hummingbird-me / kitsu-mobile / src / screens / Feed / components / Comment / component.js View on Github external
toggleLike = async () => {
    try {
      const { likesCount, isLiked, like } = this.state;
      const { comment, currentUser } = this.props;

      this.setState({
        isLiked: !isLiked,
        likesCount: isLiked ? likesCount - 1 : likesCount + 1,
      });

      if (like) {
        await Kitsu.destroy('commentLikes', like.id);
        this.setState({ like: null });
      } else {
        const record = await Kitsu.create('commentLikes', {
          comment: {
            id: comment.id,
            type: 'comments',
          },
          user: {
            id: currentUser.id,
            type: 'users',
          },
        });
        this.setState({ like: record });
      }
    } catch (err) {
      console.log('Error toggling like: ', err);
github hummingbird-me / kitsu-mobile / src / store / profile / actions.js View on Github external
export const deleteUserLibraryEntry = (id, libraryType, libraryStatus) => async (dispatch, getState) => {
  const { currentUser } = getState().user;
  if (!currentUser || !currentUser.id) return;

  try {
    await Kitsu.destroy('libraryEntries', id);
    dispatch(onLibraryEntryDelete(id, currentUser.id, libraryType, libraryStatus));
    KitsuLibrary.onLibraryEntryDelete(id, libraryType, libraryStatus, KitsuLibraryEventSource.STORE);
  } catch (e) {
    throw e;
  }
};
github hummingbird-me / kitsu-mobile / src / screens / Sidebar / Library / ExportLibrary.js View on Github external
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,
      });
    }
  }
github hummingbird-me / kitsu-mobile / src / screens / Profiles / MediaPages / index.js View on Github external
case 'add': {
        const record = await Kitsu.create('favorites', {
          item: {
            id: mediaId,
            type: mediaType,
          },
          user: {
            id: currentUser.id,
            type: 'users',
          },
        });
        this.setState({ favorite: record });
        break;
      }
      case 'remove':
        await Kitsu.destroy('favorites', this.state.favorite.id);
        this.setState({ favorite: null });
        break;
      case 'share': {
        const id = (media && media.slug) || mediaId;
        if (isNull(id) || isNull(mediaType)) return;
        const url = `${kitsuConfig.kitsuUrl}/${mediaType}/${id}`;
        const key = Platform.select({ ios: 'url', android: 'message' });
        Share.share({ [key]: url });
        break;
      }
      case 'cover': {
        if (!media || !media.coverImage) return;
        const coverURL = media.coverImage.original ||
          media.coverImage.large ||
          media.coverImage.medium ||
          media.coverImage.small ||