Edit Feed to allow guest loading and guard realtime
cgen-087dd3448da14c1cb32c445f35184962
This commit is contained in:
parent
15dbb11bcf
commit
49176d45a9
1 changed files with 14 additions and 11 deletions
|
|
@ -66,13 +66,16 @@ export default function Feed() {
|
|||
|
||||
useEffect(() => {
|
||||
ensureDemoSeed();
|
||||
if (!user) return;
|
||||
const load = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const posts = await communityService.getPosts(20);
|
||||
const flw = await aethexSocialService.getFollowing(user.id);
|
||||
setFollowing(flw);
|
||||
if (user?.id) {
|
||||
const flw = await aethexSocialService.getFollowing(user.id);
|
||||
setFollowing(flw);
|
||||
} else {
|
||||
setFollowing([]);
|
||||
}
|
||||
const mapped: FeedItem[] = posts.map((p: any) => {
|
||||
const meta = parseContent(p.content);
|
||||
const author = p.user_profiles || {};
|
||||
|
|
@ -90,7 +93,7 @@ export default function Feed() {
|
|||
});
|
||||
// If no posts yet, fall back to recommended people as placeholders
|
||||
if (mapped.length === 0) {
|
||||
const recs = await aethexSocialService.listRecommended(user.id, 12);
|
||||
const recs = await aethexSocialService.listRecommended(user?.id || "guest", 12);
|
||||
const placeholders: FeedItem[] = recs.map((r: any) => ({
|
||||
id: r.id,
|
||||
authorId: r.id,
|
||||
|
|
@ -116,12 +119,12 @@ export default function Feed() {
|
|||
};
|
||||
load();
|
||||
|
||||
const sub = realtimeService.subscribeToCommunityPosts(() => load());
|
||||
return () => {
|
||||
try {
|
||||
sub.unsubscribe();
|
||||
} catch {}
|
||||
};
|
||||
let cleanup: any = null;
|
||||
try {
|
||||
const sub = realtimeService.subscribeToCommunityPosts(() => load());
|
||||
cleanup = () => { try { sub.unsubscribe?.(); } catch {} };
|
||||
} catch {}
|
||||
return () => { cleanup?.(); };
|
||||
}, [user, loading]);
|
||||
|
||||
const isFollowingAuthor = (id: string) => following.includes(id);
|
||||
|
|
@ -152,7 +155,7 @@ export default function Feed() {
|
|||
} catch {}
|
||||
};
|
||||
|
||||
if (!user && !loading) return <Navigate to="/login" replace />;
|
||||
// Guests can view the feed with demo content
|
||||
if (loading || isLoading) {
|
||||
return (
|
||||
<LoadingScreen
|
||||
|
|
|
|||
Loading…
Reference in a new issue