File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { computed , ref } from "vue" ;
2
+ import { useLoading } from "./loading.composable" ;
3
+ import { keyBy } from "@/utils" ;
4
+ import CommentsService from "@/services/comments.service" ;
5
+
6
+ export const useFetchComments = ( ) => {
7
+ const { isLoading, startLoading, endLoading } = useLoading ( ) ;
8
+ const comments = ref ( [ ] ) ;
9
+ const commentsKeyById = computed ( ( ) => keyBy ( comments . value , "id" ) ) ;
10
+
11
+ /**
12
+ * @param {AxiosRequestConfig } [config]
13
+ */
14
+ const fetchComments = ( config ) => {
15
+ startLoading ( ) ;
16
+ return CommentsService . getAll ( config )
17
+ . then ( ( response ) => {
18
+ comments . value = response . data ;
19
+ return response ;
20
+ } )
21
+ . finally ( ( ) => {
22
+ endLoading ( ) ;
23
+ } ) ;
24
+ } ;
25
+
26
+ return {
27
+ comments,
28
+ commentsIsLoading : isLoading ,
29
+ commentsKeyById,
30
+ fetchComments,
31
+ } ;
32
+ } ;
Original file line number Diff line number Diff line change
1
+ import CrudService from "./crud.service" ;
2
+
3
+ class CommentsService extends CrudService {
4
+ /**
5
+ * Service url
6
+ *
7
+ * @returns {String }
8
+ */
9
+ static get URL ( ) {
10
+ return "comments" ;
11
+ }
12
+
13
+ /**
14
+ * Get default item
15
+ *
16
+ * @returns {Object }
17
+ */
18
+ static getDefault ( ) {
19
+ return {
20
+ postId : undefined ,
21
+ id : undefined ,
22
+ name : undefined ,
23
+ body : undefined ,
24
+ email : undefined ,
25
+ } ;
26
+ }
27
+ }
28
+
29
+ export default CommentsService ;
You can’t perform that action at this time.
0 commit comments