From 0bc28c5fedf68f998c4ac05847cc205e1fc54ddb Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Sat, 24 Aug 2024 14:22:40 +0200 Subject: [PATCH] refactor --- apps/remix-ide/src/app/files/dgitProvider.ts | 11 +++- .../src/app/tabs/locales/en/git.json | 3 +- libs/remix-ui/git/src/components/gitui.tsx | 1 + .../components/panels/githubcredentials.tsx | 2 +- .../git/src/components/panels/setup.tsx | 54 ++++++++----------- libs/remix-ui/git/src/lib/gitactions.ts | 3 +- libs/remix-ui/git/src/types/index.ts | 5 +- .../workspace/src/lib/remix-ui-workspace.tsx | 4 +- 8 files changed, 45 insertions(+), 38 deletions(-) diff --git a/apps/remix-ide/src/app/files/dgitProvider.ts b/apps/remix-ide/src/app/files/dgitProvider.ts index 87cb4c3c8c..f81d80859b 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.ts +++ b/apps/remix-ide/src/app/files/dgitProvider.ts @@ -1060,9 +1060,18 @@ class DGitProvider extends Plugin { const emails = await octokit.request('GET /user/emails') const scopes = user.headers['x-oauth-scopes'] || '' + console.log(scopes) + + const scopesArr = scopes.split(',').map(scope => scope.trim()) return { - user: user.data, + user: {...user.data, isConnected: + scopes + && scopesArr.includes('repo') + && scopesArr.includes('read:user') + && scopesArr.includes('user:email') + && scopesArr.includes('gist') + }, emails: emails.data, scopes: scopes && scopes.split(',') } diff --git a/apps/remix-ide/src/app/tabs/locales/en/git.json b/apps/remix-ide/src/app/tabs/locales/en/git.json index c5f4fa6a09..ea64a5b02d 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/git.json +++ b/apps/remix-ide/src/app/tabs/locales/en/git.json @@ -16,5 +16,6 @@ "git.unstageall": "unstage all", "git.stageall": "stage all", "git.noremote": "this repo has no remotes", - "git.init": "Initialize repository" + "git.init": "Initialize repository", + "git.setup": "Setup git" } \ No newline at end of file diff --git a/libs/remix-ui/git/src/components/gitui.tsx b/libs/remix-ui/git/src/components/gitui.tsx index 98fa99616f..0fd8afc0e4 100644 --- a/libs/remix-ui/git/src/components/gitui.tsx +++ b/libs/remix-ui/git/src/components/gitui.tsx @@ -175,6 +175,7 @@ export const GitUI = (props: IGitUi) => { + {setup ? : null} {!setup && !needsInit ? <> diff --git a/libs/remix-ui/git/src/components/panels/githubcredentials.tsx b/libs/remix-ui/git/src/components/panels/githubcredentials.tsx index a81420e28b..e6b8da65d8 100644 --- a/libs/remix-ui/git/src/components/panels/githubcredentials.tsx +++ b/libs/remix-ui/git/src/components/panels/githubcredentials.tsx @@ -22,7 +22,7 @@ export const GitHubCredentials = () => { useEffect(() => { refresh() if (context.gitHubUser) { - setScopeWarning(!(context.gitHubScopes && context.gitHubScopes.length > 0)) + setScopeWarning(!context.gitHubUser.isConnected) } else { setScopeWarning(false) } diff --git a/libs/remix-ui/git/src/components/panels/setup.tsx b/libs/remix-ui/git/src/components/panels/setup.tsx index 981b0926c4..38e7953f3d 100644 --- a/libs/remix-ui/git/src/components/panels/setup.tsx +++ b/libs/remix-ui/git/src/components/panels/setup.tsx @@ -1,37 +1,29 @@ import React, { useEffect, useState } from 'react' -import { GetDeviceCode } from '../github/devicecode' -import { GitHubCredentials } from './githubcredentials' -import { Clone } from './clone' +import { gitUIPanels } from '../../types' +import GitUIButton from '../buttons/gituibutton' +import { FormattedMessage } from 'react-intl' -export const Setup = () => { +export const Setup = ({ callback }) => { - const [screen, setScreen] = useState(0) - if (screen === 0) { - return ( - <> -
SETUP
-
-
- To ensure that your commits are properly attributed in Git, you need to configure a username and email address. - These will be used to identify the author of the commit. -
- -
- -
- - ) - } else if (screen === 1) { - return ( - <> -
SETUP
-
Step 2
-
- To ensure that your commits are properly attributed in Git, you need to configure your username and email address. - -
- - ) + const startSetingUp = () => { + callback(gitUIPanels.GITHUB) } + + return ( + <> +
SETUP REQUIRED
+
+
+ To ensure that your commits are properly attributed in Git, you need to configure a username and email address or connect to GitHub. + These credentials will be used to identify the author of the commit. + + + +
+
+
+ + ) + } \ No newline at end of file diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index a4a6317adc..3c43d72903 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -574,8 +574,9 @@ export const saveGitHubCredentials = async (credentials: { username: string, ema } dispatch(setGitHubUser({ login: credentials.username, + isConnected: false })) - appDispatcher({ type: appActionTypes.setGitHubUser, payload: { login: credentials.username } }) + appDispatcher({ type: appActionTypes.setGitHubUser, payload: { login: credentials.username, isConnected: false } }) dispatch(setUserEmails([{ email: credentials.email, primary: true, diff --git a/libs/remix-ui/git/src/types/index.ts b/libs/remix-ui/git/src/types/index.ts index 3f70103838..4c24c1a450 100644 --- a/libs/remix-ui/git/src/types/index.ts +++ b/libs/remix-ui/git/src/types/index.ts @@ -5,7 +5,10 @@ import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomo import { CustomRemixApi } from "@remix-api"; import { Plugin } from "@remixproject/engine"; -export type GitHubUser = Partial +export type GitHubUser = Partial & { + isConnected: boolean +} + export type userEmails = Endpoints["GET /user/emails"]["response"]["data"] export interface IGitUi { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index ad10b7a0b8..f4725ca88e 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -971,7 +971,7 @@ export function Workspace() { { - !appContext.appState.gitHubUser && } { - appContext.appState.gitHubUser &&