1414 </VColumn >
1515 <VColumn :header =" $t('Email')" field =" email" />
1616 <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)" >
1920 <i class =" bi-eye" />
2021 </button >
2122 </template >
5253 </template >
5354 </VColumn >
5455 </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 >
5564</template >
5665
5766<script >
5867import CommentsFilterForm from ' @/components/comments/CommentsFilterForm.vue' ;
5968import VColumn from ' @/components/data-table/VColumn.vue' ;
6069import VTableServer from ' @/components/data-table/VTableServer.vue' ;
70+ import VModal from ' @/components/VModal.vue' ;
6171import { useFetchComments } from ' @/composables/comments.composable' ;
6272import { useApplyFilters } from ' @/composables/filter.composable' ;
63- import { computed } from ' vue' ;
73+ import useFetchPost from ' @/composables/posts.composable' ;
74+ import { computed , ref } from ' vue' ;
6475
6576export default {
6677 name: ' CommentsView' ,
6778 setup () {
6879 const { comments , commentsIsLoading , fetchComments } = useFetchComments ()
69-
7080 fetchComments ({})
7181
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+
7296 const filters = useApplyFilters ({
7397 searchQuery: undefined ,
7498 status: undefined ,
@@ -91,24 +115,29 @@ export default {
91115
92116 const highlightText = (text ) => {
93117 const query = filters? .searchQuery && isNaN (Number (filters .searchQuery )) ? filters .searchQuery .trim ().toLowerCase () : undefined ;
94-
118+
95119 if (! query) return text;
96120 const regex = new RegExp (` (${ query} )` , ' gi' );
97121 return String (text).replace (regex, ' <mark>$1</mark>' );
98122
99123 }
100-
124+
101125 return {
102126 comments: filteredComments,
103127 commentsIsLoading,
104128 filters,
105- highlightText
129+ highlightText,
130+ post,
131+ postIsLoading,
132+ handleFetchPost,
133+ postModalIsOpen
106134 }
107135 },
108136 components: {
109137 VTableServer,
110138 VColumn,
111- CommentsFilterForm
139+ CommentsFilterForm,
140+ VModal
112141 }
113142}
114143< / script>
0 commit comments