|
|
|
@ -5,6 +5,7 @@ import React, {useState, useRef, useEffect, useReducer} from 'react' // eslint-d |
|
|
|
|
import { FormattedMessage } from 'react-intl' |
|
|
|
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs' |
|
|
|
|
import './remix-ui-tabs.css' |
|
|
|
|
import { values } from 'lodash' |
|
|
|
|
const _paq = (window._paq = window._paq || []) |
|
|
|
|
|
|
|
|
|
/* eslint-disable-next-line */ |
|
|
|
@ -64,7 +65,6 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
const tabsRef = useRef({}) |
|
|
|
|
const tabsElement = useRef(null) |
|
|
|
|
const [ai_switch, setAI_switch] = useState<boolean>(false) |
|
|
|
|
|
|
|
|
|
const tabs = useRef(props.tabs) |
|
|
|
|
tabs.current = props.tabs // we do this to pass the tabs list to the onReady callbacks
|
|
|
|
|
|
|
|
|
@ -77,6 +77,14 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
} |
|
|
|
|
}, [tabsState.selectedIndex]) |
|
|
|
|
|
|
|
|
|
const getAI = async() => { |
|
|
|
|
try { |
|
|
|
|
return await props.plugin.call('settings', 'getCopilotSetting') |
|
|
|
|
} catch (e){ |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getFileDecorationClasses = (tab: any) => { |
|
|
|
|
const fileDecoration = tabsState.fileDecorations.find((fileDecoration: fileDecoration) => { |
|
|
|
|
if (`${fileDecoration.workspace.name}/${fileDecoration.path}` === tab.name) return true |
|
|
|
@ -92,7 +100,6 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
const classNameImg = 'my-1 mr-1 text-dark ' + tab.iconClass |
|
|
|
|
const classNameTab = 'nav-item nav-link d-flex justify-content-center align-items-center px-2 py-1 tab' + (index === currentIndexRef.current ? ' active' : '') |
|
|
|
|
const invert = props.themeQuality === 'dark' ? 'invert(1)' : 'invert(0)' |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<CustomTooltip tooltipId="tabsActive" tooltipText={tab.tooltip} placement="bottom-start"> |
|
|
|
|
<div |
|
|
|
@ -133,6 +140,7 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const setFileDecorations = (fileStates: fileDecoration[]) => { |
|
|
|
|
getAI().then(value => setAI_switch(value)).catch(error => console.log(error)) |
|
|
|
|
dispatch({ type: 'SET_FILE_DECORATIONS', payload: fileStates }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -185,7 +193,7 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
> |
|
|
|
|
<button |
|
|
|
|
data-id="play-editor" |
|
|
|
|
className="btn text-success py-0" |
|
|
|
|
className="btn text-success pr-0 py-0 d-flex" |
|
|
|
|
disabled={!(tabsState.currentExt === 'js' || tabsState.currentExt === 'ts' || tabsState.currentExt === 'sol' || tabsState.currentExt === 'circom' || tabsState.currentExt === 'vy')} |
|
|
|
|
onClick={async () => { |
|
|
|
|
const path = active().substr(active().indexOf('/') + 1, active().length) |
|
|
|
@ -205,111 +213,82 @@ export const TabsUI = (props: TabsUIProps) => { |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
<i className="fad fa-play"></i> |
|
|
|
|
</button> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip |
|
|
|
|
placement="bottom" |
|
|
|
|
tooltipId="overlay-tooltip-explaination" |
|
|
|
|
tooltipText={ |
|
|
|
|
<span> |
|
|
|
|
{tabsState.currentExt === 'sol'? ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText5" /> |
|
|
|
|
) : ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText4" /> |
|
|
|
|
)} |
|
|
|
|
</span> |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<button |
|
|
|
|
data-id="explain-editor" |
|
|
|
|
id='explain_btn' |
|
|
|
|
className='btn py-0 text-ai px-0 d-flex' |
|
|
|
|
disabled={!(tabsState.currentExt === 'sol') || explaining} |
|
|
|
|
onClick={async () => { |
|
|
|
|
const path = active().substr(active().indexOf('/') + 1, active().length) |
|
|
|
|
const content = await props.plugin.call('fileManager', 'readFile', path) |
|
|
|
|
if (tabsState.currentExt === 'sol') { |
|
|
|
|
setExplaining(true) |
|
|
|
|
await props.plugin.call('solcoder', 'code_explaining', content) |
|
|
|
|
setExplaining(false) |
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', 'explain_file']) |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
<i className={`fa-solid fa-user-robot ${explaining ? 'loadingExplanation' : ''}`}></i> |
|
|
|
|
<span |
|
|
|
|
className="position-relative text-ai text-sm pl-1" |
|
|
|
|
style={{ fontSize: "x-small", alignSelf: "end" }} |
|
|
|
|
> |
|
|
|
|
AI |
|
|
|
|
</span> |
|
|
|
|
<i className="fas fa-play"></i> |
|
|
|
|
</button> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip |
|
|
|
|
placement="bottom" |
|
|
|
|
tooltipId="overlay-tooltip-copilot" |
|
|
|
|
tooltipText={ |
|
|
|
|
<span> |
|
|
|
|
{ tabsState.currentExt === 'sol'? ( |
|
|
|
|
!ai_switch ? ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText6" /> |
|
|
|
|
) : (<FormattedMessage id="remixUiTabs.tooltipText7" />) |
|
|
|
|
) : ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText4" /> |
|
|
|
|
)} |
|
|
|
|
</span> |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<button |
|
|
|
|
data-id="remix_ai_switch" |
|
|
|
|
id='remix_ai_switch' |
|
|
|
|
className="btn ai-switch text-ai pl-2 pr-0 py-0 d-flex" |
|
|
|
|
disabled={!(tabsState.currentExt === 'sol' )} |
|
|
|
|
onClick={async () => { |
|
|
|
|
await props.plugin.call('settings', 'updateCopilotChoice', !ai_switch) |
|
|
|
|
setAI_switch(!ai_switch) |
|
|
|
|
ai_switch ? _paq.push(['trackEvent', 'ai', 'solcoder', 'copilot_enabled']) : _paq.push(['trackEvent', 'ai', 'solcoder', 'copilot_disabled']) |
|
|
|
|
}} |
|
|
|
|
|
|
|
|
|
<div className= "d-flex border-left ml-2 align-items-center" style={{ height: "3em" }}> |
|
|
|
|
<CustomTooltip |
|
|
|
|
placement="bottom" |
|
|
|
|
tooltipId="overlay-tooltip-explaination" |
|
|
|
|
tooltipText={ |
|
|
|
|
<span> |
|
|
|
|
{tabsState.currentExt === 'sol'? ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText5" /> |
|
|
|
|
) : ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText4" /> |
|
|
|
|
)} |
|
|
|
|
</span> |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<i |
|
|
|
|
className={ai_switch ? "fa-solid fa-toggle-on" : "fa-solid fa-toggle-off"} |
|
|
|
|
></i> |
|
|
|
|
<span |
|
|
|
|
className="position-relative text-ai text-sm pl-1" |
|
|
|
|
style={{ fontSize: "x-small", alignSelf: "end" }} |
|
|
|
|
<button |
|
|
|
|
data-id="explain-editor" |
|
|
|
|
id='explain_btn' |
|
|
|
|
className='btn text-ai pl-2 pr-0 py-0 d-flex' |
|
|
|
|
disabled={!(tabsState.currentExt === 'sol') || explaining} |
|
|
|
|
onClick={async () => { |
|
|
|
|
const path = active().substr(active().indexOf('/') + 1, active().length) |
|
|
|
|
const content = await props.plugin.call('fileManager', 'readFile', path) |
|
|
|
|
if (tabsState.currentExt === 'sol') { |
|
|
|
|
setExplaining(true) |
|
|
|
|
await props.plugin.call('solcoder', 'code_explaining', content) |
|
|
|
|
setExplaining(false) |
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', 'explain_file']) |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
AI |
|
|
|
|
</span> |
|
|
|
|
</button> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-aiDocumentation" tooltipText={<FormattedMessage id="remixUiTabs.tooltipText8" />}> |
|
|
|
|
<span |
|
|
|
|
data-id="remix_ai_docs" |
|
|
|
|
id="remix_ai_docs" |
|
|
|
|
className="btn pl-2 pr-0 py-0 d-flex ai-docs" |
|
|
|
|
role='link' |
|
|
|
|
onClick={()=>{ |
|
|
|
|
window.open("https://remix-ide.readthedocs.io/en/latest/ai.html") |
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', 'documentation']) |
|
|
|
|
}} |
|
|
|
|
<i className={`fas fa-user-robot ${explaining ? 'loadingExplanation' : ''}`}></i> |
|
|
|
|
</button> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip |
|
|
|
|
placement="bottom" |
|
|
|
|
tooltipId="overlay-tooltip-copilot" |
|
|
|
|
tooltipText={ |
|
|
|
|
<span> |
|
|
|
|
{ tabsState.currentExt === 'sol'? ( |
|
|
|
|
!ai_switch ? ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipText6" /> |
|
|
|
|
) : (<FormattedMessage id="remixUiTabs.tooltipText7" />) |
|
|
|
|
) : ( |
|
|
|
|
<FormattedMessage id="remixUiTabs.tooltipTextDisabledCopilot" /> |
|
|
|
|
)} |
|
|
|
|
</span> |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<i className="fa-solid fa-book text-ai"></i> |
|
|
|
|
<span |
|
|
|
|
className="position-relative text-ai text-sm pl-1" |
|
|
|
|
style={{ fontSize: "x-small", alignSelf: "end" }} |
|
|
|
|
<button |
|
|
|
|
data-id="remix_ai_switch" |
|
|
|
|
id='remix_ai_switch' |
|
|
|
|
className="btn ai-switch text-ai pl-2 pr-0 py-0 d-flex" |
|
|
|
|
disabled={!(tabsState.currentExt === 'sol' )} |
|
|
|
|
onClick={async () => { |
|
|
|
|
await props.plugin.call('settings', 'updateCopilotChoice', !ai_switch) |
|
|
|
|
setAI_switch(!ai_switch) |
|
|
|
|
ai_switch ? _paq.push(['trackEvent', 'ai', 'solcoder', 'copilot_enabled']) : _paq.push(['trackEvent', 'ai', 'solcoder', 'copilot_disabled']) |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
AI |
|
|
|
|
</span> |
|
|
|
|
</span> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<i className={ai_switch ? "fas fa-toggle-on fa-lg" : "fas fa-toggle-off fa-lg"}></i> |
|
|
|
|
</button> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-zoom-out" tooltipText={<FormattedMessage id="remixUiTabs.zoomOut" />}> |
|
|
|
|
<span data-id="tabProxyZoomOut" className="btn btn-sm px-2 fas fa-search-minus text-dark" onClick={() => props.onZoomOut()}></span> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-run-zoom-in" tooltipText={<FormattedMessage id="remixUiTabs.zoomIn" />}> |
|
|
|
|
<span data-id="tabProxyZoomIn" className="btn btn-sm px-2 fas fa-search-plus text-dark" onClick={() => props.onZoomIn()}></span> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<div className= "d-flex border-left ml-2 align-items-center" style={{ height: "3em" }}> |
|
|
|
|
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-zoom-out" tooltipText={<FormattedMessage id="remixUiTabs.zoomOut" />}> |
|
|
|
|
<span data-id="tabProxyZoomOut" className="btn fas fa-search-minus text-dark pl-2 pr-0 py-0 d-flex" onClick={() => props.onZoomOut()}></span> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-run-zoom-in" tooltipText={<FormattedMessage id="remixUiTabs.zoomIn" />}> |
|
|
|
|
<span data-id="tabProxyZoomIn" className="btn fas fa-search-plus text-dark pl-2 pr-0 py-0 d-flex" onClick={() => props.onZoomIn()}></span> |
|
|
|
|
</CustomTooltip> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<Tabs |
|
|
|
|
className="tab-scroll" |
|
|
|
|