@ -1,10 +1,10 @@
import React , { useState , useReducer , useEffect , useCallback } from 'react' // eslint-disable-line
import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line
import { enablePersonalModeText , ethereunVMText , labels , generateContractMetadataText , matomoAnalytics , textDark , textSecondary , warnText , wordWrapText , swarmSettingsTitle , ipfsSettingsText } from './constants'
import { enablePersonalModeText , ethereunVMText , labels , generateContractMetadataText , matomoAnalytics , textDark , textSecondary , warnText , wordWrapText , swarmSettingsTitle , ipfsSettingsText , useAutoCompleteText } from './constants'
import './remix-ui-settings.css'
import { ethereumVM , generateContractMetadat , personal , textWrapEventAction , useMatomoAnalytics , saveTokenToast , removeTokenToast , saveSwarmSettingsToast , saveIpfsSettingsToast } from './settingsAction'
import { ethereumVM , generateContractMetadat , personal , textWrapEventAction , useMatomoAnalytics , saveTokenToast , removeTokenToast , saveSwarmSettingsToast , saveIpfsSettingsToast , useAutoCompletion } from './settingsAction'
import { initialState , toastInitialState , toastReducer , settingReducer } from './settingsReducer'
import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
import { RemixUiThemeModule , ThemeModule } from '@remix-ui/theme-module'
@ -32,13 +32,15 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ ipfsProjectId , setipfsProjectId ] = useState ( '' )
const [ ipfsProjectSecret , setipfsProjectSecret ] = useState ( '' )
const initValue = ( ) = > {
const metadataConfig = props . config . get ( 'settings/generate-contract-metadata' )
if ( metadataConfig === undefined || metadataConfig === null ) generateContractMetadat ( props . config , true , dispatch )
const javascriptVM = props . config . get ( 'settings/always-use-vm' )
if ( javascriptVM === null || javascriptVM === undefined ) ethereumVM ( props . config , true , dispatch )
const useAutoComplete = props . config . get ( 'settings/use-auto-complete' )
if ( useAutoComplete === null || useAutoComplete === undefined ) useAutoCompletion ( props . config , true , dispatch )
}
useEffect ( ( ) = > initValue ( ) , [ resetState , props . config ] )
useEffect ( ( ) = > initValue ( ) , [ ] )
@ -87,7 +89,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
setipfsProjectSecret ( configipfsProjectSecret )
}
} , [ themeName , state . message ] )
useEffect ( ( ) = > {
@ -114,6 +115,10 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
useMatomoAnalytics ( props . config , event . target . checked , dispatch )
}
const onchangeUseAutoComplete = event = > {
useAutoCompletion ( props . config , event . target . checked , dispatch )
}
const getTextClass = ( key ) = > {
if ( props . config . get ( key ) ) {
return textDark
@ -128,6 +133,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const isEditorWrapChecked = props . config . get ( 'settings/text-wrap' ) || false
const isPersonalChecked = props . config . get ( 'settings/personal-mode' ) || false
const isMatomoChecked = props . config . get ( 'settings/matomo-analytics' ) || false
const isAutoCompleteChecked = props . config . get ( 'settings/auto-completion' ) === null ? true : props . config . get ( 'settings/auto-completion' )
return (
< div className = "$border-top" >
@ -164,6 +170,12 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
< input id = "editorWrap" className = "custom-control-input" type = "checkbox" onChange = { textWrapEvent } checked = { isEditorWrapChecked } / >
< label className = { ` form-check-label custom-control-label align-middle ${ getTextClass ( 'settings/text-wrap' ) } ` } htmlFor = "editorWrap" > { wordWrapText } < / label >
< / div >
< div className = 'custom-control custom-checkbox mb-1' >
< input onChange = { onchangeUseAutoComplete } id = "settingsUseAutoComplete" type = "checkbox" className = "custom-control-input" checked = { isAutoCompleteChecked } / >
< label className = { ` form-check-label custom-control-label align-middle ${ getTextClass ( 'settings/use-auto-complete' ) } ` } htmlFor = "settingsUseAutoComplete" >
< span > { useAutoCompleteText } < / span >
< / label >
< / div >
< div className = "custom-control custom-checkbox mb-1" >
< input onChange = { onchangePersonal } id = "personal" type = "checkbox" className = "custom-control-input" checked = { isPersonalChecked } / >
< label className = { ` form-check-label custom-control-label align-middle ${ getTextClass ( 'settings/personal-mode' ) } ` } htmlFor = "personal" >