|
1 | | -// import { V2 } from "../openapi"; |
2 | | -// import { handleErrors } from "./common"; |
| 1 | +import {V2} from "../openapi"; |
| 2 | +import {handleErrors} from "./common"; |
3 | 3 |
|
4 | 4 | export const RECEIVE_PROJECTS = "RECEIVE_PROJECTS"; |
5 | 5 |
|
6 | 6 | export function fetchProjects(skip = 0, limit = 12) { |
7 | 7 | return (dispatch) => { |
8 | | - dispatch({ |
9 | | - type: RECEIVE_PROJECTS, |
10 | | - projects: { |
11 | | - metadata: { |
12 | | - total_count: 3, |
13 | | - skip: skip, |
14 | | - limit: limit, |
15 | | - }, |
16 | | - data: [ |
17 | | - { |
18 | | - id: "60f9f8c8c23f5c45d8f0e0e2", |
19 | | - name: "Sample Project", |
20 | | - description: "A description of the sample project", |
21 | | - created: "2024-07-29T12:00:00Z", |
22 | | - modified: "2024-07-29T12:00:00Z", |
23 | | - dataset_ids: [ |
24 | | - "669ea731d559628438e5785d", |
25 | | - "669ea746d559628438e5788f", |
26 | | - ], |
27 | | - folder_ids: ["66a085640c20e43f5c50b059"], |
28 | | - file_ids: ["669fcf4c78f3222201e18a0f"], |
29 | | - creator: { |
30 | | - id: "60f9f8c8c23f5c45d8f0e0c6", |
31 | | - first_name: "Chen", |
32 | | - last_name: "Wang", |
33 | | - |
34 | | - }, |
35 | | - }, |
36 | | - { |
37 | | - id: "60f9f8c8c23f5c45d8f0e0d1", |
38 | | - name: "Sample Project 2", |
39 | | - description: "A description of the second sample project", |
40 | | - created: "2024-07-28T12:00:00Z", |
41 | | - modified: "2024-07-28T12:00:00Z", |
42 | | - dataset_ids: ["669fcf3978f3222201e18a0d"], |
43 | | - folder_ids: [ |
44 | | - "66a085640c20e43f5c50b059", |
45 | | - "66a80284cf77abbb78b4435f", |
46 | | - ], |
47 | | - file_ids: ["669ea735d559628438e57865", "669ea733d559628438e57862"], |
48 | | - creator: { |
49 | | - id: "669ea726d559628438e57841", |
50 | | - first_name: "Chen", |
51 | | - last_name: "Wang", |
52 | | - |
53 | | - }, |
54 | | - }, |
55 | | - { |
56 | | - id: "60f9f8c8c23f5c45d8f0e0e2", |
57 | | - name: "Sample Project 3", |
58 | | - description: "A description of the third sample project", |
59 | | - created: "2024-07-27T12:00:00Z", |
60 | | - modified: "2024-07-27T12:00:00Z", |
61 | | - dataset_ids: [], |
62 | | - folder_ids: ["66a80284cf77abbb78b4435f"], |
63 | | - file_ids: [], |
64 | | - creator: { |
65 | | - id: "669ea726d559628438e57841", |
66 | | - first_name: "Chen", |
67 | | - last_name: "Wang", |
68 | | - |
69 | | - }, |
70 | | - }, |
71 | | - ], |
72 | | - }, |
73 | | - receivedAt: Date.now(), |
74 | | - }); |
| 8 | + return V2.ProjectsService.getProjectsApiV2ProjectsGet(skip, limit) |
| 9 | + .then((json) => { |
| 10 | + dispatch({ |
| 11 | + type: RECEIVE_PROJECTS, |
| 12 | + projects: json, |
| 13 | + receivedAt: Date.now(), |
| 14 | + }); |
| 15 | + }) |
| 16 | + .catch((reason) => { |
| 17 | + dispatch( |
| 18 | + handleErrors( |
| 19 | + reason, |
| 20 | + fetchProjects(skip, limit) |
| 21 | + ) |
| 22 | + ); |
| 23 | + }); |
75 | 24 | }; |
76 | 25 | } |
77 | 26 |
|
78 | 27 | export const RECEIVE_PROJECT = "RECEIVE_PROJECT"; |
79 | 28 |
|
80 | 29 | export function fetchProject(id) { |
81 | 30 | return (dispatch) => { |
82 | | - dispatch({ |
83 | | - type: RECEIVE_PROJECT, |
84 | | - project: { |
85 | | - id: id, |
86 | | - name: "Sample Project", |
87 | | - description: "A description of the sample project", |
88 | | - created: "2024-07-29T12:00:00Z", |
89 | | - modified: "2024-07-29T12:00:00Z", |
90 | | - dataset_ids: ["669ea731d559628438e5785d", "669ea746d559628438e5788f"], |
91 | | - folder_ids: ["66a085640c20e43f5c50b059"], |
92 | | - file_ids: ["669fcf4c78f3222201e18a0f"], |
93 | | - creator: { |
94 | | - id: "60f9f8c8c23f5c45d8f0e0c6", |
95 | | - first_name: "Chen", |
96 | | - last_name: "Wang", |
97 | | - |
98 | | - }, |
99 | | - }, |
100 | | - receivedAt: Date.now(), |
101 | | - }); |
| 31 | + return V2.ProjectsService.getProjectApiV2ProjectsProjectIdGet(id) |
| 32 | + .then((json) => { |
| 33 | + dispatch({ |
| 34 | + type: RECEIVE_PROJECT, |
| 35 | + project: json, |
| 36 | + receivedAt: Date.now(), |
| 37 | + }); |
| 38 | + }) |
| 39 | + .catch((reason) => { |
| 40 | + dispatch(handleErrors(reason, fetchProject(id))); |
| 41 | + }); |
102 | 42 | }; |
103 | 43 | } |
0 commit comments