mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
fix(skills): install correct skill from skills.sh search results (#2784)
* fix(skills): install correct skill from skills.sh search results When multiple skills share the same directory name across different repos, SkillCard was passing directory to onInstall/onUninstall, causing handleInstall to always match the first result. Switch to using the unique key field (directory:repoOwner:repoName) for precise identification. * test(skills): add regression test for skills.sh install by key Verifies that clicking install on the second card when two skills share the same directory name correctly installs the second skill, not the first. --------- Co-authored-by: mrzhao <mrzhao@iflytek.com>
This commit is contained in:
@@ -18,8 +18,8 @@ type SkillCardSkill = DiscoverableSkill & { installed: boolean };
|
||||
|
||||
interface SkillCardProps {
|
||||
skill: SkillCardSkill;
|
||||
onInstall: (directory: string) => Promise<void>;
|
||||
onUninstall: (directory: string) => Promise<void>;
|
||||
onInstall: (key: string) => Promise<void>;
|
||||
onUninstall: (key: string) => Promise<void>;
|
||||
installs?: number;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function SkillCard({
|
||||
const handleInstall = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await onInstall(skill.directory);
|
||||
await onInstall(skill.key);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export function SkillCard({
|
||||
const handleUninstall = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await onUninstall(skill.directory);
|
||||
await onUninstall(skill.key);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -194,20 +194,16 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
readmeUrl: s.readmeUrl,
|
||||
});
|
||||
|
||||
const handleInstall = async (directory: string) => {
|
||||
const handleInstall = async (key: string) => {
|
||||
let skill: DiscoverableSkill | undefined;
|
||||
|
||||
if (searchSource === "skillssh") {
|
||||
const found = accumulatedResults.find((s) => s.directory === directory);
|
||||
const found = accumulatedResults.find((s) => s.key === key);
|
||||
if (found) {
|
||||
skill = toDiscoverableSkill(found);
|
||||
}
|
||||
} else {
|
||||
skill = discoverableSkills?.find(
|
||||
(s) =>
|
||||
s.directory === directory ||
|
||||
s.directory.split("/").pop() === directory,
|
||||
);
|
||||
skill = discoverableSkills?.find((s) => s.key === key);
|
||||
}
|
||||
|
||||
if (!skill) {
|
||||
|
||||
Reference in New Issue
Block a user