fix: get real skill count by awaiting discovery after adding repo

The previous approach computed count before discovery, so it was always 0.
Now we await refetchDiscoverable() after the mutation, then filter the
fresh skills list to get the actual count for the toast message.

Also reverts the SkillRepo.count field — keep the interface clean since
count is a transient UI concern, not a data model property.
This commit is contained in:
Jason
2026-03-07 21:45:54 +08:00
parent ea13395207
commit ebf407e46b
4 changed files with 12 additions and 12 deletions
+1 -5
View File
@@ -74,15 +74,11 @@ export function RepoManager({
}
try {
const repoToAdd: SkillRepo = {
await onAdd({
owner: parsed.owner,
name: parsed.name,
branch: branch || "main",
enabled: true,
};
await onAdd({
...repoToAdd,
count: getSkillCount(repoToAdd),
});
setRepoUrl("");
+1 -5
View File
@@ -61,15 +61,11 @@ export function RepoManagerPanel({
}
try {
const repoToAdd: SkillRepo = {
await onAdd({
owner: parsed.owner,
name: parsed.name,
branch: branch || "main",
enabled: true,
};
await onAdd({
...repoToAdd,
count: getSkillCount(repoToAdd),
});
setRepoUrl("");
+10 -1
View File
@@ -164,11 +164,20 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
const handleAddRepo = async (repo: SkillRepo) => {
try {
await addRepoMutation.mutateAsync(repo);
// Await discovery so we can report the real count
const { data: freshSkills } = await refetchDiscoverable();
const count =
freshSkills?.filter(
(s) =>
s.repoOwner === repo.owner &&
s.repoName === repo.name &&
(s.repoBranch || "main") === (repo.branch || "main"),
).length ?? 0;
toast.success(
t("skills.repo.addSuccess", {
owner: repo.owner,
name: repo.name,
count: repo.count || 0,
count,
}),
{ closeButton: true },
);
-1
View File
@@ -67,7 +67,6 @@ export interface SkillRepo {
name: string;
branch: string;
enabled: boolean;
count?: number;
}
// ========== API ==========