Skip to content

Commit 0239e06

Browse files
authored
Merge pull request ethereum#4787 from ethereum/ai_setting
enabled AI setting restore
2 parents 13cec16 + 0c6c57f commit 0239e06

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

apps/remix-ide/src/app/tabs/settings-tab.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const _paq = (window._paq = window._paq || [])
1515
const profile = {
1616
name: 'settings',
1717
displayName: 'Settings',
18-
methods: ['get', 'updateCopilotChoice'],
18+
methods: ['get', 'updateCopilotChoice', 'getCopilotSetting'],
1919
events: [],
2020
icon: 'assets/img/settings.webp',
2121
description: 'Remix-IDE settings',
@@ -52,7 +52,7 @@ module.exports = class SettingsTab extends ViewPlugin {
5252
this.element = document.createElement('div')
5353
this.element.setAttribute('id', 'settingsTab')
5454
this.useMatomoAnalytics = null
55-
this.useCopilot = false
55+
this.useCopilot = this.get('settings/copilot/suggest/activate')
5656
}
5757

5858
setDispatch(dispatch: React.Dispatch<any>) {
@@ -102,6 +102,10 @@ module.exports = class SettingsTab extends ViewPlugin {
102102
})
103103
}
104104

105+
getCopilotSetting(){
106+
return this.useCopilot
107+
}
108+
105109
updateMatomoAnalyticsChoice(isChecked) {
106110
this.config.set('settings/matomo-analytics', isChecked)
107111
this.useMatomoAnalytics = isChecked

libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
5858
const [ipfsProtocol, setipfsProtocol] = useState('')
5959
const [ipfsProjectId, setipfsProjectId] = useState('')
6060
const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
61-
const copilotDownload = useRef(null)
6261

6362
const intl = useIntl()
6463
const initValue = () => {
@@ -145,7 +144,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
145144
}
146145

147146
const startCopilot = async () => {
148-
copilotActivate(props.config, true, dispatch)
147+
copilotActivate(props.config, props.useCopilot, dispatch)
149148
props.plugin.call('terminal', 'log', { type: 'typewriterlog', value: `Solidity copilot activated!` })
150149
}
151150

libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {useState, useRef, useEffect, useReducer} from 'react' // eslint-d
55
import { FormattedMessage } from 'react-intl'
66
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'
77
import './remix-ui-tabs.css'
8+
import { values } from 'lodash'
89
const _paq = (window._paq = window._paq || [])
910

1011
/* eslint-disable-next-line */
@@ -64,7 +65,6 @@ export const TabsUI = (props: TabsUIProps) => {
6465
const tabsRef = useRef({})
6566
const tabsElement = useRef(null)
6667
const [ai_switch, setAI_switch] = useState<boolean>(false)
67-
6868
const tabs = useRef(props.tabs)
6969
tabs.current = props.tabs // we do this to pass the tabs list to the onReady callbacks
7070

@@ -77,6 +77,14 @@ export const TabsUI = (props: TabsUIProps) => {
7777
}
7878
}, [tabsState.selectedIndex])
7979

80+
const getAI = async() => {
81+
try {
82+
return await props.plugin.call('settings', 'getCopilotSetting')
83+
} catch (e){
84+
return false
85+
}
86+
}
87+
8088
const getFileDecorationClasses = (tab: any) => {
8189
const fileDecoration = tabsState.fileDecorations.find((fileDecoration: fileDecoration) => {
8290
if (`${fileDecoration.workspace.name}/${fileDecoration.path}` === tab.name) return true
@@ -92,7 +100,6 @@ export const TabsUI = (props: TabsUIProps) => {
92100
const classNameImg = 'my-1 mr-1 text-dark ' + tab.iconClass
93101
const classNameTab = 'nav-item nav-link d-flex justify-content-center align-items-center px-2 py-1 tab' + (index === currentIndexRef.current ? ' active' : '')
94102
const invert = props.themeQuality === 'dark' ? 'invert(1)' : 'invert(0)'
95-
96103
return (
97104
<CustomTooltip tooltipId="tabsActive" tooltipText={tab.tooltip} placement="bottom-start">
98105
<div
@@ -133,6 +140,7 @@ export const TabsUI = (props: TabsUIProps) => {
133140
}
134141

135142
const setFileDecorations = (fileStates: fileDecoration[]) => {
143+
getAI().then(value => setAI_switch(value)).catch(error => console.log(error))
136144
dispatch({ type: 'SET_FILE_DECORATIONS', payload: fileStates })
137145
}
138146

@@ -208,6 +216,7 @@ export const TabsUI = (props: TabsUIProps) => {
208216
<i className="fas fa-play"></i>
209217
</button>
210218
</CustomTooltip>
219+
211220
<div className= "d-flex border-left ml-2 align-items-center" style={{ height: "3em" }}>
212221
<CustomTooltip
213222
placement="bottom"

0 commit comments

Comments
 (0)