1
1
<template >
2
- <div class =" h3 mb-4" >{{ $t(' Comments' ) }}</div >
2
+ <div class =" h3 mb-4" >{{ $t(" Comments" ) }}</div >
3
3
<CommentsFilterForm class =" mb-4" v-model =" filters" />
4
4
<VTableServer :items =" comments" :itemsLength =" comments.length" :is-loading =" commentsIsLoading" >
5
5
<VColumn :header =" $t('Id')" field =" id" >
29
29
<VColumn :header =" $t('Status')" field =" id" >
30
30
<template #body =" { item } " >
31
31
<span v-if =" item.status === 'PENDING'" >
32
- {{ $t(' Pending' ) }}
32
+ {{ $t(" Pending" ) }}
33
33
</span >
34
34
<span v-if =" item.status === 'CONFIRMED'" >
35
- {{ $t(' Confirmed' ) }}
35
+ {{ $t(" Confirmed" ) }}
36
36
</span >
37
37
<span v-if =" item.status === 'REJECTED'" >
38
- {{ $(' Rejected' ) }}
38
+ {{ $(" Rejected" ) }}
39
39
</span >
40
40
</template >
41
41
</VColumn >
54
54
</VColumn >
55
55
</VTableServer >
56
56
<VModal v-model =" postModalIsOpen" >
57
- <div v-if =" postIsLoading" >
58
- Loading...
59
- </div >
57
+ <div v-if =" postIsLoading" >Loading...</div >
60
58
<h1 v-if =" !postIsLoading && post !== null" >
61
59
{{ post.title }}
62
60
</h1 >
63
61
</VModal >
64
62
</template >
65
63
66
64
<script >
67
- import CommentsFilterForm from ' @/components/comments/CommentsFilterForm.vue' ;
68
- import VColumn from ' @/components/data-table/VColumn.vue' ;
69
- import VTableServer from ' @/components/data-table/VTableServer.vue' ;
70
- import VModal from ' @/components/VModal.vue' ;
71
- import { useFetchComments } from ' @/composables/comments.composable' ;
72
- import { useApplyFilters } from ' @/composables/filter.composable' ;
73
- import useFetchPost from ' @/composables/posts.composable' ;
74
- import { computed , ref } from ' vue' ;
65
+ import CommentsFilterForm from " @/components/comments/CommentsFilterForm.vue" ;
66
+ import VColumn from " @/components/data-table/VColumn.vue" ;
67
+ import VTableServer from " @/components/data-table/VTableServer.vue" ;
68
+ import VModal from " @/components/VModal.vue" ;
69
+ import { useFetchComments } from " @/composables/comments.composable" ;
70
+ import { useApplyFilters } from " @/composables/filter.composable" ;
71
+ import useFetchPost from " @/composables/posts.composable" ;
72
+ import StorageService from " @/services/storage.service" ;
73
+ import { computed , ref , watch } from " vue" ;
75
74
76
75
export default {
77
- name: ' CommentsView' ,
76
+ name: " CommentsView" ,
78
77
setup () {
79
- const { comments , commentsIsLoading , fetchComments } = useFetchComments ()
80
- fetchComments ({})
81
-
82
- const { post , postIsLoading , fetchPost } = useFetchPost ()
83
- const postModalIsOpen = ref (false )
78
+ const { comments , commentsIsLoading , fetchComments } = useFetchComments ();
79
+ fetchComments ({});
84
80
81
+ const { post , postIsLoading , fetchPost } = useFetchPost ();
82
+ const postModalIsOpen = ref (false );
85
83
const handleFetchPost = async (id ) => {
86
84
try {
87
- postModalIsOpen .value = true
88
- await fetchPost (id)
85
+ postModalIsOpen .value = true ;
86
+ await fetchPost (id);
89
87
} catch {
90
- postModalIsOpen .value = false
88
+ postModalIsOpen .value = false ;
91
89
}
90
+ };
92
91
93
-
94
- }
92
+ const syncedFilters = StorageService .get (" synced-filters" );
95
93
96
94
const filters = useApplyFilters ({
97
- searchQuery: undefined ,
98
- status: undefined ,
99
- email: undefined
95
+ searchQuery: syncedFilters? .searchQuery || undefined ,
96
+ status: syncedFilters? .status || undefined ,
97
+ email: syncedFilters? .email || undefined ,
98
+ });
99
+
100
+ watch (filters, (newFilters ) => {
101
+ StorageService .set (' synced-filters' ,{... filters,... newFilters})
102
+ }, { immediate: true })
103
+
104
+ StorageService .observe (" synced-filters" , (newValue ) => {
105
+ filters .searchQuery = newValue? .searchQuery || undefined ;
106
+ filters .email = newValue? .email || undefined ;
107
+ filters .status = newValue? .status || undefined
100
108
});
101
109
102
110
const filteredComments = computed (() => {
103
111
const enteredEmail = filters? .email && filters .email .trim ().toLowerCase ();
104
- const query = filters? .searchQuery && isNaN (Number (filters .searchQuery )) ? filters .searchQuery .trim ().toLowerCase () : filters .searchQuery ;
112
+ const query =
113
+ filters? .searchQuery && isNaN (Number (filters .searchQuery )) ? filters .searchQuery .trim ().toLowerCase () : filters .searchQuery ;
105
114
const status = filters? .status && filters .status .trim ();
106
115
107
- const matchesEmail = (email ) => enteredEmail && email .trim ().toLowerCase ().includes (enteredEmail)
108
- const matchesQuery = (id , body , name ) => id === Number (query) || body .trim ().toLowerCase ().includes (query) || name .trim ().toLowerCase ().includes (query)
116
+ const matchesEmail = (email ) => enteredEmail && email .trim ().toLowerCase ().includes (enteredEmail);
117
+ const matchesQuery = (id , body , name ) =>
118
+ id === Number (query) || body .trim ().toLowerCase ().includes (query) || name .trim ().toLowerCase ().includes (query);
109
119
110
- return comments .value ? .filter (comment => {
120
+ return comments .value ? .filter (( comment ) => {
111
121
if (! query && ! enteredEmail && ! status) return true ;
112
122
return matchesEmail (comment .email ) || matchesQuery (comment .id , comment .body , comment .name ) || status === comment .status ;
113
123
});
@@ -117,10 +127,9 @@ export default {
117
127
const query = filters? .searchQuery && isNaN (Number (filters .searchQuery )) ? filters .searchQuery .trim ().toLowerCase () : undefined ;
118
128
119
129
if (! query) return text;
120
- const regex = new RegExp (` (${ query} )` , ' gi' );
121
- return String (text).replace (regex, ' <mark>$1</mark>' );
122
-
123
- }
130
+ const regex = new RegExp (` (${ query} )` , " gi" );
131
+ return String (text).replace (regex, " <mark>$1</mark>" );
132
+ };
124
133
125
134
return {
126
135
comments: filteredComments,
@@ -130,14 +139,14 @@ export default {
130
139
post,
131
140
postIsLoading,
132
141
handleFetchPost,
133
- postModalIsOpen
134
- }
142
+ postModalIsOpen,
143
+ };
135
144
},
136
145
components: {
137
146
VTableServer,
138
147
VColumn,
139
148
CommentsFilterForm,
140
- VModal
141
- }
142
- }
149
+ VModal,
150
+ },
151
+ };
143
152
< / script>
0 commit comments