mirror of
https://github.com/block/buzz.git
synced 2026-10-31 06:21:34 +00:00
refactor(desktop): extract agent activity opening actions
Co-authored-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz> Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import { useAppShell } from "@/app/AppShellContext";
|
||||
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
|
||||
import { useActiveChannelHeader } from "@/features/channels/useActiveChannelHeader";
|
||||
@@ -58,7 +57,6 @@ import type { TimelineMessage } from "@/features/messages/types";
|
||||
import { useUsersBatchQuery } from "@/features/profile/hooks";
|
||||
import { useRelaySelfQuery } from "@/features/moderation/hooks";
|
||||
import type { RelayEvent, RespondToMode } from "@/shared/api/types";
|
||||
import { openAgentActivityWindow } from "@/shared/api/agentActivityWindow";
|
||||
import { isAgentActivityWindow } from "@/features/agents/lib/agentActivityWindow";
|
||||
import { ChannelScreenLoadingFallback } from "@/features/channels/ui/ChannelScreenLoadingFallback";
|
||||
import {
|
||||
@@ -79,6 +77,7 @@ import { normalizePubkey } from "@/shared/lib/pubkey";
|
||||
import { useChannelActivityTyping } from "./useChannelActivityTyping";
|
||||
import { useChannelAgentSessions } from "./useChannelAgentSessions";
|
||||
import { useMessageProfiles } from "./useMessageProfiles";
|
||||
import { useOpenAgentActivityActions } from "./useOpenAgentActivityActions";
|
||||
import { useChannelPanelHistoryState } from "./useChannelPanelHistoryState";
|
||||
import { useChannelProfilePanel } from "./useChannelProfilePanel";
|
||||
import { useChannelRouteTarget } from "./useChannelRouteTarget";
|
||||
@@ -587,35 +586,10 @@ export function ChannelScreen({
|
||||
setThreadReplyTargetId,
|
||||
setThreadScrollTargetId,
|
||||
});
|
||||
const handleOpenAgentActivityExternal = React.useCallback(
|
||||
(pubkey: string, channelId?: string | null) => {
|
||||
const destinationChannelId = channelId ?? activeChannelId;
|
||||
if (!destinationChannelId) return;
|
||||
|
||||
if (isAgentActivityWindow()) {
|
||||
handleOpenAgentSession(pubkey, destinationChannelId);
|
||||
return;
|
||||
}
|
||||
|
||||
void openAgentActivityWindow(destinationChannelId, pubkey)
|
||||
.then((openedNativeWindow) => {
|
||||
if (!openedNativeWindow) {
|
||||
handleOpenAgentSession(pubkey, destinationChannelId);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to open agent activity window:", error);
|
||||
toast.error("Couldn't open the agent activity window.");
|
||||
});
|
||||
},
|
||||
[activeChannelId, handleOpenAgentSession],
|
||||
);
|
||||
const handleOpenAgentActivity = React.useCallback(
|
||||
(pubkey: string, channelId?: string | null) => {
|
||||
handleOpenAgentSession(pubkey, channelId ?? activeChannelId);
|
||||
},
|
||||
[activeChannelId, handleOpenAgentSession],
|
||||
);
|
||||
const {
|
||||
openInApp: handleOpenAgentActivity,
|
||||
openInExternalWindow: handleOpenAgentActivityExternal,
|
||||
} = useOpenAgentActivityActions(activeChannelId, handleOpenAgentSession);
|
||||
const { handleOpenProfilePanel, handleCloseProfilePanel, handleOpenDm } =
|
||||
useChannelProfilePanel({
|
||||
closeAgentSession: handleCloseAgentSession,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { isAgentActivityWindow } from "@/features/agents/lib/agentActivityWindow";
|
||||
import { openAgentActivityWindow } from "@/shared/api/agentActivityWindow";
|
||||
|
||||
type OpenAgentSession = (pubkey: string, channelId?: string | null) => void;
|
||||
|
||||
export function useOpenAgentActivityActions(
|
||||
activeChannelId: string | null,
|
||||
openAgentSession: OpenAgentSession,
|
||||
) {
|
||||
const openInExternalWindow = React.useCallback(
|
||||
(pubkey: string, channelId?: string | null) => {
|
||||
const destinationChannelId = channelId ?? activeChannelId;
|
||||
if (!destinationChannelId) return;
|
||||
|
||||
if (isAgentActivityWindow()) {
|
||||
openAgentSession(pubkey, destinationChannelId);
|
||||
return;
|
||||
}
|
||||
|
||||
void openAgentActivityWindow(destinationChannelId, pubkey)
|
||||
.then((openedNativeWindow) => {
|
||||
if (!openedNativeWindow) {
|
||||
openAgentSession(pubkey, destinationChannelId);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to open agent activity window:", error);
|
||||
toast.error("Couldn't open the agent activity window.");
|
||||
});
|
||||
},
|
||||
[activeChannelId, openAgentSession],
|
||||
);
|
||||
const openInApp = React.useCallback(
|
||||
(pubkey: string, channelId?: string | null) => {
|
||||
openAgentSession(pubkey, channelId ?? activeChannelId);
|
||||
},
|
||||
[activeChannelId, openAgentSession],
|
||||
);
|
||||
|
||||
return { openInApp, openInExternalWindow };
|
||||
}
|
||||
Reference in New Issue
Block a user