Skip to content

Commit a3d734a

Browse files
committed
chore: add message id to state as well
1 parent 363a923 commit a3d734a

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

package/src/components/Message/Message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
351351
const layout = await measureInWindow(messageWrapperRef, insets);
352352
setRect(layout);
353353
setOverlayMessageH(layout);
354-
openOverlay(messageOverlayId);
354+
openOverlay({ id: messageOverlayId, messageId: message.id });
355355
} catch (e) {
356356
console.error(e);
357357
}

package/src/components/Message/hooks/__tests__/useShouldUseOverlayStyles.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('useShouldUseOverlayStyles', () => {
6666
closing: false,
6767
closingPortalHostBlacklist: [],
6868
id: undefined,
69+
messageId: undefined,
6970
});
7071
});
7172
});
@@ -79,6 +80,7 @@ describe('useShouldUseOverlayStyles', () => {
7980
closing: false,
8081
closingPortalHostBlacklist: [],
8182
id: undefined,
83+
messageId: undefined,
8284
});
8385
});
8486
});

package/src/components/UIComponents/__tests__/PortalWhileClosingView.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('PortalWhileClosingView', () => {
5858
closing: false,
5959
closingPortalHostBlacklist: [],
6060
id: undefined,
61+
messageId: undefined,
6162
});
6263
});
6364
});
@@ -72,6 +73,7 @@ describe('PortalWhileClosingView', () => {
7273
closing: false,
7374
closingPortalHostBlacklist: [],
7475
id: undefined,
76+
messageId: undefined,
7577
});
7678
});
7779

package/src/contexts/overlayContext/__tests__/MessageOverlayHostLayer.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('MessageOverlayHostLayer', () => {
111111
closing: false,
112112
closingPortalHostBlacklist: [],
113113
id: undefined,
114+
messageId: undefined,
114115
});
115116
});
116117
});
@@ -124,6 +125,7 @@ describe('MessageOverlayHostLayer', () => {
124125
closing: false,
125126
closingPortalHostBlacklist: [],
126127
id: undefined,
128+
messageId: undefined,
127129
});
128130
});
129131

package/src/state-store/__tests__/message-overlay-store.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('message overlay store portal hooks', () => {
6565
closing: false,
6666
closingPortalHostBlacklist: [],
6767
id: undefined,
68+
messageId: undefined,
6869
});
6970
});
7071
});
@@ -81,6 +82,7 @@ describe('message overlay store portal hooks', () => {
8182
closing: false,
8283
closingPortalHostBlacklist: [],
8384
id: undefined,
85+
messageId: undefined,
8486
});
8587
});
8688

@@ -147,6 +149,7 @@ describe('message overlay store portal hooks', () => {
147149
closing: true,
148150
closingPortalHostBlacklist: [],
149151
id: undefined,
152+
messageId: undefined,
150153
});
151154
});
152155

package/src/state-store/message-overlay-store.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ import { useStateStore } from '../hooks';
1010
type OverlayState = {
1111
closingPortalHostBlacklist: string[];
1212
id: string | undefined;
13+
messageId: string | undefined;
1314
closing: boolean;
1415
};
1516

17+
type OpenOverlayParams = {
18+
id: string;
19+
messageId?: string;
20+
};
21+
1622
export type Rect = { x: number; y: number; w: number; h: number } | undefined;
1723
export type ClosingPortalLayoutEntry = {
1824
id: string;
@@ -26,6 +32,7 @@ const DefaultState = {
2632
closingPortalHostBlacklist: [],
2733
closing: false,
2834
id: undefined,
35+
messageId: undefined,
2936
};
3037
const DefaultClosingPortalLayoutsState: ClosingPortalLayoutsState = {
3138
layouts: {},
@@ -71,12 +78,14 @@ export const bumpOverlayLayoutRevision = (closeCorrectionDeltaY = 0) => {
7178
sharedValueController?.incrementCloseCorrectionY(closeCorrectionDeltaY);
7279
};
7380

74-
export const openOverlay = (id: string) => {
81+
export const openOverlay = (params: OpenOverlayParams | string) => {
82+
const overlayPayload = typeof params === 'string' ? { id: params, messageId: undefined } : params;
83+
7584
sharedValueController?.resetCloseCorrectionY();
7685
overlayStore.partialNext({
7786
closing: false,
7887
closingPortalHostBlacklist: getCurrentClosingPortalHostBlacklist(),
79-
id,
88+
...overlayPayload,
8089
});
8190
};
8291

@@ -216,6 +225,7 @@ overlayStore.subscribeWithSelector(actionQueueSelector, async ({ active }) => {
216225
const selector = (nextState: OverlayState) => ({
217226
closing: nextState.closing,
218227
id: nextState.id,
228+
messageId: nextState.messageId,
219229
});
220230

221231
export const useOverlayController = () => {
@@ -323,11 +333,11 @@ export const useClosingPortalLayouts = () => {
323333

324334
const noOpObject = { active: false, closing: false };
325335

326-
export const useIsOverlayActive = (messageId: string) => {
336+
export const useIsOverlayActive = (id: string) => {
327337
const messageOverlaySelector = useCallback(
328338
(nextState: OverlayState) =>
329-
nextState.id === messageId ? { active: true, closing: nextState.closing } : noOpObject,
330-
[messageId],
339+
nextState.id === id ? { active: true, closing: nextState.closing } : noOpObject,
340+
[id],
331341
);
332342

333343
return useStateStore(overlayStore, messageOverlaySelector);

0 commit comments

Comments
 (0)