event duplication

pull/4791/head
filip mertens 6 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 }) => { export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => {
console.log('saveGitHubCredentials', credentials)
try { try {
await plugin.call('config', 'setAppParameter', 'settings/github-user-name', credentials.username) const storedEmail = await plugin.call('config', 'getAppParameter','settings/github-email')
await plugin.call('config', 'setAppParameter', 'settings/github-email', credentials.email) const storedUsername = await plugin.call('config', 'getAppParameter','settings/github-user-name')
await plugin.call('config', 'setAppParameter', 'settings/gist-access-token', credentials.token) 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) { } catch (e) {
console.log(e) console.log(e)
} }
@ -562,13 +568,19 @@ export const loadGitHubUserFromToken = async () => {
console.log('GET USER"', data) console.log('GET USER"', data)
if (data && data.emails && data.user && data.user.login) { if (data && data.emails && data.user && data.user.login) {
console.log('SET USER"', data)
const primaryEmail = data.emails.find(email => email.primary) 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(setGitHubUser(data.user))
dispatch(setRateLimit(data.ratelimit)) dispatch(setRateLimit(data.ratelimit))
dispatch(setScopes(data.scopes)) dispatch(setScopes(data.scopes))
dispatch(setUserEmails(data.emails)) dispatch(setUserEmails(data.emails))
} }
} else { } else {
const credentials = await getGitHubCredentialsFromLocalStorage() const credentials = await getGitHubCredentialsFromLocalStorage()

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

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

Loading…
Cancel
Save