mirror of
https://github.com/block/buzz.git
synced 2026-10-30 22:11:36 +00:00
Co-authored-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz> Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import * as React from "react";
|
|
|
|
type HuddleThreadIsolationOptions = {
|
|
closeThread: (threadId: string | null) => void;
|
|
isHuddleTranscript: boolean;
|
|
openThreadHeadId: string | null;
|
|
optimisticOpenThreadHeadId: string | null | undefined;
|
|
requireThreadEditResolutionRef: React.RefObject<() => boolean>;
|
|
};
|
|
|
|
export function resolveHuddleOpenThreadHeadId({
|
|
isHuddleTranscript,
|
|
openThreadHeadId,
|
|
optimisticOpenThreadHeadId,
|
|
}: Pick<
|
|
HuddleThreadIsolationOptions,
|
|
"isHuddleTranscript" | "openThreadHeadId" | "optimisticOpenThreadHeadId"
|
|
>): string | null {
|
|
if (isHuddleTranscript) return null;
|
|
return optimisticOpenThreadHeadId === undefined
|
|
? openThreadHeadId
|
|
: optimisticOpenThreadHeadId;
|
|
}
|
|
|
|
export function useHuddleThreadIsolation({
|
|
closeThread,
|
|
isHuddleTranscript,
|
|
openThreadHeadId,
|
|
optimisticOpenThreadHeadId,
|
|
requireThreadEditResolutionRef,
|
|
}: HuddleThreadIsolationOptions): string | null {
|
|
React.useEffect(() => {
|
|
if (!isHuddleTranscript || openThreadHeadId === null) return;
|
|
if (!requireThreadEditResolutionRef.current()) return;
|
|
closeThread(null);
|
|
}, [
|
|
closeThread,
|
|
isHuddleTranscript,
|
|
openThreadHeadId,
|
|
requireThreadEditResolutionRef,
|
|
]);
|
|
return resolveHuddleOpenThreadHeadId({
|
|
isHuddleTranscript,
|
|
openThreadHeadId,
|
|
optimisticOpenThreadHeadId,
|
|
});
|
|
}
|