Skip to content

Instantly share code, notes, and snippets.

@mvanlonden
Created July 28, 2016 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanlonden/b93bb5d083bb348b0aec59fba583778e to your computer and use it in GitHub Desktop.
Save mvanlonden/b93bb5d083bb348b0aec59fba583778e to your computer and use it in GitHub Desktop.
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
Copy link


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