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