Skip to content

Commit a7d57db

Browse files
committed
refactor: return readonly tuple from useActivityKeysOfSendStatus per hook convention
1 parent 26e9a2d commit a7d57db

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

packages/component/src/Transcript/LiveRegion/LongSend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const LiveRegionLongSend = () => {
3131
const [tick, setTick] = useState(0);
3232

3333
/** Keys of outgoing non-presentational activities that are currently in the sending state. */
34-
const sendingKeys = useActivityKeysOfSendStatus(SENDING);
34+
const [sendingKeys] = useActivityKeysOfSendStatus(SENDING);
3535

3636
/**
3737
* Arm a per-key timer when a key newly enters `sendingKeys`.

packages/component/src/Transcript/LiveRegion/SendFailed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const LiveRegionSendFailed = () => {
2727
* Activities which are presentational, such as `event` or `typing`, are ignored to reduce confusions.
2828
* "Failed to send message" should not be narrated for presentational activities.
2929
*/
30-
const activityKeysOfSendFailed = useActivityKeysOfSendStatus(SEND_FAILED);
30+
const [activityKeysOfSendFailed] = useActivityKeysOfSendStatus(SEND_FAILED);
3131

3232
/** Returns localized "Failed to send message." */
3333
const liveRegionSendFailedAlt = localize('TRANSCRIPT_LIVE_REGION_SEND_FAILED_ALT');

packages/component/src/Transcript/LiveRegion/useActivityKeysOfSendStatus.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ const { useGetActivityByKey, useSendStatusByActivityKey } = hooks;
1212
*
1313
* Presentational activities (e.g. `event` or `typing`) are excluded to reduce noise.
1414
*/
15-
export default function useActivityKeysOfSendStatus(status: SendStatus): Set<string> {
15+
export default function useActivityKeysOfSendStatus(status: SendStatus): readonly [Set<string>] {
1616
const [sendStatusByActivityKey] = useSendStatusByActivityKey();
1717
const getActivityByKey = useGetActivityByKey();
1818

19-
return useMemo<Set<string>>(() => {
20-
const keys = new Set<string>();
19+
return [
20+
useMemo<Set<string>>(() => {
21+
const keys = new Set<string>();
2122

22-
for (const [key, sendStatus] of sendStatusByActivityKey) {
23-
if (sendStatus === status && !isPresentational(getActivityByKey(key))) {
24-
keys.add(key);
23+
for (const [key, sendStatus] of sendStatusByActivityKey) {
24+
if (sendStatus === status && !isPresentational(getActivityByKey(key))) {
25+
keys.add(key);
26+
}
2527
}
26-
}
2728

28-
return keys;
29-
}, [getActivityByKey, sendStatusByActivityKey, status]);
29+
return keys;
30+
}, [getActivityByKey, sendStatusByActivityKey, status])
31+
] as const;
3032
}

0 commit comments

Comments
 (0)