I am trying to create a type of panel in React (Preact) that changes display when the layer selection changes. The code is already working as intended, but I have a few questions.
-
According to the documentation, I need to use executeAsModal when there is a possibility of changing the Photoshop display. Does that apply to this case as well and do I need to use it?
-
According to the topic “Error: host is in a modal state”, if I put executeAsModal in the wrong place, it will interrupt with the operation of plugins created by others. Where is the right place to put it in this code?
export const App = () => {
const defaultState = {
selectedArtboard: null,
} ;
const [state, dispatch] = useReducer(reducer, defaultState) ;
// componentDidMount
useEffect(() => {
const onSelect = async (event, descriptor) => {
if(descriptor._obj) {
const layerInfo = await getLayerInfo(descriptor) ;
if(layerInfo.artboard) {
// update state based on artboard info
dispatch( {type: ActionType.setSelectedArtboard, payload: {value: layerInfo}} ) ;
return ;
}
}
// update state with null
dispatch( {type: ActionType.setSelectedArtboard, payload: {value: null}} ) ;
} ;
action.addNotificationListener(['select', 'selectNoLayers'], onSelect) ;
// componentWillUnmount
return () => {
action.removeNotificationListener(['select', 'selectNoLayers'], onSelect) ;
} ;
}, []) ;
return (
<p>{state.selectedArtboard ? state.selectedArtboard.name : ''}</p>
) ;
} ;