Skip to content

Commit

Permalink
Fix button status on imported skill change
Browse files Browse the repository at this point in the history
show alert on skill change
Update markdown type and theme on import of agent skill
  • Loading branch information
timothycarambat committed Nov 25, 2024
1 parent bdc3477 commit 3fe10db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/WorkspaceChat/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function copyCodeSnippet(uuid) {
}

// Listens and hunts for all data-code-snippet clicks.
function setEventDelegatorForCodeSnippets() {
export function setEventDelegatorForCodeSnippets() {
document?.addEventListener("click", function (e) {
const target = e.target.closest("[data-code-snippet]");
const uuidCode = target?.dataset?.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default function ImportedSkillConfig({
prev.map((s) => (s.hubId === config.hubId ? updatedConfig : s))
);
setConfig(updatedConfig);
showToast(
`Skill ${updatedConfig.active ? "activated" : "deactivated"}.`,
"success",
{ clear: true }
);
}

async function handleSubmit(e) {
Expand Down Expand Up @@ -91,6 +96,7 @@ export default function ImportedSkillConfig({
)
);
showToast("Skill config updated successfully.", "success");
setHasChanges(false);
}

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useEffect, useState } from "react";
import renderMarkdown from "@/utils/chat/markdown";
import DOMPurify from "dompurify";
import CommunityHub from "@/models/communityHub";
import { setEventDelegatorForCodeSnippets } from "@/components/WorkspaceChat";

export default function AgentSkill({ item, settings, setStep }) {
const [loading, setLoading] = useState(false);
Expand All @@ -30,6 +31,10 @@ export default function AgentSkill({ item, settings, setStep }) {
}
}

useEffect(() => {
setEventDelegatorForCodeSnippets();
}, []);

return (
<div className="flex flex-col mt-4 gap-y-4">
<div className="border border-white/10 light:border-orange-500/20 my-2 flex flex-col md:flex-row md:items-center gap-x-2 text-theme-text-primary mb-4 bg-orange-800/30 light:bg-orange-500/10 rounded-lg px-4 py-2">
Expand Down Expand Up @@ -112,11 +117,6 @@ function FileReview({ item }) {
const files = item.manifest.files || [];
const [index, setIndex] = useState(0);
const [file, setFile] = useState(files[index]);

useEffect(() => {
if (files.length > 0) setFile(files?.[index] || files[0]);
}, [index]);

function handlePrevious() {
if (index > 0) setIndex(index - 1);
}
Expand All @@ -125,6 +125,24 @@ function FileReview({ item }) {
if (index < files.length - 1) setIndex(index + 1);
}

function fileMarkup(file) {
const extension = file.name.split(".").pop();
switch (extension) {
case "js":
return "javascript";
case "json":
return "json";
case "md":
return "markdown";
default:
return "text";
}
}

useEffect(() => {
if (files.length > 0) setFile(files?.[index] || files[0]);
}, [index]);

if (!file) return null;
return (
<div className="flex flex-col gap-y-2">
Expand Down Expand Up @@ -153,10 +171,12 @@ function FileReview({ item }) {
</button>
</div>
<span
className="whitespace-pre-line flex flex-col gap-y-1 text-sm leading-[20px] max-h-[500px] overflow-y-auto"
className="whitespace-pre-line flex flex-col gap-y-1 text-sm leading-[20px] max-h-[500px] overflow-y-auto hljs"
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(
renderMarkdown(`\`\`\`javascript\n${file.content}\n\`\`\``)
renderMarkdown(
`\`\`\`${fileMarkup(file)}\n${file.content}\n\`\`\``
)
),
}}
/>
Expand Down

0 comments on commit 3fe10db

Please sign in to comment.