Skip to content

Commit ddf4b45

Browse files
committed
fix: Making sure the trigger message is removed when leaving zone
1 parent af30023 commit ddf4b45

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Features/variable_actions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ActionMessage } from "@workadventure/iframe-api-typings";
12
import type { Properties } from "../Properties";
23

34
export function initVariableActionLayer(properties: Properties, layerName: string): void {
@@ -19,6 +20,8 @@ export function initVariableActionLayer(properties: Properties, layerName: strin
1920
}
2021
}
2122

23+
let actionMessagePopup: ActionMessage | undefined;
24+
2225
function setupVariableActionLayer(
2326
variableName: string,
2427
layerName: string,
@@ -34,7 +37,7 @@ function setupVariableActionLayer(
3437
if (enterValue !== undefined) {
3538
WA.room.onEnterLayer(layerName).subscribe(() => {
3639
if (triggerMessage) {
37-
WA.ui.displayActionMessage({
40+
actionMessagePopup = WA.ui.displayActionMessage({
3841
type: "message",
3942
message: triggerMessage,
4043
callback: () => {
@@ -49,6 +52,12 @@ function setupVariableActionLayer(
4952
if (leaveValue !== undefined) {
5053
WA.room.onLeaveLayer(layerName).subscribe(() => {
5154
WA.state[variableName] = leaveValue;
55+
if (actionMessagePopup) {
56+
actionMessagePopup.remove().catch((e) => {
57+
console.error(e);
58+
});
59+
actionMessagePopup = undefined;
60+
}
5261
});
5362
}
5463
}

0 commit comments

Comments
 (0)