diff --git a/packages/webapp/src/client/index.ts b/packages/webapp/src/client/index.ts index 523b83c0..f8ac4dbe 100644 --- a/packages/webapp/src/client/index.ts +++ b/packages/webapp/src/client/index.ts @@ -49,17 +49,18 @@ export type ErrorInfo = { interface Client { createMap(map: BasicMapInfo): Promise; - registerNewUser(user: NewUser): Promise; - resetPassword(email: string): Promise; - fetchAllMaps(): Promise; deleteMap(id: number): Promise; renameMap(id: number, basicInfo: BasicMapInfo): Promise; + fetchAllMaps(): Promise; duplicateMap(id: number, basicInfo: BasicMapInfo): Promise; - loadMapInfo(id: number): Promise; + fetchMapInfo(id: number): Promise; changeStarred(id: number, starred: boolean): Promise; fetchLabels(): Promise; - deleteLabel(id: number): Promise; + deleteLabel(id: number): Promise; + + registerNewUser(user: NewUser): Promise; + resetPassword(email: string): Promise; } diff --git a/packages/webapp/src/client/mock-client/index.ts b/packages/webapp/src/client/mock-client/index.ts index c7706172..522793ea 100644 --- a/packages/webapp/src/client/mock-client/index.ts +++ b/packages/webapp/src/client/mock-client/index.ts @@ -36,7 +36,7 @@ class MockClient implements Client { this.labels = [ { id: 1, title: "Red Label", iconName: "", color: 'red' }, - { id: 1, title: "Blue Label", iconName: "", color: 'blue' } + { id: 2, title: "Blue Label", iconName: "", color: 'blue' } ]; } @@ -62,7 +62,7 @@ class MockClient implements Client { return Promise.resolve(); } - loadMapInfo(id: number): Promise { + fetchMapInfo(id: number): Promise { return Promise.resolve({ title: 'My Map', description: 'My Description' }); } diff --git a/packages/webapp/src/client/rest-client/index.ts b/packages/webapp/src/client/rest-client/index.ts index f4d9f551..a3f7f6ad 100644 --- a/packages/webapp/src/client/rest-client/index.ts +++ b/packages/webapp/src/client/rest-client/index.ts @@ -11,7 +11,7 @@ export default class RestClient extends MockClient { super(); this.baseUrl = baseUrl; } - + private parseResponseOnError = (response: any): ErrorInfo => { let result: ErrorInfo | undefined; @@ -184,7 +184,7 @@ export default class RestClient extends MockClient { changeStarred(id: number, starred: boolean): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`, - starred, + starred, { headers: { 'Content-Type': 'text/plain' } } ).then(() => { success(); @@ -197,6 +197,34 @@ export default class RestClient extends MockClient { return new Promise(handler); } + + fetchLabels(): Promise { + + const handler = (success: (labels: Label[]) => void, reject: (error: ErrorInfo) => void) => { + axios.get( + this.baseUrl + '/c/restful/labels/', + { + headers: { 'Content-Type': 'application/json' } + } + ).then(response => { + const data = response.data; + const maps: Label[] = (data.labels as any[]).map(l => { + return { + id: l.id, + color: l.color, + title: l.title, + iconName: l.iconName + } + }) + success(maps); + }).catch(error => { + const errorInfo = this.parseResponseOnError(error.response); + reject(errorInfo); + }); + } + return new Promise(handler); + } + deleteLabel(id: number): Promise { console.log("Fetching labels from server") return Promise.resolve();