<commit_before><template>
  <v-ons-dialog cancelable
    :visible="dialogVisible"
    @prehide="closeDialog"
  >
    <v-ons-list>
      <v-ons-list-item
        tappable
        @click="moveTweetInput"
      >
        <v-ons-icon icon="ion-reply" class="icon"></v-ons-icon>
        Reply
      </v-ons-list-item>
      <v-ons-list-item
        v-if="me.screen_name === screenName"
        tappable
        @click="deleteOwnTweet"
      >
        <v-ons-icon icon="ion-ios-trash" class="icon"></v-ons-icon>
        Delete tweet
      </v-ons-list-item>
      <v-ons-list-item
        tappable
        @click="favorited ? $twitter.destroyFavorite(idStr) : $twitter.createFavorite(idStr)"
      >
        <v-ons-icon icon="ion-heart" class="icon"></v-ons-icon>
        {{ favoritePrefix }} favorite
      </v-ons-list-item>
    </v-ons-list>
  </v-ons-dialog>
</template>

<script>
  import { mapState, mapActions } from 'vuex'

  export default {
    name: 'item-dialog',
    computed: {
      favoritePrefix: function () {
        return this.favorited ? 'Remove' : 'Add'
      },
      ...mapState({
        dialogVisible: state => state.app.tweetItemDialogVisible,
        favorited: state => state.app.favorited,
        idStr: state => state.app.idStr,
        screenName: state => state.app.screenName,
        me: state => state.twitter.me
      })
    },
    methods: {
      closeDialog: function (event) {
        this.closeTweetItemDialog()
        this.removeSelectedItem()
      },
      moveTweetInput: function () {
        this.changeActiveIndex(0)
        this.closeTweetItemDialog()
      },
      deleteOwnTweet: function () {
        this.$ons.notification.confirm({
          message: 'Are you sure?',
          callback: (answer) => {
            if (answer) {
              this.$twitter.deleteTweet(this.idStr)
                .then((res) => {
                  this.deleteTweet(this.idStr)
                  this.closeTweetItemDialog()
                })
                .catch(() => {
                  this.$ons.notification.alert('Delete failed...')
                })
            } else {
              this.closeTweetItemDialog()
            }
          }
        })
      },
      ...mapActions([
        'changeActiveIndex',
        'closeTweetItemDialog',
        'removeSelectedItem',
        'deleteTweet'
      ])
    }
  }
</script>

<style scoped>
  .icon {
    margin-right: 5px;
  }
</style><commit_msg>Add favorite actions<commit_after><template>
  <v-ons-dialog cancelable
    :visible="dialogVisible"
    @prehide="closeDialog"
  >
    <v-ons-list>
      <v-ons-list-item
        tappable
        @click="moveTweetInput"
      >
        <v-ons-icon icon="ion-reply" class="icon"></v-ons-icon>
        Reply
      </v-ons-list-item>
      <v-ons-list-item
        v-if="me.screen_name === screenName"
        tappable
        @click="deleteOwnTweet"
      >
        <v-ons-icon icon="ion-ios-trash" class="icon"></v-ons-icon>
        Delete tweet
      </v-ons-list-item>
      <v-ons-list-item
        tappable
        @click="actionFavorite"
      >
        <v-ons-icon icon="ion-heart" class="icon"></v-ons-icon>
        {{ favoritePrefix }} favorite
      </v-ons-list-item>
    </v-ons-list>
  </v-ons-dialog>
</template>

<script>
  import { mapState, mapActions } from 'vuex'

  export default {
    name: 'item-dialog',
    computed: {
      favoritePrefix: function () {
        return this.favorited ? 'Remove' : 'Add'
      },
      ...mapState({
        dialogVisible: state => state.app.tweetItemDialogVisible,
        favorited: state => state.app.favorited,
        idStr: state => state.app.idStr,
        screenName: state => state.app.screenName,
        me: state => state.twitter.me
      })
    },
    methods: {
      closeDialog: function (event) {
        this.closeTweetItemDialog()
        this.removeSelectedItem()
      },
      moveTweetInput: function () {
        this.changeActiveIndex(0)
        this.closeTweetItemDialog()
      },
      deleteOwnTweet: function () {
        this.$ons.notification.confirm({
          message: 'Are you sure?',
          callback: (answer) => {
            if (answer) {
              this.$twitter.deleteTweet(this.idStr)
                .then((res) => {
                  this.deleteTweet(this.idStr)
                  this.closeTweetItemDialog()
                })
                .catch(() => {
                  this.$ons.notification.alert('Delete failed...')
                })
            } else {
              this.closeTweetItemDialog()
            }
          }
        })
      },
      actionFavorite: function () {
        const result = this.favorited ? this.$twitter.destroyFavorite(this.idStr) : this.$twitter.createFavorite(this.idStr)
        result
          .then(() => {
            this.$ons.notification.toast(this.favoritePrefix + ' favorite', {timeout: 2000})
            this.closeTweetItemDialog()
          })
          .catch(() => {
            this.$ons.notification.alert(this.favoritePrefix + ' favorite failed...')
          })
      },
      ...mapActions([
        'changeActiveIndex',
        'closeTweetItemDialog',
        'removeSelectedItem',
        'deleteTweet'
      ])
    }
  }
</script>

<style scoped>
  .icon {
    margin-right: 5px;
  }
</style>
{'fraction_non_alphanumeric': 0.1443648699585375, 'fraction_numerical': 0.0015077271013946476, 'mean_word_length': 1.7299382716049383, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6800726', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1625, 'n_words': 245}