|
|
@@ -1,21 +1,30 @@
|
|
1
|
1
|
<template>
|
|
2
|
|
- <ion-card :router-link="'/tabs/mat_detail/'+obj.id">
|
|
3
|
|
- <ion-img alt="Silhouette of mountains" :src="thmb" v-if="thmb" class="img_16_9"/>
|
|
4
|
|
- <ion-card-header>
|
|
|
2
|
+ <ion-card >
|
|
|
3
|
+ <ion-img :router-link="'/tabs/mat_detail/'+obj.id" alt="Silhouette of mountains" :src="thmb" v-if="thmb" class="img_16_9"/>
|
|
|
4
|
+ <ion-card-header :router-link="'/tabs/mat_detail/'+obj.id">
|
|
5
|
5
|
<ion-card-title>{{ name }}</ion-card-title>
|
|
6
|
6
|
</ion-card-header>
|
|
7
|
7
|
|
|
8
|
|
- <ion-card-content class='ion-text-wrap'>
|
|
|
8
|
+ <ion-card-content class='ion-text-wrap ion-no-padding ion-padding-horizontal' :router-link="'/tabs/mat_detail/'+obj.id">
|
|
9
|
9
|
{{ dt }}
|
|
10
|
10
|
</ion-card-content>
|
|
|
11
|
+ <ion-button fill="clear" @click="likeMatClick"><ion-icon :icon="heart" :color="isLike ? 'danger' : 'medium' "></ion-icon>
|
|
|
12
|
+ <template v-if="obj.total_likes > 0">
|
|
|
13
|
+
|
|
|
14
|
+ {{ Humanize.compactInteger(obj.total_likes, 1) }} {{ pluralize('Like', obj.total_likes) }}
|
|
|
15
|
+ </template>
|
|
|
16
|
+ </ion-button>
|
|
11
|
17
|
</ion-card>
|
|
12
|
18
|
</template>
|
|
13
|
19
|
|
|
14
|
20
|
<script setup lang="ts">
|
|
15
|
|
- import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonIcon, onIonViewWillEnter, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonImg } from '@ionic/vue';
|
|
|
21
|
+ import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonIcon, onIonViewWillEnter, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonImg, IonButton } from '@ionic/vue';
|
|
16
|
22
|
import moment from 'moment'
|
|
17
|
|
-import { getTrainers, listCourses } from '@/composable/settings';
|
|
|
23
|
+ import { getTrainers, listCourses, isLogin, getPref, likeMat } from '@/composable/settings';
|
|
18
|
24
|
import { ref, onMounted } from 'vue'
|
|
|
25
|
+ import { heart } from 'ionicons/icons';
|
|
|
26
|
+ import pluralize from 'pluralize';
|
|
|
27
|
+ import Humanize from 'humanize-plus/dist/humanize';
|
|
19
|
28
|
|
|
20
|
29
|
const props = defineProps({
|
|
21
|
30
|
obj: Object,
|
|
|
@@ -25,11 +34,23 @@ import { getTrainers, listCourses } from '@/composable/settings';
|
|
25
|
34
|
const dt = ref()
|
|
26
|
35
|
const thmb = ref()
|
|
27
|
36
|
const name = ref()
|
|
28
|
|
-
|
|
29
|
|
- onMounted(() => {
|
|
|
37
|
+ let pref = null
|
|
|
38
|
+ const isLike = ref(false)
|
|
|
39
|
+ onMounted(async() => {
|
|
30
|
40
|
console.log("--- onmounted ---")
|
|
31
|
41
|
console.log("name === ", props.obj)
|
|
|
42
|
+
|
|
32
|
43
|
const obj = props.obj
|
|
|
44
|
+ if(await isLogin()) {
|
|
|
45
|
+ pref = await getPref()
|
|
|
46
|
+ console.debug(" pref = ", pref)
|
|
|
47
|
+ for(const m of pref.mat_likes) {
|
|
|
48
|
+ if(obj.id == m.id) {
|
|
|
49
|
+ isLike.value = true
|
|
|
50
|
+ break
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
|
33
|
54
|
let temp = obj.display_datetime || obj.vimeo_created || obj.created_at
|
|
34
|
55
|
dt.value = moment(temp).format('LLL');
|
|
35
|
56
|
|
|
|
@@ -45,7 +66,22 @@ import { getTrainers, listCourses } from '@/composable/settings';
|
|
45
|
66
|
}
|
|
46
|
67
|
name.value = obj.vimeo_name || props.courseName
|
|
47
|
68
|
})
|
|
48
|
|
-
|
|
|
69
|
+ const likeMatClick = async() => {
|
|
|
70
|
+ console.debug(props.obj)
|
|
|
71
|
+ pref = await likeMat(props.obj.id)
|
|
|
72
|
+ console.debug(pref)
|
|
|
73
|
+ isLike.value = false
|
|
|
74
|
+ for(const m of pref.mat_likes) {
|
|
|
75
|
+ if(props.obj.id == m.id) {
|
|
|
76
|
+ isLike.value = true
|
|
|
77
|
+ props.obj.total_likes += 1
|
|
|
78
|
+ break
|
|
|
79
|
+ }
|
|
|
80
|
+ }
|
|
|
81
|
+ if(isLike.value == false) {
|
|
|
82
|
+ props.obj.total_likes -= 1
|
|
|
83
|
+ }
|
|
|
84
|
+ }
|
|
49
|
85
|
</script>
|
|
50
|
86
|
|
|
51
|
87
|
<style scoped>
|