mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-30 11:26:24 +02:00
navigate directly to chat with search space id
This commit is contained in:
parent
98e12dd195
commit
06f02fba0a
1 changed files with 14 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { useAtomValue } from "jotai";
|
||||
import {
|
||||
BookOpen,
|
||||
Check,
|
||||
|
|
@ -11,7 +12,9 @@ import {
|
|||
PenLine,
|
||||
Search,
|
||||
} from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { searchSpacesAtom } from "@/atoms/search-spaces/search-space-query.atoms";
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
|
|
@ -35,6 +38,8 @@ const ICONS: Record<string, React.ReactNode> = {
|
|||
};
|
||||
|
||||
export default function QuickAskPage() {
|
||||
const router = useRouter();
|
||||
const { data: searchSpaces = [] } = useAtomValue(searchSpacesAtom);
|
||||
const [clipboardText, setClipboardText] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -43,21 +48,24 @@ export default function QuickAskPage() {
|
|||
});
|
||||
}, []);
|
||||
|
||||
const navigateToChat = (prompt: string, mode: string) => {
|
||||
if (!searchSpaces.length) return;
|
||||
const spaceId = searchSpaces[0].id;
|
||||
const encoded = encodeURIComponent(prompt);
|
||||
router.push(`/dashboard/${spaceId}/new-chat?quickAskPrompt=${encoded}&quickAskMode=${mode}`);
|
||||
};
|
||||
|
||||
const handleAction = (actionId: string) => {
|
||||
const action = DEFAULT_ACTIONS.find((a) => a.id === actionId);
|
||||
if (!action || !clipboardText) return;
|
||||
|
||||
const prompt = action.prompt.replace("{selection}", clipboardText);
|
||||
const encoded = encodeURIComponent(prompt);
|
||||
const mode = action.mode;
|
||||
|
||||
window.location.href = `/dashboard?quickAskPrompt=${encoded}&quickAskMode=${mode}`;
|
||||
navigateToChat(prompt, action.mode);
|
||||
};
|
||||
|
||||
const handleAskAnything = () => {
|
||||
if (!clipboardText) return;
|
||||
const encoded = encodeURIComponent(clipboardText);
|
||||
window.location.href = `/dashboard?quickAskPrompt=${encoded}&quickAskMode=explore`;
|
||||
navigateToChat(clipboardText, "explore");
|
||||
};
|
||||
|
||||
const transformActions = DEFAULT_ACTIONS.filter((a) => a.group === "transform");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue