pull/3549/head
yann300 2 years ago committed by Aniket
parent 7c1360f7bb
commit 05345cbff0
  1. 12
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

@ -27,17 +27,20 @@ interface ITabsState {
selectedIndex: number, selectedIndex: number,
fileDecorations: fileDecoration[], fileDecorations: fileDecoration[],
currentExt: string currentExt: string
fileName: string
} }
interface ITabsAction { interface ITabsAction {
type: string, type: string,
payload: any, payload: any,
ext?: string, ext?: string,
fileName?: string
} }
const initialTabsState: ITabsState = { const initialTabsState: ITabsState = {
selectedIndex: -1, selectedIndex: -1,
fileDecorations: [], fileDecorations: [],
currentExt: '' currentExt: '',
fileName: ''
} }
const tabsReducer = (state: ITabsState, action: ITabsAction) => { const tabsReducer = (state: ITabsState, action: ITabsAction) => {
@ -46,6 +49,7 @@ const tabsReducer = (state: ITabsState, action: ITabsAction) => {
return { return {
...state, ...state,
currentExt: action.ext, currentExt: action.ext,
fileName: action.fileName,
selectedIndex: action.payload, selectedIndex: action.payload,
} }
case 'SET_FILE_DECORATIONS': case 'SET_FILE_DECORATIONS':
@ -120,7 +124,7 @@ export const TabsUI = (props: TabsUIProps) => {
const activateTab = (name: string) => { const activateTab = (name: string) => {
const index = tabs.current.findIndex((tab) => tab.name === name) const index = tabs.current.findIndex((tab) => tab.name === name)
currentIndexRef.current = index currentIndexRef.current = index
dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(name)}) dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(name), fileName: name})
} }
const setFileDecorations = (fileStates: fileDecoration[]) => { const setFileDecorations = (fileStates: fileDecoration[]) => {
@ -152,7 +156,6 @@ export const TabsUI = (props: TabsUIProps) => {
if (ext) return ext[0].toLowerCase() if (ext) return ext[0].toLowerCase()
else return '' else return ''
} }
const path = active().substr(active().indexOf('/') + 1, active().length)
return ( return (
<div className="remix-ui-tabs d-flex justify-content-between border-0 header nav-tabs" data-id="tabs-component"> <div className="remix-ui-tabs d-flex justify-content-between border-0 header nav-tabs" data-id="tabs-component">
<div className="d-flex flex-row" style={{ maxWidth: 'fit-content', width: '99%' }}> <div className="d-flex flex-row" style={{ maxWidth: 'fit-content', width: '99%' }}>
@ -162,6 +165,7 @@ export const TabsUI = (props: TabsUIProps) => {
className="btn text-success py-0" className="btn text-success py-0"
disabled={!(tabsState.currentExt === 'js' || tabsState.currentExt === 'ts' || tabsState.currentExt === 'sol')} disabled={!(tabsState.currentExt === 'js' || tabsState.currentExt === 'ts' || tabsState.currentExt === 'sol')}
onClick={async () => { onClick={async () => {
const path = active().substr(active().indexOf('/') + 1, active().length)
const content = await props.plugin.call('fileManager', "readFile", path) const content = await props.plugin.call('fileManager', "readFile", path)
if (tabsState.currentExt === 'js' || tabsState.currentExt === 'ts') { if (tabsState.currentExt === 'js' || tabsState.currentExt === 'ts') {
await props.plugin.call('scriptRunner', 'execute', content, path) await props.plugin.call('scriptRunner', 'execute', content, path)
@ -180,7 +184,7 @@ export const TabsUI = (props: TabsUIProps) => {
tooltipId="overlay-tooltip-run-script" tooltipId="overlay-tooltip-run-script"
tooltipText={<span> tooltipText={<span>
{(tabsState.currentExt === 'js' || tabsState.currentExt === 'ts') ? "Run script (CTRL + SHIFT + S)" : {(tabsState.currentExt === 'js' || tabsState.currentExt === 'ts') ? "Run script (CTRL + SHIFT + S)" :
(path.endsWith('.script.sol')) ? "Run Solidity code as a script (free function)" : (tabsState.fileName.endsWith('.script.sol')) ? "Run Solidity code as a script (free function). This will run the function 'run'" :
tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul'? "Compile CTRL + S" : "Select .sol or .yul file to compile or a .ts or .js file and run it"} tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul'? "Compile CTRL + S" : "Select .sol or .yul file to compile or a .ts or .js file and run it"}
</span>} </span>}
> >

Loading…
Cancel
Save