The best way to control Claude Code, Codex and more from any computer or phone

main
ts 40 lines 1.45 KB
Raw
1 import { type ComposerImageAttachment, type DraftId } from "../../composerDraftStore";
2 import { type ScopedThreadRef } from "@t3tools/contracts";
3 import {
4 getPendingSnapShotAnimations,
5 pendingSnapShotAnimationIdsForTarget,
6 subscribeToPendingSnapShotAnimations,
7 } from "../../lib/snapShotAnimation";
8 import { useSyncExternalStore } from "react";
9
10 /**
11 * Follows the SnapShots still animating into this draft and splits the draft's images into
12 * pending SnapShots and standalone images.
13 */
14 export function useComposerImageGroups(
15 composerDraftTarget: ScopedThreadRef | DraftId,
16 composerImages: ReadonlyArray<ComposerImageAttachment>,
17 composerPreviewAnnotations: ReadonlyArray<{ readonly id: string }>,
18 ) {
19 const pendingSnapShotAnimations = useSyncExternalStore(
20 subscribeToPendingSnapShotAnimations,
21 getPendingSnapShotAnimations,
22 getPendingSnapShotAnimations,
23 );
24 const pendingSnapShotIds = pendingSnapShotAnimationIdsForTarget(
25 pendingSnapShotAnimations,
26 composerDraftTarget,
27 );
28 const previewAnnotationIds = new Set(
29 composerPreviewAnnotations.map((annotation) => annotation.id),
30 );
31 return {
32 pendingSnapShotAnimations,
33 pendingSnapShotIds,
34 pendingSnapShotIdSet: new Set(pendingSnapShotIds),
35 uncommittedSnapShotIds: pendingSnapShotIds.filter(
36 (id) => !composerImages.some((image) => image.id === id),
37 ),
38 standaloneComposerImages: composerImages.filter((image) => !previewAnnotationIds.has(image.id)),
39 };
40 }