Created
July 28, 2016 00:00
-
-
Save mvanlonden/b93bb5d083bb348b0aec59fba583778e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function moveModuleIntoBoard(module, board) { | |
return new Promise((resolve, reject) => { | |
const mutation = ` | |
{ | |
moveModuleToBoard(input: { | |
clientMutationId: "${new Date().getTime()}", | |
boardId: "${board.id}", | |
moduleId: "${module.id}" | |
}) { | |
viewer { | |
id | |
} | |
} | |
} | |
` | |
client.mutate(mutation) | |
.then(result => { | |
return resolve(result) | |
}); | |
}) | |
} |
farmisen
commented
Jul 28, 2016
function getBoardForModule() {
return new Promise((resolve, reject) => {
// let's see if there are boards in our chrome extension storage
chrome.storage.sync.get('boards', ({boards}) => {
if (boards.length > 0) {
return resolve(boards[boards.length - 1])
}
// if no boards in extension storage, create one!
const mutation = `
{
addBoard(input: {
clientMutationId: "${new Date().getTime()}"
}) {
boardEdge {
node {
id,
name
}
}
}
}
`
client.mutate(mutation)
.then(result => {
const { addBoard: { boardEdge: { node } } } = result
chrome.storage.sync.set({
boards: [node]
})
return resolve(node)
});
})
})
}
async function getLocalBoards() {
return new Promise( (resolve, reject) => {
chrome.storage.sync.get('boards', ({boards}) => {
resolve(boards)
})
})
}
async function getBoardForModule() {
const boards = await getLocalBoards()
if (boards.length > 0) {
return boards[boards.length - 1]
}
// if no boards in extension storage, create one!
const mutation = `
{
addBoard(input: {
clientMutationId: "${new Date().getTime()}"
}) {
boardEdge {
node {
id,
name
}
}
}
}
`
const board = await client.mutate(mutation)
chrome.storage.sync.set({ boards: [board]})
return board
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment