From 95b4f107b43d8017f8f43a53e6fb96c062a0b599 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 29 Jul 2019 18:14:21 +0200 Subject: [PATCH] Removed dependency on Apollo and Teams Module --- Dashboard.js | 120 ++------------------------------------------------- 1 file changed, 4 insertions(+), 116 deletions(-) diff --git a/Dashboard.js b/Dashboard.js index ccf9635d3..4811d2b5a 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -49,13 +49,12 @@ function newDashboard () { userProfileChangedEventSubscriptionId = window.canvasApp.eventHandler.listenToEvent('User Profile Changed', userProfileChanged) browserResizedEventSubscriptionId = window.canvasApp.eventHandler.listenToEvent('Browser Resized', browserResized) - loadImages(onImagesLoaded) + /* Here we used to have a call to the Teams Module to get the profile pictures. That was removed but to keep things working, we do this: */ - function onImagesLoaded () { - /* Next we start the App */ + window.canvasApp.context.teamProfileImages = new Map() + window.canvasApp.context.fbProfileImages = new Map() - setTimeout(delayedStart, DEBUG_START_UP_DELAY) - } + setTimeout(delayedStart, DEBUG_START_UP_DELAY) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } } @@ -102,115 +101,4 @@ function newDashboard () { if (ERROR_LOG === true) { logger.write('[ERROR] browserResized -> err = ' + err.stack) } } } - - function loadImages (callBack) { - try { - const accessToken = '' - // Soon, we will need to get images from the Financial Beings Module. - - const networkInterfaceTeams = Apollo.lib.createNetworkInterface({ - uri: window.canvasApp.graphQL.masterAppApiUrl - }) - - networkInterfaceTeams.use([{ - applyMiddleware (req, next) { - req.options.headers = { - authorization: `Bearer ${accessToken}` - } - next() - } - }]) - - const apolloClientTeams = new Apollo.lib.ApolloClient({ - networkInterface: networkInterfaceTeams, - connectToDevTools: true - }) - - const ALL_TEAMS_QUERY = Apollo.gql` - { - teams_Teams{ - edges{ - node{ - id - name - slug - profile { - avatar - banner - description - motto - updatedAt - } - fb { - id - name - slug - avatar - kind - status { - status - reason - createdAt - } - } - } - } - } - } - ` - - let teams - - const getTeams = () => { - return new Promise((resolve, reject) => { - apolloClientTeams.query({ - query: ALL_TEAMS_QUERY - }) - .then(response => { - teams = response.data.teams_Teams - // window.localStorage.setItem('Teams', JSON.stringify(response.data.teams_Teams)) - resolve({ teams: response.data.teams_Teams }) - }) - .catch(err => { - if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> getTeams -> Error fetching data from Teams Module.') } - if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> getTeams -> err = ' + err.stack) } - reject(err) - }) - }) - } - - // To avoid race conditions, add asynchronous fetches to array - let fetchDataPromises = [] - - fetchDataPromises.push(/* getUser(), */ getTeams()) // <-- Here we must add the function calll to the Financial Beings module. - - // When all asynchronous fetches resolve, authenticate user or throw error. - Promise.all(fetchDataPromises).then(result => { - /* All good, we will go through the results creating a map with all the Images URLs */ - - let teamProfileImages = new Map() - let fbProfileImages = new Map() - - for (let i = 0; i < teams.edges.length; i++) { - let team = teams.edges[i].node - - teamProfileImages.set(team.slug, team.profile.avatar) - - if (team.fb.length > 0) { - fbProfileImages.set(team.slug + '-' + team.fb[0].slug, team.fb[0].avatar) - } - } - - window.canvasApp.context.teamProfileImages = teamProfileImages - window.canvasApp.context.fbProfileImages = fbProfileImages - - callBack() - }, err => { - if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> Error fetching data from Teams Module.') } - if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> err = ' + err.stack) } - }) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> err = ' + err.stack) } - } - } }