Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled AI setting restore #4787

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/remix-ide/src/app/tabs/settings-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const _paq = (window._paq = window._paq || [])
const profile = {
name: 'settings',
displayName: 'Settings',
methods: ['get', 'updateCopilotChoice'],
methods: ['get', 'updateCopilotChoice', 'getCopilotSetting'],
events: [],
icon: 'assets/img/settings.webp',
description: 'Remix-IDE settings',
Expand Down Expand Up @@ -52,7 +52,7 @@ module.exports = class SettingsTab extends ViewPlugin {
this.element = document.createElement('div')
this.element.setAttribute('id', 'settingsTab')
this.useMatomoAnalytics = null
this.useCopilot = false
this.useCopilot = this.get('settings/copilot/suggest/activate')
}

setDispatch(dispatch: React.Dispatch<any>) {
Expand Down Expand Up @@ -102,6 +102,10 @@ module.exports = class SettingsTab extends ViewPlugin {
})
}

getCopilotSetting(){
return this.useCopilot
}

updateMatomoAnalyticsChoice(isChecked) {
this.config.set('settings/matomo-analytics', isChecked)
this.useMatomoAnalytics = isChecked
Expand Down
3 changes: 1 addition & 2 deletions libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ipfsProtocol, setipfsProtocol] = useState('')
const [ipfsProjectId, setipfsProjectId] = useState('')
const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
const copilotDownload = useRef(null)

const intl = useIntl()
const initValue = () => {
Expand Down Expand Up @@ -145,7 +144,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
}

const startCopilot = async () => {
copilotActivate(props.config, true, dispatch)
copilotActivate(props.config, props.useCopilot, dispatch)
props.plugin.call('terminal', 'log', { type: 'typewriterlog', value: `Solidity copilot activated!` })
}

Expand Down
13 changes: 11 additions & 2 deletions libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 })
}

Expand Down Expand Up @@ -208,6 +216,7 @@ export const TabsUI = (props: TabsUIProps) => {
<i className="fas fa-play"></i>
</button>
</CustomTooltip>

<div className= "d-flex border-left ml-2 align-items-center" style={{ height: "3em" }}>
<CustomTooltip
placement="bottom"
Expand Down
Loading