react to changes

pull/3097/head
filip mertens 2 years ago committed by Aniket
parent 661dacb94b
commit b953418881
  1. 17
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 7
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  3. 32
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  4. 15
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  5. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -78,6 +78,7 @@ class DGitProvider extends Plugin {
...await this.getGitConfig(),
defaultBranch: (input && input.branch) || 'main'
})
this.emit('init')
}
async status (cmd) {
@ -88,28 +89,19 @@ class DGitProvider extends Plugin {
return status
}
async add (cmd, refresh = true) {
async add (cmd) {
await git.add({
...await this.getGitConfig(),
...cmd
})
if (refresh) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
}
this.emit('add')
}
async rm (cmd, refresh = true) {
async rm (cmd) {
await git.remove({
...await this.getGitConfig(),
...cmd
})
if (refresh) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
}
}
async checkout (cmd, refresh = true) {
@ -194,6 +186,7 @@ class DGitProvider extends Plugin {
...await this.getGitConfig(),
...cmd
})
this.emit('commit')
return sha
} catch (e) {
throw new Error(e)

@ -278,3 +278,10 @@ export const setCurrentWorkspaceCurrentBranch = (currentBranch?: string) => {
payload: currentBranch
}
}
export const setCurrentWorkspaceIsRepo = (isRepo: boolean) => {
return {
type: 'SET_CURRENT_WORKSPACE_IS_REPO',
payload: isRepo
}
}

@ -1,7 +1,7 @@
import React from 'react'
import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import axios, { AxiosResponse } from 'axios'
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setCurrentWorkspaceBranches, setCurrentWorkspaceCurrentBranch, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setCurrentWorkspaceBranches, setCurrentWorkspaceCurrentBranch, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace, setCurrentWorkspaceIsRepo } from './payload'
import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types'
@ -27,11 +27,19 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
plugin = filePanelPlugin
dispatch = reducerDispatch
plugin.on('dGitProvider', 'checkout', async () => {
const currentBranch = await plugin.call('dGitProvider', 'currentbranch')
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch))
await checkGit()
})
plugin.on('dGitProvider', 'init', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'add', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'commit', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'branch', async () => {
await refreshBranches()
await checkGit()
})
}
@ -100,10 +108,10 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
worktreeStatus
? plugin.call('dGitProvider', 'add', {
filepath: removeSlash(filepath),
}, false)
})
: plugin.call('dGitProvider', 'rm', {
filepath: removeSlash(filepath),
}, false)
})
)
).then(async () => {
await plugin.call('dGitProvider', 'commit', {
@ -461,6 +469,16 @@ export const cloneRepository = async (url: string) => {
}
}
export const checkGit = async () => {
const isGitRepo = await plugin.fileManager.isGitRepo()
dispatch(setCurrentWorkspaceIsRepo(isGitRepo))
await refreshBranches()
const currentBranch = await plugin.call('dGitProvider', 'currentbranch')
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch))
}
export const getRepositoryTitle = async (url: string) => {
const urlArray = url.split('/')
let name = urlArray.length > 0 ? urlArray[urlArray.length - 1] : ''
@ -486,7 +504,6 @@ export const getGitRepoBranches = async (workspacePath: string) => {
dir: addSlash(workspacePath)
}
const branches: { remote: any; name: string; }[] = await plugin.call('dGitProvider', 'branches', { ...gitConfig })
return branches
}
@ -496,7 +513,6 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
dir: addSlash(workspaceName)
}
const currentBranch: string = await plugin.call('dGitProvider', 'currentbranch', { ...gitConfig })
return currentBranch
}

@ -703,6 +703,21 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
case 'SET_CURRENT_WORKSPACE_IS_REPO': {
const payload: boolean = action.payload
return {
...state,
browser: {
...state.browser,
workspaces: state.browser.workspaces.map((workspace) => {
if (workspace.name === state.browser.currentWorkspace) workspace.isGitRepo = payload
return workspace
})
}
}
}
default:
throw new Error()
}

@ -697,7 +697,7 @@ export function Workspace () {
</div>
{
selectedWorkspace &&
<div className={`bg-light border-top ${selectedWorkspace.isGitRepo ? 'd-block' : 'd-none'}`} data-id="workspaceGitPanel">
<div className={`bg-light border-top ${selectedWorkspace.isGitRepo && currentBranch ? 'd-block' : 'd-none'}`} data-id="workspaceGitPanel">
<div className='d-flex justify-space-between p-1'>
<div className="mr-auto text-uppercase text-dark pt-2 pl-2">GIT</div>
<div className="pt-1 mr-1" data-id="workspaceGitBranchesDropdown">

Loading…
Cancel
Save