diff --git a/apps/remix-ide/src/app/components/status-bar.tsx b/apps/remix-ide/src/app/components/status-bar.tsx index cd0fe99ee1..786333a91e 100644 --- a/apps/remix-ide/src/app/components/status-bar.tsx +++ b/apps/remix-ide/src/app/components/status-bar.tsx @@ -3,20 +3,22 @@ import { EventEmitter } from 'events' import { Plugin } from '@remixproject/engine' import packageJson from '../../../../../package.json' import { PluginViewWrapper } from '@remix-ui/helper' -import { PluginProfile } from '../../types' +import { PluginProfile, StatusBarInterface } from '../../types' import { RemixUIStatusBar } from '@remix-ui/statusbar' const statusBarProfile: PluginProfile = { name: 'statusBar', displayName: 'Status Bar', description: 'Remix IDE status bar panel', - version: packageJson.version + methods: ['getGitBranchName'], + version: packageJson.version, } -export class StatusBar extends Plugin { +export class StatusBar extends Plugin implements StatusBarInterface { htmlElement: HTMLDivElement events: EventEmitter dispatch: React.Dispatch = () => {} + currentWorkspaceName: string = '' constructor() { super(statusBarProfile) this.events = new EventEmitter() @@ -25,15 +27,27 @@ export class StatusBar extends Plugin { } onActivation(): void { + this.on('filePanel', 'setWorkspace', async () => { + await this.getGitBranchName() + }) this.renderComponent() } + + async getGitBranchName() { + const isGitRepo = await this.call('fileManager', 'isGitRepo') + if (!isGitRepo) return + const repoName = await this.call('filePanel', 'getCurrentWorkspace') + repoName && repoName?.name.length > 0 ? this.currentWorkspaceName = repoName.name : this.currentWorkspaceName = '' + return { repoWorkspaceName: repoName } + } + setDispatch(dispatch: React.Dispatch) { this.dispatch = dispatch } renderComponent() { this.dispatch({ - plugins: this + plugins: this, }) } @@ -42,9 +56,10 @@ export class StatusBar extends Plugin { } render() { - return (
- -
) + return ( +
+ +
+ ) } - } diff --git a/apps/remix-ide/src/types/index.d.ts b/apps/remix-ide/src/types/index.d.ts index cb650c5daa..768a5fc9fb 100644 --- a/apps/remix-ide/src/types/index.d.ts +++ b/apps/remix-ide/src/types/index.d.ts @@ -1,4 +1,3 @@ - export interface PluginProfile { name: string displayName: string @@ -11,10 +10,10 @@ export interface PluginProfile { version?: string } -export interface StatusBarInterface extends Plugin { +export interface StatusBarInterface { htmlElement: HTMLDivElement events: EventEmitter dispatch: React.Dispatch setDispatch(dispatch: React.Dispatch): void + getGitBranchName: () => Promise } - diff --git a/libs/remix-ui/statusbar/src/lib/components/gitStatus.tsx b/libs/remix-ui/statusbar/src/lib/components/gitStatus.tsx index 7ce3de2bff..3270c5ce71 100644 --- a/libs/remix-ui/statusbar/src/lib/components/gitStatus.tsx +++ b/libs/remix-ui/statusbar/src/lib/components/gitStatus.tsx @@ -1,15 +1,20 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' +import { StatusBarInterface } from '../types' export interface GitStatusProps { - workspaceName: string + plugin: StatusBarInterface } -export default function GitStatus({ workspaceName }: GitStatusProps) { +export default function GitStatus({ plugin }: GitStatusProps) { + + const [gitBranchName, setGitBranchName] = useState('') return ( -
+
- {`${workspaceName}`} + {`${gitBranchName}`}
) diff --git a/libs/remix-ui/statusbar/src/lib/remixui-statusbar-panel.tsx b/libs/remix-ui/statusbar/src/lib/remixui-statusbar-panel.tsx index 372830a5df..c6b8653541 100644 --- a/libs/remix-ui/statusbar/src/lib/remixui-statusbar-panel.tsx +++ b/libs/remix-ui/statusbar/src/lib/remixui-statusbar-panel.tsx @@ -6,8 +6,6 @@ import ScamAlertStatus from './components/scamAlertStatus' import ScamDetails from './components/scamDetails' import { FloatingFocusManager, autoUpdate, flip, offset, shift, useClick, useDismiss, useFloating, useInteractions, useRole } from '@floating-ui/react' import axios from 'axios' -import { get } from 'lodash' -import { current } from '@reduxjs/toolkit' export interface RemixUIStatusBarProps { statusBarPlugin: StatusBarInterface @@ -18,12 +16,11 @@ export type ScamAlert = { url: string } -type GetCurrentWorkspace = - { - name: string - isLocalhost: boolean - absolutePath: string - } +type GetCurrentWorkspace = { + name: string + isLocalhost: boolean + absolutePath: string +} export function RemixUIStatusBar({ statusBarPlugin }: RemixUIStatusBarProps) { const [showScamDetails, setShowScamDetails] = useState(false) @@ -54,31 +51,13 @@ export function RemixUIStatusBar({ statusBarPlugin }: RemixUIStatusBarProps) { } }, []) - useEffect(() => { - async function getGitBranchName() { - const gitRepo = await statusBarPlugin.call('fileManager', 'isGitRepo') - console.log('gitRepo', gitRepo) - return gitRepo - } - async function getWorkspaceName() { - const thing = await statusBarPlugin.call('filePanel', 'getCurrentWorkspace') - console.log('thing', thing) - return thing - } - async function getWorkspaceGitBranchName() { - if (!getGitBranchName()) return - let currentWorkspace: GetCurrentWorkspace = {} as GetCurrentWorkspace - currentWorkspace = await getWorkspaceName() - console.log('currentWorkspace', currentWorkspace) - setWorkspaceName(currentWorkspace?.name) - } - getWorkspaceGitBranchName() - - return () => { - getWorkspaceGitBranchName() - } - - }, [statusBarPlugin]) + const t = async () => { + const isGit = await statusBarPlugin.call('fileManager', 'isGitRepo') + if (!isGit) return + const repoName = await statusBarPlugin.call('filePanel', 'getCurrentWorkspace') + repoName && repoName?.name.length > 0 ? statusBarPlugin.currentWorkspaceName = repoName.name : statusBarPlugin.currentWorkspaceName = '' + return { repoWorkspaceName: repoName } + } return ( <> @@ -89,7 +68,7 @@ export function RemixUIStatusBar({ statusBarPlugin }: RemixUIStatusBarProps) { )}
- +
diff --git a/libs/remix-ui/statusbar/src/lib/types/index.ts b/libs/remix-ui/statusbar/src/lib/types/index.ts index 3ff77181e1..f58a8f5937 100644 --- a/libs/remix-ui/statusbar/src/lib/types/index.ts +++ b/libs/remix-ui/statusbar/src/lib/types/index.ts @@ -17,4 +17,6 @@ export interface StatusBarInterface extends Plugin { events: EventEmitter dispatch: React.Dispatch setDispatch(dispatch: React.Dispatch): void + getGitBranchName: () => Promise + currentWorkspaceName: string }