From 072273204a1a529f47f819835519585fc9240cb8 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 8 Nov 2021 02:02:31 +0100 Subject: [PATCH] moved icon statuschanged handling higher up --- .../src/app/components/vertical-icons.js | 4 +-- .../src/lib/components/Badge.tsx | 33 ++++++++++++------- .../src/lib/components/Debugger.tsx | 31 +++++++++++++++-- .../src/lib/components/Icon.tsx | 29 +--------------- .../src/lib/components/Solidity.tsx | 29 ++++++++++++++-- .../lib/components/SolidityStaticAnalysis.tsx | 28 ++++++++++++++-- .../src/lib/components/Udapp.tsx | 31 +++++++++++++++-- .../src/lib/reducers/iconBadgeReducer.ts | 22 +++++-------- .../src/lib/remix-ui-vertical-icons-panel.css | 5 +-- 9 files changed, 147 insertions(+), 65 deletions(-) diff --git a/apps/remix-ide/src/app/components/vertical-icons.js b/apps/remix-ide/src/app/components/vertical-icons.js index e74ff87418..0033cc532d 100644 --- a/apps/remix-ide/src/app/components/vertical-icons.js +++ b/apps/remix-ide/src/app/components/vertical-icons.js @@ -76,9 +76,7 @@ export class VerticalIcons extends Plugin { // this.setIconStatus(profile.name, status) // } // this.iconStatus[profile.name] = fn - // this.on(profile.name, 'statusChanged', () => { - // console.log('caught statusChanged in react!') - // }) + // this.on(profile.name, this.iconStatus[profile.name]) } /** diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/components/Badge.tsx b/libs/remix-ui/vertical-icons-panel/src/lib/components/Badge.tsx index bd2dcd5cb8..8b49b65b9d 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/components/Badge.tsx +++ b/libs/remix-ui/vertical-icons-panel/src/lib/components/Badge.tsx @@ -7,15 +7,12 @@ import { iconBadgeReducer, IconBadgeReducerAction } from '../reducers/iconBadgeR import { BadgeStatus, IconProfile, IconStatus } from './Icon' interface BadgeProps { - verticalIconPlugin: VerticalIcons - iconRef: React.MutableRefObject - profile: IconProfile, badgeStatus: BadgeStatus } // eslint-disable-next-line no-undef // eslint-disable-next-line @typescript-eslint/no-unused-vars -function Badge ({ iconRef, verticalIconPlugin, profile, badgeStatus }: BadgeProps) { +function Badge ({ badgeStatus }: BadgeProps) { /** * resolve a classes list for @arg key * @param {Object} key @@ -43,14 +40,28 @@ function Badge ({ iconRef, verticalIconPlugin, profile, badgeStatus }: BadgeProp return classes } + function checkStatusKeyValue (value: any, type: string) { + if (value === 'succeed' || value === 'edited' || value === 'loading' || value === 'failed' || + typeof value === 'number' || type === 'warning' || type === 'error' || type === 'success' || type === 'info' || type === 'danger') { + return true + } + return false + } + return ( - + + { + badgeStatus && checkStatusKeyValue(badgeStatus.key, badgeStatus.type) ? ( + + ) : null + } + ) } diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/components/Debugger.tsx b/libs/remix-ui/vertical-icons-panel/src/lib/components/Debugger.tsx index 6e4cfbfc23..6fafcdc7be 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/components/Debugger.tsx +++ b/libs/remix-ui/vertical-icons-panel/src/lib/components/Debugger.tsx @@ -1,7 +1,9 @@ import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' // eslint-disable-next-line no-use-before-define -import React, { Fragment } from 'react' -import Icon from './Icon' +import React, { Fragment, useEffect, useReducer, useRef } from 'react' +import { iconBadgeReducer, IconBadgeReducerAction } from '../reducers/iconBadgeReducer' +import Badge from './Badge' +import Icon, { IconStatus } from './Icon' interface DebuggerProps { verticalIconsPlugin: VerticalIcons @@ -10,7 +12,24 @@ interface DebuggerProps { removeActive: () => void } +const initialState = { + text: '', + key: '', + title: '', + type: '' +} + function Debugger ({ verticalIconsPlugin, itemContextAction, addActive, removeActive }: DebuggerProps) { + const [badgeStatus, dispatchStatusUpdate] = useReducer(iconBadgeReducer, initialState) + const ref = useRef(null) + + useEffect(() => { + verticalIconsPlugin.on('debugger', 'statusChanged', (iconStatus: IconStatus) => { + const action: IconBadgeReducerAction = { type: 'debugger', payload: { status: iconStatus, ref: ref, verticalIconPlugin: verticalIconsPlugin } } + dispatchStatusUpdate(action) + }) + }, []) + return ( {verticalIconsPlugin.targetProfileForChange && @@ -31,6 +50,14 @@ function Debugger ({ verticalIconsPlugin, itemContextAction, addActive, removeAc verticalIconsPlugin.targetProfileForChange[p].displayName } /> + { + badgeStatus && verticalIconsPlugin.keys.includes(badgeStatus.key) && + verticalIconsPlugin.types.includes(badgeStatus.type) ? ( + + ) : null + } )) : null} diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/components/Icon.tsx b/libs/remix-ui/vertical-icons-panel/src/lib/components/Icon.tsx index ded511240b..2dde1a9b1a 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/components/Icon.tsx +++ b/libs/remix-ui/vertical-icons-panel/src/lib/components/Icon.tsx @@ -5,9 +5,6 @@ import VerticalIconsContextMenu from '../vertical-icons-context-menu' // eslint-disable-next-line @typescript-eslint/no-unused-vars import React, { Fragment, SyntheticEvent, useEffect, useReducer, useRef, useState } from 'react' import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' -// import * as helper from '../../../../../../apps/remix-ide/src/lib/helper' -import Badge from './Badge' -import { iconBadgeReducer, IconBadgeReducerAction } from '../reducers/iconBadgeReducer' interface IconProps { verticalIconPlugin: VerticalIcons @@ -41,13 +38,6 @@ export interface IconProfile { tooltip?: string } -const initialState = { - text: '', - key: '', - title: '', - type: '' -} - function Icon ({ profile, verticalIconPlugin, @@ -71,7 +61,6 @@ function Icon ({ const [showContext, setShowContext] = useState(false) const [canDeactivate] = useState(false) const iconRef = useRef(null) - const [badgeStatus, dispatchStatusUpdate] = useReducer(iconBadgeReducer, initialState) // eslint-disable-next-line @typescript-eslint/no-unused-vars const handleContextMenu = (e: SyntheticEvent & PointerEvent) => { @@ -91,13 +80,6 @@ function Icon ({ setShowContext(false) } - useEffect(() => { - verticalIconPlugin.on(profile.name, 'statusChanged', (iconStatus: IconStatus) => { - const action: IconBadgeReducerAction = { type: profile.name, payload: { status: iconStatus, ref: iconRef } } - dispatchStatusUpdate(action) - }) - }, []) - return (
{name}
- { - verticalIconPlugin.keys.includes(badgeStatus.key) ? ( - - ) : null - } + {showContext ? ( void removeActive: () => void } +const initialState = { + text: '', + key: '', + title: '', + type: '' +} function Solidity ({ verticalIconsPlugin, itemContextAction, addActive, removeActive }: SolidityProps) { + const [badgeStatus, dispatchStatusUpdate] = useReducer(iconBadgeReducer, initialState) + + useEffect(() => { + verticalIconsPlugin.on('solidity', 'statusChanged', (iconStatus: IconStatus) => { + const action: IconBadgeReducerAction = { type: 'solidity', payload: { status: iconStatus, verticalIconPlugin: verticalIconsPlugin } } + dispatchStatusUpdate(action) + }) + console.log('solidity icon useEffect handled no issues') + }, []) return ( {verticalIconsPlugin.targetProfileForChange && @@ -31,6 +48,14 @@ function Solidity ({ verticalIconsPlugin, itemContextAction, addActive, removeAc verticalIconsPlugin.targetProfileForChange[p].displayName } /> + { + badgeStatus && verticalIconsPlugin.keys.includes(badgeStatus.key) && + verticalIconsPlugin.types.includes(badgeStatus.type) ? ( + + ) : null + } )) : null} diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/components/SolidityStaticAnalysis.tsx b/libs/remix-ui/vertical-icons-panel/src/lib/components/SolidityStaticAnalysis.tsx index ce2fe43aeb..22f3069244 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/components/SolidityStaticAnalysis.tsx +++ b/libs/remix-ui/vertical-icons-panel/src/lib/components/SolidityStaticAnalysis.tsx @@ -1,7 +1,9 @@ import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' // eslint-disable-next-line no-use-before-define -import React, { Fragment } from 'react' -import Icon from './Icon' +import React, { Fragment, useEffect, useReducer } from 'react' +import { iconBadgeReducer, IconBadgeReducerAction } from '../reducers/iconBadgeReducer' +import Badge from './Badge' +import Icon, { IconStatus } from './Icon' interface SolidityStaticAnalysisProps { verticalIconsPlugin: VerticalIcons @@ -10,7 +12,21 @@ interface SolidityStaticAnalysisProps { removeActive: () => void } +const initialState = { + text: '', + key: '', + title: '', + type: '' +} + function SolidityStaticAnalysis ({ verticalIconsPlugin, itemContextAction, addActive, removeActive }: SolidityStaticAnalysisProps) { + const [badgeStatus, dispatchStatusUpdate] = useReducer(iconBadgeReducer, initialState) + useEffect(() => { + verticalIconsPlugin.on('solidityStaticAnalysis', 'statusChanged', (iconStatus: IconStatus) => { + const action: IconBadgeReducerAction = { type: 'solidityStaticAnalysis', payload: { status: iconStatus, verticalIconPlugin: verticalIconsPlugin } } + dispatchStatusUpdate(action) + }) + }, []) return ( {verticalIconsPlugin.targetProfileForChange && @@ -31,6 +47,14 @@ function SolidityStaticAnalysis ({ verticalIconsPlugin, itemContextAction, addAc verticalIconsPlugin.targetProfileForChange[p].displayName } /> + { + badgeStatus && verticalIconsPlugin.keys.includes(badgeStatus.key) && + verticalIconsPlugin.types.includes(badgeStatus.type) ? ( + + ) : null + } )) : null} diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/components/Udapp.tsx b/libs/remix-ui/vertical-icons-panel/src/lib/components/Udapp.tsx index 377609d968..44c592e3f7 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/components/Udapp.tsx +++ b/libs/remix-ui/vertical-icons-panel/src/lib/components/Udapp.tsx @@ -1,7 +1,9 @@ import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' // eslint-disable-next-line no-use-before-define -import React, { Fragment } from 'react' -import Icon from './Icon' +import React, { Fragment, useEffect, useReducer, useRef } from 'react' +import { iconBadgeReducer, IconBadgeReducerAction } from '../reducers/iconBadgeReducer' +import Badge from './Badge' +import Icon, { IconStatus } from './Icon' interface UdappProps { verticalIconsPlugin: VerticalIcons @@ -10,7 +12,24 @@ interface UdappProps { removeActive: () => void } +const initialState = { + text: '', + key: '', + title: '', + type: '' +} + function Udapp ({ verticalIconsPlugin, itemContextAction, addActive, removeActive }: UdappProps) { + const [badgeStatus, dispatchStatusUpdate] = useReducer(iconBadgeReducer, initialState) + const ref = useRef(null) + + useEffect(() => { + verticalIconsPlugin.on('udapp', 'statusChanged', (iconStatus: IconStatus) => { + const action: IconBadgeReducerAction = { type: 'udapp', payload: { status: iconStatus, ref: ref, verticalIconPlugin: verticalIconsPlugin } } + dispatchStatusUpdate(action) + }) + }, []) + return ( {verticalIconsPlugin.targetProfileForChange && @@ -32,6 +51,14 @@ function Udapp ({ verticalIconsPlugin, itemContextAction, addActive, removeActiv verticalIconsPlugin.targetProfileForChange[p].displayName } /> + { + badgeStatus && verticalIconsPlugin.keys.includes(badgeStatus.key) && + verticalIconsPlugin.types.includes(badgeStatus.type) ? ( + + ) : null + } )) : null} diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/reducers/iconBadgeReducer.ts b/libs/remix-ui/vertical-icons-panel/src/lib/reducers/iconBadgeReducer.ts index 27bb556ff7..d0c35b91f3 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/reducers/iconBadgeReducer.ts +++ b/libs/remix-ui/vertical-icons-panel/src/lib/reducers/iconBadgeReducer.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import helper from 'apps/remix-ide/src/lib/helper' import { BadgeStatus, IconStatus } from '../components/Icon' -import React from 'react' +import React, { MutableRefObject } from 'react' +import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' export type IconBadgeReducerAction = { readonly type: string @@ -24,11 +25,7 @@ export type IconBadgeReducerAction = { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars // if (!ref.current) return -function setIconStatus (name: string, status: IconStatus, ref: React.MutableRefObject) { - const statusEl = ref.current.querySelector('i') - if (statusEl) { - ref.current.removeChild(statusEl) // need to eject component instead of removing? - } +function setIconStatus (name: string, status: IconStatus) { if (status.key === 'none') return { ...status, text: '' } // remove status let text = '' @@ -42,19 +39,18 @@ function setIconStatus (name: string, status: IconStatus, ref: React.MutableRefO let thisType = '' if (status.type === 'error') { thisType = 'danger' // to use with bootstrap - // eslint-disable-next-line @typescript-eslint/no-unused-vars } else thisType = helper.checkSpecialChars(status.type) ? '' : status.type! - // eslint-disable-next-line @typescript-eslint/no-unused-vars const title = helper.checkSpecialChars(status.title) ? '' : status.title - // ref.current.classList.add('remixui_icon') + console.log(`new status for ${name} is :`, { title, type: thisType, key, text }) return { title, type: thisType, key, text } } export function iconBadgeReducer (state: BadgeStatus, action: IconBadgeReducerAction) { - const status = setIconStatus(action.type, action.payload.status, action.payload.ref) - if (action.type.length > 0) { - console.log(`from reducer of ${action.type} :`, { status }) - return status + const { status, ref, verticalIconPlugin } = action.payload + if (Object.keys(verticalIconPlugin.targetProfileForChange).includes(action.type)) { + const setStatus = setIconStatus(action.type, status) + console.log(`from reducer of ${action.type} :`, { setStatus }) + return setStatus } return state } diff --git a/libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.css b/libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.css index 55f1902eb5..27ecdf7f93 100644 --- a/libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.css +++ b/libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.css @@ -44,9 +44,10 @@ bottom: 0; } .remixui_status { - /* position: relative; + /* position: relative; */ bottom: 0; - right: 0; */ + right: 0; + align-self: flex-end; } .remixui_statusCheck { font-size: 1.2em;