diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index f1313faa73..f38487d293 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.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() diff --git a/libs/remix-ui/git/src/lib/listeners.ts b/libs/remix-ui/git/src/lib/listeners.ts index 23de1c5f8f..c0cf410309 100644 --- a/libs/remix-ui/git/src/lib/listeners.ts +++ b/libs/remix-ui/git/src/lib/listeners.ts @@ -147,11 +147,13 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch { + console.log('config changed') await getGitConfig() }) plugin.on('settings', 'configChanged', async () => { + console.log('settings changed') await getGitConfig() - }) + }) callBackEnabled = true; } @@ -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) => { diff --git a/libs/remix-ui/git/src/state/gitpayload.ts b/libs/remix-ui/git/src/state/gitpayload.ts index ec54f9117a..d66264a19e 100644 --- a/libs/remix-ui/git/src/state/gitpayload.ts +++ b/libs/remix-ui/git/src/state/gitpayload.ts @@ -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