You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB

2 years ago
  1. <template>
  2. <div class="tw-cursor-pointer like">
  3. <div v-if="childLiked" @click="removeServiceRelation">
  4. <img
  5. class="tw-w-[20px] tw-h-[18px] md:tw-w-[33px] md:tw-h-[30px]"
  6. src="~/assets/svg/newHeart.svg"
  7. alt=""
  8. />
  9. </div>
  10. <div v-else @click="buildServiceRelation">
  11. <img
  12. class="tw-w-[20px] tw-h-[18px] md:tw-w-[33px] md:tw-h-[30px]"
  13. src="~/assets/svg/newHeartOutline.svg"
  14. alt=""
  15. />
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. like: {
  23. type: Boolean,
  24. default: false,
  25. },
  26. serviceId: {
  27. type: String,
  28. default: "",
  29. },
  30. isForUserprofile: {
  31. type: Boolean,
  32. default: false,
  33. },
  34. },
  35. data() {
  36. return {
  37. childLiked: false,
  38. };
  39. },
  40. methods: {
  41. removeServiceRelation() {
  42. if (this.$auth.loggedIn) {
  43. this.$axios
  44. .delete(
  45. `member/services/${this.serviceId}?jwt=${
  46. this.$auth.$storage.getUniversal("jwt").token
  47. }`
  48. )
  49. .then((result) => {
  50. this.$emit("remove-relation");
  51. this.$nextTick(() => {
  52. this.childLiked = false;
  53. });
  54. })
  55. .catch((err) => {
  56. console.log(err);
  57. });
  58. } else {
  59. this.$router.push(this.localePath("/user"));
  60. }
  61. },
  62. buildServiceRelation() {
  63. if (this.$auth.loggedIn) {
  64. this.$axios
  65. .patch(
  66. `member/services/${this.serviceId}?jwt=${
  67. this.$auth.$storage.getUniversal("jwt").token
  68. }`
  69. )
  70. .then((result) => {
  71. this.childLiked = true;
  72. })
  73. .catch((err) => {
  74. console.log(err);
  75. });
  76. } else {
  77. this.$router.push(this.localePath("/user"));
  78. }
  79. },
  80. },
  81. mounted() {
  82. this.like ? (this.childLiked = true) : (this.childLiked = false);
  83. },
  84. updated() {
  85. this.isForUserprofile ? (this.childLiked = true) : this.childLiked;
  86. },
  87. };
  88. </script>
  89. <style lang="scss" scoped></style>