14
14
</VColumn >
15
15
<VColumn :header =" $t('Email')" field =" email" />
16
16
<VColumn :header =" $t('Post')" field =" postId" >
17
- <template #body >
18
- <button class =" btn btn-sm btn-outline-info" title =" View Related Post" >
17
+ <template #body =" { item } " >
18
+ <button class =" btn btn-sm btn-outline-info" title =" View Related Post"
19
+ @click =" handleFetchPost(item.postId)" >
19
20
<i class =" bi-eye" />
20
21
</button >
21
22
</template >
52
53
</template >
53
54
</VColumn >
54
55
</VTableServer >
56
+ <VModal v-model =" postModalIsOpen" >
57
+ <div v-if =" postIsLoading" >
58
+ Loading...
59
+ </div >
60
+ <h1 v-if =" !postIsLoading && post !== null" >
61
+ {{ post.title }}
62
+ </h1 >
63
+ </VModal >
55
64
</template >
56
65
57
66
<script >
58
67
import CommentsFilterForm from ' @/components/comments/CommentsFilterForm.vue' ;
59
68
import VColumn from ' @/components/data-table/VColumn.vue' ;
60
69
import VTableServer from ' @/components/data-table/VTableServer.vue' ;
70
+ import VModal from ' @/components/VModal.vue' ;
61
71
import { useFetchComments } from ' @/composables/comments.composable' ;
62
72
import { useApplyFilters } from ' @/composables/filter.composable' ;
63
- import { computed } from ' vue' ;
73
+ import useFetchPost from ' @/composables/posts.composable' ;
74
+ import { computed , ref } from ' vue' ;
64
75
65
76
export default {
66
77
name: ' CommentsView' ,
67
78
setup () {
68
79
const { comments , commentsIsLoading , fetchComments } = useFetchComments ()
69
-
70
80
fetchComments ({})
71
81
82
+ const { post , postIsLoading , fetchPost } = useFetchPost ()
83
+ const postModalIsOpen = ref (false )
84
+
85
+ const handleFetchPost = async (id ) => {
86
+ try {
87
+ postModalIsOpen .value = true
88
+ await fetchPost (id)
89
+ } catch {
90
+ postModalIsOpen .value = false
91
+ }
92
+
93
+
94
+ }
95
+
72
96
const filters = useApplyFilters ({
73
97
searchQuery: undefined ,
74
98
status: undefined ,
@@ -91,24 +115,29 @@ export default {
91
115
92
116
const highlightText = (text ) => {
93
117
const query = filters? .searchQuery && isNaN (Number (filters .searchQuery )) ? filters .searchQuery .trim ().toLowerCase () : undefined ;
94
-
118
+
95
119
if (! query) return text;
96
120
const regex = new RegExp (` (${ query} )` , ' gi' );
97
121
return String (text).replace (regex, ' <mark>$1</mark>' );
98
122
99
123
}
100
-
124
+
101
125
return {
102
126
comments: filteredComments,
103
127
commentsIsLoading,
104
128
filters,
105
- highlightText
129
+ highlightText,
130
+ post,
131
+ postIsLoading,
132
+ handleFetchPost,
133
+ postModalIsOpen
106
134
}
107
135
},
108
136
components: {
109
137
VTableServer,
110
138
VColumn,
111
- CommentsFilterForm
139
+ CommentsFilterForm,
140
+ VModal
112
141
}
113
142
}
114
143
< / script>
0 commit comments