View in #ohif on Slack
@Enas_Mostafa: I’m encountering an issue with ViewportGridContext
. When I try to apply actions like pan, zoom, window leveling, or drawing annotations in non-active viewport, I have to activate the viewport first. After investigating, I found that the SET_ACTIVE_VIEWPORT_ID
action is being dispatched correctly, but when I call getState
, the viewportGridState
still holds the old value of the active viewport id.
I tried removing useCallback
from getState
, but the problem persists—I still see the old active viewport ID, and I have to click again to apply the action.
Could you please advice or help me
@Alireza_Sedghi: It is very annoying
I have seen this too
if you put the call into setTimeout , 0 it wokrs fine
i need to fix it properly though
probably the state should move to the service
and provider should read from it
@Enas_Mostafa: I tried setTimeout in the
public setActiveViewportId(id: string) {
this.serviceImplementation._setActiveViewport(id);
setTimeout(() => {
const state = this.getState();
this._broadcastEvent(this.EVENTS.ACTIVE_VIEWPORT_ID_CHANGED, {
viewportId: id,
});
}, 10);
}
I see that insside timeout it work but I think the delay in state update cause me to click again to apply the action
Should I add timeout in another place??
@Alireza_Sedghi: i’m trying to see right now
@Enas_Mostafa: Thank you so much
@Alireza_Sedghi: seems like if you subscribe to the event
it works fine
const { unsubscribe } = viewportGridService.subscribe(evt, event => {
const viewportId = event.viewportId;
@Enas_Mostafa: where should i add this?
@Alireza_Sedghi: i mean you can add it anywhere you want
look here
https://docs.ohif.org/platform/services/pubsub/
Pub sub | OHIF
all services can be using this
@Enas_Mostafa: great
but when i click in port to change window or draw annotation
i think is done based on active tool group of the port
how can i update it to get the correct active port id?
@Alireza_Sedghi: seems like we need to do this
and it should work without pubsub
@Enas_Mostafa: ok let me try it
Still I have to click in port before start apply the action
@Alireza_Sedghi: you need to set the configuration
activateViewportBeforeInteraction
make it false or true
i don’t remember
@Enas_Mostafa: ok I will check it
yes worked fine now
and no need for the queuemicrotask
@Alireza_Sedghi: ok good