Fix React Hooks order - move useMemo and useEffect before conditional returns
cgen-c715432288b64226bb95a7b4b0bc467b
This commit is contained in:
parent
2ffc5b2f68
commit
ada7c4024f
1 changed files with 33 additions and 33 deletions
|
|
@ -224,6 +224,39 @@ export default function Admin() {
|
|||
}
|
||||
}, [managedProfiles, selectedMemberId]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
setLoadingPosts(true);
|
||||
const res = await fetch("/api/blog?limit=100");
|
||||
const data = res.ok ? await res.json() : [];
|
||||
if (Array.isArray(data)) setBlogPosts(data);
|
||||
} catch (e) {
|
||||
console.warn("Failed to load blog posts:", e);
|
||||
} finally {
|
||||
setLoadingPosts(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const resolvedBlogPosts = blogPosts.length ? blogPosts : blogSeedPosts;
|
||||
const selectedMember = useMemo(
|
||||
() =>
|
||||
managedProfiles.find((profile) => profile.id === selectedMemberId) ??
|
||||
null,
|
||||
[managedProfiles, selectedMemberId],
|
||||
);
|
||||
|
||||
const totalMembers = managedProfiles.length;
|
||||
const publishedPosts = resolvedBlogPosts.length;
|
||||
const featuredStudios = studios.length;
|
||||
const pendingProjectApplications = projectApplications.filter((app) => {
|
||||
const status = (app.status ?? "").toLowerCase();
|
||||
return (
|
||||
status !== "approved" && status !== "completed" && status !== "closed"
|
||||
);
|
||||
}).length;
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<LoadingScreen
|
||||
|
|
@ -276,39 +309,6 @@ export default function Admin() {
|
|||
);
|
||||
}
|
||||
|
||||
const resolvedBlogPosts = blogPosts.length ? blogPosts : blogSeedPosts;
|
||||
const selectedMember = useMemo(
|
||||
() =>
|
||||
managedProfiles.find((profile) => profile.id === selectedMemberId) ??
|
||||
null,
|
||||
[managedProfiles, selectedMemberId],
|
||||
);
|
||||
|
||||
const totalMembers = managedProfiles.length;
|
||||
const publishedPosts = resolvedBlogPosts.length;
|
||||
const featuredStudios = studios.length;
|
||||
const pendingProjectApplications = projectApplications.filter((app) => {
|
||||
const status = (app.status ?? "").toLowerCase();
|
||||
return (
|
||||
status !== "approved" && status !== "completed" && status !== "closed"
|
||||
);
|
||||
}).length;
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
setLoadingPosts(true);
|
||||
const res = await fetch("/api/blog?limit=100");
|
||||
const data = res.ok ? await res.json() : [];
|
||||
if (Array.isArray(data)) setBlogPosts(data);
|
||||
} catch (e) {
|
||||
console.warn("Failed to load blog posts:", e);
|
||||
} finally {
|
||||
setLoadingPosts(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SEO
|
||||
|
|
|
|||
Loading…
Reference in a new issue