Files
buzz/desktop/src/features/projects/ui/useProjectDiscussInChannel.ts
Thomas Petersen 8728af5040 feat(desktop): refine context-aware Projects collaboration
Give project agents the visible page context and shared thread presentation, while aligning list metadata and detail communication actions with the active workspace.

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
2026-08-17 12:22:33 -04:00

42 lines
1.2 KiB
TypeScript

import * as React from "react";
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
import {
loadDraftEntry,
saveDraftEntry,
} from "@/features/messages/lib/useDrafts";
import {
mergeSelectionDiscussDraft,
projectSelectionDiscussContent,
type ProjectSelectionItem,
} from "@/features/projects/lib/projectSelection";
export function useProjectDiscussInChannel(items: ProjectSelectionItem[]) {
const { goChannel } = useAppNavigation();
return React.useCallback(
(channelId: string) => {
const now = new Date().toISOString();
const existing = loadDraftEntry(channelId);
const content = mergeSelectionDiscussDraft(
existing?.content,
projectSelectionDiscussContent(items),
);
saveDraftEntry(channelId, {
channelId,
content,
createdAt: existing?.createdAt ?? now,
mentionRefs: existing?.mentionRefs ?? [],
pendingImeta: existing?.pendingImeta ?? [],
selectionEnd: content.length,
selectionStart: content.length,
spoileredAttachmentUrls: existing?.spoileredAttachmentUrls ?? [],
status: "active",
updatedAt: now,
});
void goChannel(channelId);
},
[goChannel, items],
);
}