Skip to content
Snippets Groups Projects
RentHistoryView.vue 1.78 KiB
Newer Older
Gilgard's avatar
Gilgard committed
<template>
  <!-- A view for showing rating and rent history -->
Gilgard's avatar
Gilgard committed
  <rating-modal
    :visible="modal.show"
    :name="modal.name"
    :title="modal.title"
    :rentID="modal.rentID"
    :renterIsReceiverOfRating="modal.renterIsReceiverOfRating"
    @close="modal.show = false"
    @reload="this.$forceUpdate()"
  />
Gilgard's avatar
Gilgard committed
  <ul>
    <li v-for="historyItem in fullHistory" :key="historyItem.rentId">
Gilgard's avatar
Gilgard committed
      <rent-history-item
        :historyItem="historyItem"
        @rate="(modal) => openModal(modal)"
      />
Gilgard's avatar
Gilgard committed
    </li>
  </ul>
</template>

<script>
import RentHistoryItem from "@/components/UserProfileComponents/RentHistoryComponents/RentHistoryItem.vue";
Gilgard's avatar
Gilgard committed
import RatingModal from "@/components/UserProfileComponents/RatingComponents/RatingModal.vue";
import UserService from "@/services/user.service";
Gilgard's avatar
Gilgard committed

export default {
  components: {
    RentHistoryItem,
Gilgard's avatar
Gilgard committed
    RatingModal,
Gilgard's avatar
Gilgard committed
  },
  data() {
    return {
      renterHistory: [],
      ownerHistory: [],
Gilgard's avatar
Gilgard committed
      modal: {
        show: false,
        name: "",
        title: "",
        rentID: -1,
        renterIsReceiverOfRating: false,
      },
    };
Gilgard's avatar
Gilgard committed
  },
  computed: {
    fullHistory() {
      function compareHistoryItems(itemA, itemB) {
Titus Netland's avatar
Titus Netland committed
        if (itemA.fromTime > itemB.fromTime) {
Gilgard's avatar
Gilgard committed
          return -1;
        }
Titus Netland's avatar
Titus Netland committed
        if (itemA.fromTime < itemB.fromTime) {
Gilgard's avatar
Gilgard committed
          return 1;
        }
        return 0;
      }

      let fullHistory = this.renterHistory.concat(this.ownerHistory);
      fullHistory.filter((item) => item.isAccepted);
      fullHistory.sort(compareHistoryItems);
      return fullHistory;
    },
  },
  methods: {
Gilgard's avatar
Gilgard committed
    openModal(modal) {
      this.modal = modal;
    },
Gilgard's avatar
Gilgard committed
  },
Gilgard's avatar
Gilgard committed
  async beforeCreate() {
    this.renterHistory = await UserService.getRenterHistory();
    this.ownerHistory = await UserService.getOwnerHistory();
Gilgard's avatar
Gilgard committed
  },
};
</script>