event duplication

pull/4791/head
filip mertens 5 months ago
parent 75642c450d
commit a61d3304a1
  1. 22
      libs/remix-ui/git/src/lib/gitactions.ts
  2. 12
      libs/remix-ui/git/src/lib/listeners.ts
  3. 1
      libs/remix-ui/git/src/state/gitpayload.ts

@ -523,10 +523,16 @@ export const remoteCommits = async (url: string, branch: string, length: number)
}
export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => {
console.log('saveGitHubCredentials', credentials)
try {
await plugin.call('config', 'setAppParameter', 'settings/github-user-name', credentials.username)
await plugin.call('config', 'setAppParameter', 'settings/github-email', credentials.email)
await plugin.call('config', 'setAppParameter', 'settings/gist-access-token', credentials.token)
const storedEmail = await plugin.call('config', 'getAppParameter','settings/github-email')
const storedUsername = await plugin.call('config', 'getAppParameter','settings/github-user-name')
const storedToken = await plugin.call('config', 'getAppParameter','settings/gist-access-token')
if(storedUsername !== credentials.username) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', credentials.username)
if(storedEmail !== credentials.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', credentials.email)
if(storedToken !== credentials.token) await plugin.call('config', 'setAppParameter', 'settings/gist-access-token', credentials.token)
} catch (e) {
console.log(e)
}
@ -562,13 +568,19 @@ export const loadGitHubUserFromToken = async () => {
console.log('GET USER"', data)
if (data && data.emails && data.user && data.user.login) {
console.log('SET USER"', data)
const primaryEmail = data.emails.find(email => email.primary)
if (primaryEmail) await plugin.call('config', 'setAppParameter', 'settings/github-email', primaryEmail.email)
data.user && data.user.login && await plugin.call('config', 'setAppParameter', 'settings/github-user-name', data.user.login)
const storedEmail = await plugin.call('config', 'getAppParameter', 'settings/github-email')
if (primaryEmail && storedEmail !== primaryEmail.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', primaryEmail.email)
const storedUsername = await plugin.call('config', 'getAppParameter', 'settings/github-user-name')
if(data.user && data.user.login && (storedUsername !== data.user.login)) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', data.user.login)
dispatch(setGitHubUser(data.user))
dispatch(setRateLimit(data.ratelimit))
dispatch(setScopes(data.scopes))
dispatch(setUserEmails(data.emails))
}
} else {
const credentials = await getGitHubCredentialsFromLocalStorage()

@ -147,9 +147,11 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
})
plugin.on('config', 'configChanged', async () => {
console.log('config changed')
await getGitConfig()
})
plugin.on('settings', 'configChanged', async () => {
console.log('settings changed')
await getGitConfig()
})
@ -161,12 +163,10 @@ export const getGitConfig = async () => {
const email = await plugin.call('settings', 'get', 'settings/github-email')
const token = await plugin.call('settings', 'get', 'settings/gist-access-token')
const config = { username, email, token }
gitDispatch(setGItHubToken(config.token))
gitDispatch(setGitHubUser({
login: config.username,
}))
gitDispatch(setUserEmails([{ email: email, primary: true, visibility: 'public', verified: true }]))
return config
loadGitHubUserFromToken()
return
}
const syncFromWorkspace = async (callback: Function, isLocalhost = false) => {

@ -45,6 +45,7 @@ export const setRemoteBranches = (branches: any[]) => {
}
export const setGitHubUser = (user: GitHubUser) => {
console.log('set user', user)
return {
type: 'SET_GITHUB_USER',
payload: user

Loading…
Cancel
Save