open the prompt file or hub prompt
- added `PromptWithSlug`
This commit is contained in:
parent
98b8ebb84e
commit
dd92bb13a6
1 changed files with 55 additions and 13 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import { parseConfigYaml } from "@continuedev/config-yaml";
|
||||
import {
|
||||
BookmarkIcon as BookmarkOutline,
|
||||
PencilIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
|
||||
import { SlashCommandDescription } from "core";
|
||||
import { useContext } from "react";
|
||||
import { useContext, useMemo } from "react";
|
||||
import { useAuth } from "../../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../../context/IdeMessenger";
|
||||
import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands";
|
||||
import { useAppSelector } from "../../../../redux/hooks";
|
||||
|
|
@ -13,8 +15,10 @@ import { useMainEditor } from "../../TipTapEditor";
|
|||
import { useLump } from "../LumpContext";
|
||||
import { ExploreBlocksButton } from "./ExploreBlocksButton";
|
||||
|
||||
type PromptWithSlug = SlashCommandDescription & { slug?: string };
|
||||
|
||||
interface PromptRowProps {
|
||||
prompt: SlashCommandDescription;
|
||||
prompt: PromptWithSlug;
|
||||
isBookmarked: boolean;
|
||||
setIsBookmarked: (isBookmarked: boolean) => void;
|
||||
onEdit?: () => void;
|
||||
|
|
@ -90,6 +94,7 @@ function PromptRow({
|
|||
* Section that displays all available prompts with bookmarking functionality
|
||||
*/
|
||||
export function PromptsSection() {
|
||||
const { selectedProfile } = useAuth();
|
||||
const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
|
|
@ -97,19 +102,56 @@ export function PromptsSection() {
|
|||
(state) => state.config.config.slashCommands ?? [],
|
||||
);
|
||||
|
||||
const handleEdit = (_prompt: SlashCommandDescription) => {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
});
|
||||
const handleEdit = (prompt: PromptWithSlug) => {
|
||||
if (prompt.promptFile) {
|
||||
ideMessenger.post("openFile", {
|
||||
path: prompt.promptFile,
|
||||
});
|
||||
} else if (prompt.slug) {
|
||||
void ideMessenger.request("controlPlane/openUrl", {
|
||||
path: `${prompt.slug}/new-version`,
|
||||
orgSlug: undefined,
|
||||
});
|
||||
} else {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const sortedCommands = [...slashCommands].sort((a, b) => {
|
||||
const aBookmarked = isCommandBookmarked(a.name);
|
||||
const bBookmarked = isCommandBookmarked(b.name);
|
||||
if (aBookmarked && !bBookmarked) return -1;
|
||||
if (!aBookmarked && bBookmarked) return 1;
|
||||
return 0;
|
||||
});
|
||||
const sortedCommands = useMemo(() => {
|
||||
const promptsWithSlug: PromptWithSlug[] = structuredClone(slashCommands);
|
||||
// get the slugs from rawYaml
|
||||
if (selectedProfile?.rawYaml) {
|
||||
const parsed = parseConfigYaml(selectedProfile.rawYaml);
|
||||
const parsedPrompts = parsed.prompts ?? [];
|
||||
|
||||
let index = 0;
|
||||
for (const prompt of promptsWithSlug) {
|
||||
// skip for local prompt files
|
||||
if (prompt.promptFile) continue;
|
||||
|
||||
const yamlPrompt = parsedPrompts[index];
|
||||
if (yamlPrompt) {
|
||||
if ("uses" in yamlPrompt) {
|
||||
prompt.slug = yamlPrompt.uses;
|
||||
} else {
|
||||
prompt.slug =
|
||||
`${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`;
|
||||
}
|
||||
}
|
||||
index = index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return promptsWithSlug.sort((a, b) => {
|
||||
const aBookmarked = isCommandBookmarked(a.name);
|
||||
const bBookmarked = isCommandBookmarked(b.name);
|
||||
if (aBookmarked && !bBookmarked) return -1;
|
||||
if (!aBookmarked && bBookmarked) return 1;
|
||||
return 0;
|
||||
});
|
||||
}, [slashCommands, isCommandBookmarked, selectedProfile]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue