Implement load labels

This commit is contained in:
Paulo Gustavo Veiga 2021-02-04 19:08:08 -08:00
parent 9596852c90
commit 6115eeec26
3 changed files with 38 additions and 9 deletions

View File

@ -49,17 +49,18 @@ export type ErrorInfo = {
interface Client { interface Client {
createMap(map: BasicMapInfo): Promise<number>; createMap(map: BasicMapInfo): Promise<number>;
registerNewUser(user: NewUser): Promise<void>;
resetPassword(email: string): Promise<void>;
fetchAllMaps(): Promise<MapInfo[]>;
deleteMap(id: number): Promise<void>; deleteMap(id: number): Promise<void>;
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>; renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>;
fetchAllMaps(): Promise<MapInfo[]>;
duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number>; duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number>;
loadMapInfo(id: number): Promise<BasicMapInfo>; fetchMapInfo(id: number): Promise<BasicMapInfo>;
changeStarred(id: number, starred: boolean): Promise<void>; changeStarred(id: number, starred: boolean): Promise<void>;
fetchLabels(): Promise<Label[]>; fetchLabels(): Promise<Label[]>;
deleteLabel(id: number): Promise<void>; deleteLabel(id: number): Promise<void>;
registerNewUser(user: NewUser): Promise<void>;
resetPassword(email: string): Promise<void>;
} }

View File

@ -36,7 +36,7 @@ class MockClient implements Client {
this.labels = [ this.labels = [
{ id: 1, title: "Red Label", iconName: "", color: 'red' }, { 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(); return Promise.resolve();
} }
loadMapInfo(id: number): Promise<BasicMapInfo> { fetchMapInfo(id: number): Promise<BasicMapInfo> {
return Promise.resolve({ title: 'My Map', description: 'My Description' }); return Promise.resolve({ title: 'My Map', description: 'My Description' });
} }

View File

@ -184,7 +184,7 @@ export default class RestClient extends MockClient {
changeStarred(id: number, starred: boolean): Promise<void> { changeStarred(id: number, starred: boolean): Promise<void> {
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`, axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`,
starred, starred,
{ headers: { 'Content-Type': 'text/plain' } } { headers: { 'Content-Type': 'text/plain' } }
).then(() => { ).then(() => {
success(); success();
@ -197,6 +197,34 @@ export default class RestClient extends MockClient {
return new Promise(handler); return new Promise(handler);
} }
fetchLabels(): Promise<Label[]> {
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<void> { deleteLabel(id: number): Promise<void> {
console.log("Fetching labels from server") console.log("Fetching labels from server")
return Promise.resolve(); return Promise.resolve();