Comple client maps loading

This commit is contained in:
Paulo Gustavo Veiga 2021-02-03 20:34:24 -08:00
parent b10360fe6f
commit a6951b850e
4 changed files with 51 additions and 37 deletions

View File

@ -12,7 +12,7 @@ export type MapInfo = {
name: string;
labels: string[];
creator: string;
modified: number;
modified: string;
description: string;
isPublic: boolean;
}

View File

@ -14,25 +14,25 @@ class MockClient implements Client {
name: string,
labels: string[],
creator: string,
modified: number,
modified: string,
description: string,
isPublic: boolean
): MapInfo {
return { id, name, labels, creator, modified, starred, description, isPublic };
}
this.maps = [
createMapInfo(1, true, "El Mapa", [""], "Paulo", 67, "", true),
createMapInfo(2, false, "El Mapa2", [""], "Paulo2", 67, "", false),
createMapInfo(3, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(4, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(5, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(6, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(7, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(8, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(9, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(10, false, "El Mapa3", [""], "Paulo3", 67, "", false),
createMapInfo(11, false, "El Mapa3", ["label 3", "label3"], "Paulo3", 67, "", false),
createMapInfo(12, false, "El Mapa3", ["label 2"], "Paulo3", 67, "", false)
createMapInfo(1, true, "El Mapa", [""], "Paulo", "2008-06-02T00:00:00Z", "", true),
createMapInfo(2, false, "El Mapa2", [""], "Paulo2", "2008-06-02T00:00:00Z", "", false),
createMapInfo(3, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(4, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(5, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(6, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(7, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(8, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(9, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(10, false, "El Mapa3", [""], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(11, false, "El Mapa3", ["label 3", "label3"], "Paulo3", "2008-06-02T00:00:00Z", "", false),
createMapInfo(12, false, "El Mapa3", ["label 2"], "Paulo3", "2008-06-02T00:00:00Z", "", false)
];
this.labels = ["label 1,", "label 2", "label 3"];
@ -105,7 +105,7 @@ class MockClient implements Client {
starred: false,
creator: "current user",
labels: [],
modified: -1,
modified: "2008-06-02T00:00:00Z",
isPublic: false
};
this.maps.push(newMap);

View File

@ -13,27 +13,40 @@ export default class RestClient extends MockClient {
}
fetchAllMaps(): Promise<MapInfo[]> {
// https://app.wisemapping.com/c/restful/maps/
const handler = (success: (mapsInfo: MapInfo[]) => void, reject: (error: ErrorInfo) => void) => {
axios.get(
this.baseUrl + '/c/restful/maps/',
{ headers: { 'Content-Type': 'application/json' }
}
).then(response => {
console.log("Maps List Response=>")
console.log(response.data)
// const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
// axios.post(this.baseUrl + '/service/users/',
// JSON.stringify(user),
// { headers: { 'Content-Type': 'application/json' } }
// ).then(response => {
// // All was ok, let's sent to success page ...;
// success();
// }).catch(error => {
// const response = error.response;
// const errorInfo = parseResponseOnError(response);
// reject(errorInfo);
// });
// }
// return new Promise(handler);
// https://app.wisemapping.com/c/restful/maps/
const data = response.data;
const maps: MapInfo[] = (data.mindmapsInfo as any[]).map(m => {
return {
id: m.id,
starred: Boolean(m.starred),
name: m.title,
labels: [],
creator: m.creator,
modified: m.lastModificationTime,
description: m.description,
isPublic: false
}
})
success(maps);
}).catch(error => {
console.log("Maps List Error=>")
console.log(error)
// console.log("Fetching maps from server")
return Promise.resolve([]);
const response = error.response;
const errorInfo = parseResponseOnError(response);
reject(errorInfo);
});
}
return new Promise(handler);
}
registerNewUser(user: NewUser): Promise<void> {

View File

@ -13,7 +13,8 @@ const GlobalError = (props: GlobalErrorProps) => {
const hasError = Boolean(error?.msg);
const errorMsg = error?.msg;
return (hasError ? <StyledAlert severity="error" variant="filled" hidden={!hasError}> {errorMsg}</StyledAlert> : null);
return (hasError ?
<StyledAlert severity="error" variant="filled" hidden={!hasError}> {errorMsg}</StyledAlert> : null);
};