Commit 863eae95 authored by ioedeveloper's avatar ioedeveloper

Detect scroll up and scroll down

parent be4f7b18
{ {
"rules": { "rules": {
"no-case-declarations": "off",
"array-callback-return": "warn", "array-callback-return": "warn",
"dot-location": ["warn", "property"], "dot-location": ["warn", "property"],
"eqeqeq": ["warn", "smart"], "eqeqeq": ["warn", "smart"],
......
...@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react' ...@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'
import Slider from '../slider/slider' import Slider from '../slider/slider'
import ButtonNavigator from '../button-navigator/button-navigator' import ButtonNavigator from '../button-navigator/button-navigator'
export const StepManager = ({ stepManager, stepManager: { jumpTo, traceLength, stepIntoBack, stepIntoForward, stepOverBack, stepOverForward, jumpOut, jumpNextBreakpoint, jumpPreviousBreakpoint, jumpToException, registerEvent } }) => { export const StepManager = ({ stepManager: { jumpTo, traceLength, stepIntoBack, stepIntoForward, stepOverBack, stepOverForward, jumpOut, jumpNextBreakpoint, jumpPreviousBreakpoint, jumpToException, registerEvent } }) => {
const [state, setState] = useState({ const [state, setState] = useState({
sliderValue: 0, sliderValue: 0,
revertWarning: '', revertWarning: '',
......
import React, { useState, useRef, useEffect } from 'react' import React, { useState, useRef, useEffect, useReducer } from 'react'
import { initialState, reducer } from '../../reducers/assembly-items'
import './styles/assembly-items.css' import './styles/assembly-items.css'
export const AssemblyItems = ({ codeView, index }) => { export const AssemblyItems = ({ registerEvent }) => {
const [state, setState] = useState({ const [assemblyItems, dispatch] = useReducer(reducer, initialState)
selectedItem: 0, const [selectedItem, setSelectedItem] = useState(0)
opCode: [] const [scrollHeight, setScrollHeight] = useState(null)
})
const refs = useRef({}) const refs = useRef({})
const asmItemsRef = useRef(null) const asmItemsRef = useRef(null)
useEffect(()=>{
registerEvent && registerEvent('codeManagerChanged', (code, address, index) => {
dispatch({ type: 'FETCH_OPCODES_SUCCESS', payload: { code, address, index } })
})
}, [])
useEffect(() => { useEffect(() => {
indexChanged(index) indexChanged(assemblyItems.index)
}, [index]) }, [assemblyItems.index])
useEffect(() => { useEffect(() => {
opCodeChanged(codeView) if (asmItemsRef.current.scrollTop > scrollHeight) {
}, [codeView]) console.log('scrolling up')
} else if (asmItemsRef.current.scrollTop < scrollHeight) {
console.log('scrolling down')
}
}, [asmItemsRef.current.scrollTop])
const indexChanged = (index) => { const indexChanged = (index: number) => {
if (index < 0) return if (index < 0) return
const { selectedItem } = state
let currentItem = refs.current[selectedItem] ? refs.current[selectedItem] : null let currentItem = refs.current[selectedItem] ? refs.current[selectedItem] : null
if (currentItem) { if (currentItem) {
currentItem.removeAttribute('selected') currentItem.removeAttribute('selected')
currentItem.removeAttribute('style') currentItem.removeAttribute('style')
...@@ -29,39 +38,31 @@ export const AssemblyItems = ({ codeView, index }) => { ...@@ -29,39 +38,31 @@ export const AssemblyItems = ({ codeView, index }) => {
currentItem.firstChild.removeAttribute('style') currentItem.firstChild.removeAttribute('style')
} }
const codeView = asmItemsRef.current const codeView = asmItemsRef.current
currentItem = codeView.children[index] currentItem = codeView.children[index]
currentItem.style.setProperty('border-color', 'var(--primary)') currentItem.style.setProperty('border-color', 'var(--primary)')
currentItem.style.setProperty('border-style', 'solid') currentItem.style.setProperty('border-style', 'solid')
currentItem.setAttribute('selected', 'selected') currentItem.setAttribute('selected', 'selected')
codeView.scrollTop = currentItem.offsetTop - parseInt(codeView.offsetTop) codeView.scrollTop = currentItem.offsetTop - parseInt(codeView.offsetTop)
setState(prevState => { setSelectedItem(index)
return {
...prevState,
selectedItem: index
}
})
} }
} }
const opCodeChanged = (codeView) => { const onScroll = () => {
setState(prevState => {
return {
...prevState,
opCode: codeView
}
})
} }
return ( return (
<div className="border rounded px-1 mt-1 bg-light"> <div className="border rounded px-1 mt-1 bg-light">
<div className='dropdownpanel'> <div className='dropdownpanel'>
<div className='dropdowncontent'> <div className='dropdowncontent'>
<div className="pl-2 my-1 small instructions" id='asmitems' ref={asmItemsRef}> <div className="pl-2 my-1 small instructions" id='asmitems' ref={asmItemsRef} onScroll={() => setScrollHeight(asmItemsRef.current.scrollTop)}>
{ {
// state.opCode.map((item, i) => { assemblyItems.display.map((item, i) => {
// return <div className="px-1" key={i} ref={ref => refs.current[i] = ref}><span>{item}</span></div> return <div className="px-1" key={i} ref={ref => refs.current[i] = ref}><span>{item}</span></div>
// }) })
} }
</div> </div>
</div> </div>
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import AssemblyItems from './assembly-items' import AssemblyItems from './assembly-items'
export const CodeListView = ({ asm }) => { export const CodeListView = ({ registerEvent }) => {
const [state, setState] = useState({ const [state, setState] = useState({
code: [], code: [],
address: '', address: '',
...@@ -9,12 +9,6 @@ export const CodeListView = ({ asm }) => { ...@@ -9,12 +9,6 @@ export const CodeListView = ({ asm }) => {
index: null index: null
}) })
useEffect(() => {
const { code, address, index } = asm
changed(code, address, index)
}, [asm])
const indexChanged = (index) => { const indexChanged = (index) => {
if(index < 0) return if(index < 0) return
setState(prevState => { setState(prevState => {
...@@ -41,7 +35,7 @@ export const CodeListView = ({ asm }) => { ...@@ -41,7 +35,7 @@ export const CodeListView = ({ asm }) => {
return ( return (
<div id='asmcodes'> <div id='asmcodes'>
<AssemblyItems codeView={state.code || []} index={state.index} /> <AssemblyItems registerEvent={registerEvent} />
</div> </div>
) )
} }
......
...@@ -119,8 +119,8 @@ export const VmDebuggerHead = ({ vmDebuggerHead: { registerEvent } }) => { ...@@ -119,8 +119,8 @@ export const VmDebuggerHead = ({ vmDebuggerHead: { registerEvent } }) => {
<SolidityLocals data={solidityLocals.calldata} message={solidityLocals.message} /> <SolidityLocals data={solidityLocals.calldata} message={solidityLocals.message} />
{/* <SolidityState calldata={solidityState.calldata} message={solidityState.message} /> */} {/* <SolidityState calldata={solidityState.calldata} message={solidityState.message} /> */}
</div> </div>
{/* <div className="w-100"><CodeListView asm={asm} /></div> <div className="w-100"><CodeListView registerEvent={registerEvent} /></div>
<div className="w-100"><StepDetail stepDetail={stepDetail} /></div> */} {/* <div className="w-100"><StepDetail stepDetail={stepDetail} /></div> */}
</div> </div>
</div> </div>
) )
......
import { default as deepEqual } from 'deep-equal'
interface Action {
type: string;
payload: { [key: string]: any };
}
export const initialState = {
opCodes: {
code: [],
index: 0,
address: ''
},
display: [],
index: 0,
isRequesting: false,
isSuccessful: false,
hasError: null
}
export const reducer = (state = initialState, action: Action) => {
switch (action.type) {
case 'FETCH_OPCODES_REQUEST':
return {
...state,
isRequesting: true,
isSuccessful: false,
hasError: null
};
case 'FETCH_OPCODES_SUCCESS':
const opCodes = action.payload.address === state.opCodes.address ? {
...state.opCodes, index: action.payload.index
} : deepEqual(action.payload.code, state.opCodes.code) ? state.opCodes : action.payload
const display = opCodes.index > 0 ? opCodes.code.slice(opCodes.index - 1, opCodes.index + 10) : opCodes.code.slice(opCodes.index, opCodes.index + 10)
return {
opCodes,
display,
index: display.findIndex(code => code === opCodes.code[opCodes.index]),
isRequesting: false,
isSuccessful: true,
hasError: null
};
case 'FETCH_OPCODES_ERROR':
return {
...state,
isRequesting: false,
isSuccessful: false,
hasError: action.payload
};
default:
throw new Error();
}
}
\ No newline at end of file
interface Action {
type: string;
payload: { [key: string]: any };
}
export const initialState = {
calldata: {},
isRequesting: false,
isSuccessful: false,
hasError: null
}
export const reducer = (state = initialState, action: Action) => {
switch (action.type) {
case 'FETCH_CALLDATA_REQUEST':
return {
...state,
isRequesting: true,
isSuccessful: false,
hasError: null
};
case 'FETCH_CALLDATA_SUCCESS':
return {
opCodes: action.payload,
isRequesting: false,
isSuccessful: true,
hasError: null
};
case 'FETCH_CALLDATA_ERROR':
return {
...state,
isRequesting: false,
isSuccessful: false,
hasError: action.payload
};
default:
throw new Error();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment