feat(webui): add catalog loading skeletons (#6092)

* feat(webui): add catalog loading skeletons

* feat(webui): add MCP tool loading skeleton

* fix(webui): make skill discovery skeletons visible

* refactor(webui): share skeleton status markup
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-07 21:28:53 +08:00
1 parent 7cb396788c
commit f24969d282
25 files changed
+538 -99

No files matched your search

+19 -6
View File
@@ -4,8 +4,14 @@ import { fetchSkills } from "@/lib/api";
import { isSkillsPayload, SKILLS_CHANGED_EVENT, SKILLS_REFRESH_EVENT } from "@/lib/skill-events";
import type { SkillSummary } from "@/lib/types";
export function useSkills(getToken: () => string): SkillSummary[] {
const [skills, setSkills] = useState<SkillSummary[]>([]);
type SkillsState =
| { status: "loading" | "error"; skills: null }
| { status: "ready"; skills: SkillSummary[] };
const EMPTY_SKILLS: SkillSummary[] = [];
export function useSkills(getToken: () => string) {
const [state, setState] = useState<SkillsState>({ status: "loading", skills: null });
useEffect(() => {
let cancelled = false;
@@ -21,13 +27,16 @@ export function useSkills(getToken: () => string): SkillSummary[] {
}
refreshing = true;
refreshQueued = false;
setState((current) => current.skills === null ? { status: "loading", skills: null } : current);
const version = payloadVersion;
fetchSkills(getToken())
.then(({ skills: nextSkills }) => {
if (!cancelled && version === payloadVersion) setSkills(nextSkills);
if (!cancelled && version === payloadVersion) setState({ status: "ready", skills: nextSkills });
})
.catch(() => {
// Keep the last known list usable during transient refresh failures.
if (!cancelled && version === payloadVersion) {
setState((current) => current.skills === null ? { status: "error", skills: null } : current);
}
})
.finally(() => {
refreshing = false;
@@ -38,7 +47,7 @@ export function useSkills(getToken: () => string): SkillSummary[] {
const payload = (event as CustomEvent<unknown>).detail;
if (!cancelled && isSkillsPayload(payload)) {
payloadVersion += 1;
setSkills(payload.skills);
setState({ status: "ready", skills: payload.skills });
}
};
@@ -52,5 +61,9 @@ export function useSkills(getToken: () => string): SkillSummary[] {
};
}, [getToken]);
return skills;
return {
skills: state.skills ?? EMPTY_SKILLS,
loading: state.status === "loading",
error: state.status === "error",
};
}