|
|
|
@ -1,8 +1,9 @@ |
|
|
|
|
import React, { useEffect, Dispatch, useState } from 'react' |
|
|
|
|
import React, { useEffect, Dispatch, useState, useContext } from 'react' |
|
|
|
|
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
|
|
|
|
|
import { StatusBar } from 'apps/remix-ide/src/app/components/status-bar' |
|
|
|
|
import '../../css/statusbar.css' |
|
|
|
|
import { CustomTooltip } from '@remix-ui/helper' |
|
|
|
|
import { AppContext } from '@remix-ui/app' |
|
|
|
|
|
|
|
|
|
export interface GitStatusProps { |
|
|
|
|
plugin: StatusBar |
|
|
|
@ -11,70 +12,32 @@ export interface GitStatusProps { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function GitStatus({ plugin, gitBranchName, setGitBranchName }: GitStatusProps) { |
|
|
|
|
const [isLocalHost, setIsLocalHost] = useState(false) |
|
|
|
|
const appContext = useContext(AppContext) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
plugin.on('filePanel', 'setWorkspace', async (workspace) => { |
|
|
|
|
const isGit = await plugin.call('fileManager', 'isGitRepo') |
|
|
|
|
setIsLocalHost(workspace.isLocalhost) |
|
|
|
|
if (isGit) { |
|
|
|
|
setGitBranchName(workspace.name) |
|
|
|
|
} else { |
|
|
|
|
setGitBranchName('Not a git repo') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
plugin.on('filePanel', 'workspaceInitializationCompleted', async () => { |
|
|
|
|
const isGit = await plugin.call('fileManager', 'isGitRepo') |
|
|
|
|
if (isGit) { |
|
|
|
|
const workspace = localStorage.getItem('currentWorkspace') |
|
|
|
|
setGitBranchName(workspace) |
|
|
|
|
} else { |
|
|
|
|
setGitBranchName('Not a git repo') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
plugin.on('dgitApi', 'init', async () => { |
|
|
|
|
const isGit = await plugin.call('fileManager', 'isGitRepo') |
|
|
|
|
if (isGit) { |
|
|
|
|
const workspace = localStorage.getItem('currentWorkspace') |
|
|
|
|
setGitBranchName(workspace) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
const lightDgitUp = async () => { |
|
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'dgit') |
|
|
|
|
const isGit = await plugin.call('fileManager', 'isGitRepo') |
|
|
|
|
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit') |
|
|
|
|
if (gitBranchName.length > 0 && isGit) { |
|
|
|
|
plugin.verticalIcons.select('dgit') |
|
|
|
|
} |
|
|
|
|
const openDgit = async () => { |
|
|
|
|
plugin.verticalIcons.select('dgit') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const initializeNewGitRepo = async () => { |
|
|
|
|
if (isLocalHost === false) { |
|
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'dgit') |
|
|
|
|
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit') |
|
|
|
|
await plugin.call('dgitApi', 'init') |
|
|
|
|
;(window as any)._paq.push('trackEvent', 'statusbar', 'initNewRepo') |
|
|
|
|
} |
|
|
|
|
await plugin.call('dgit', 'init') |
|
|
|
|
await plugin.call('matomo', 'track', ['trackEvent', 'statusBar', 'initNewRepo']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const checkBranchName = ()=> { |
|
|
|
|
return gitBranchName && gitBranchName !== 'Not a git repo' && gitBranchName.length > 0 |
|
|
|
|
} |
|
|
|
|
if (!appContext.appState.canUseGit) return null |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<CustomTooltip |
|
|
|
|
tooltipText={`${gitBranchName === 'Not a git repo' ? 'Initialize as a git repo' : gitBranchName} (Git)`} |
|
|
|
|
tooltipText={`${appContext.appState.needsGitInit ? 'Initialize as git repo' : 'Current branch: ' + appContext.appState.currentBranch.name}`} |
|
|
|
|
> |
|
|
|
|
<div |
|
|
|
|
className="d-flex flex-row pl-3 small text-white justify-content-center align-items-center remixui_statusbar_gitstatus" |
|
|
|
|
onClick={async () => await lightDgitUp()} |
|
|
|
|
onClick={async () => await openDgit()} |
|
|
|
|
> |
|
|
|
|
{checkBranchName() && isLocalHost === false ? <span className="fa-regular fa-code-branch ml-1"></span> |
|
|
|
|
: <span className=" ml-1" onClick={initializeNewGitRepo}> Initialize as git repo</span>} |
|
|
|
|
{checkBranchName() && isLocalHost === false && <span className="ml-1">{gitBranchName}</span>} |
|
|
|
|
{checkBranchName() && isLocalHost === false && <span className="fa-solid fa-arrows-rotate fa-1 ml-1"></span>} |
|
|
|
|
{!appContext.appState.needsGitInit ? <span className="fa-regular fa-code-branch ml-1"></span> |
|
|
|
|
: <span className=" ml-1" onClick={initializeNewGitRepo}>Initialize as git repo</span>} |
|
|
|
|
{!appContext.appState.needsGitInit && appContext.appState.currentBranch && |
|
|
|
|
<span onClick={async () => await openDgit()} className="ml-1">{appContext.appState.currentBranch.name}</span> |
|
|
|
|
} |
|
|
|
|
</div> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
) |
|
|
|
|