From b536bb92d64875eef2acc66be9be8cfefcdee801 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 23:08:18 +0000 Subject: [PATCH] Use Supabase only for social service cgen-f7efa9713fc7429e8239a46f709003cc --- client/lib/aethex-social-service.ts | 87 ++++++++++++++--------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/client/lib/aethex-social-service.ts b/client/lib/aethex-social-service.ts index 6918ce6e..0d754836 100644 --- a/client/lib/aethex-social-service.ts +++ b/client/lib/aethex-social-service.ts @@ -1,5 +1,7 @@ import { supabase } from "./supabase"; +import { supabase } from "./supabase"; + export const aethexSocialService = { async listRecommended(userId: string, limit = 10) { try { @@ -7,15 +9,18 @@ export const aethexSocialService = { .from("user_profiles") .select("id, username, full_name, avatar_url, bio") .neq("id", userId) + .order("updated_at", { ascending: false }) .limit(limit); - if (!error && data) return data as any[]; - } catch {} - try { - const raw = localStorage.getItem("demo_profiles"); - const profiles = raw ? JSON.parse(raw) : []; - return profiles.filter((p: any) => p.id !== userId).slice(0, limit); - } catch { - return [] as any[]; + + if (error) { + console.error("Failed to load recommended profiles:", error); + return []; + } + + return (data || []) as any[]; + } catch (error) { + console.error("Unexpected error loading recommended profiles:", error); + return []; } }, @@ -25,49 +30,39 @@ export const aethexSocialService = { .from("user_follows") .select("following_id") .eq("follower_id", userId); - if (!error && data) - return (data as any[]).map((r: any) => r.following_id); - } catch {} - try { - const raw = localStorage.getItem("mock_follows"); - const map = raw ? JSON.parse(raw) : {}; - return map[userId] || []; - } catch {} - return []; + + if (error) { + console.error("Failed to load following list:", error); + return []; + } + + return (data as any[]).map((r: any) => r.following_id); + } catch (error) { + console.error("Unexpected error loading following list:", error); + return []; + } }, async followUser(followerId: string, followingId: string): Promise { - try { - const { error } = await supabase.from("user_follows").insert({ - follower_id: followerId, - following_id: followingId, - }); - if (!error) return; - } catch {} - const raw = localStorage.getItem("mock_follows"); - const map = raw ? JSON.parse(raw) : {}; - const set: string[] = Array.from( - new Set([...(map[followerId] || []), followingId]), - ); - map[followerId] = set; - localStorage.setItem("mock_follows", JSON.stringify(map)); + const { error } = await supabase.from("user_follows").insert({ + follower_id: followerId, + following_id: followingId, + }); + + if (error) { + throw new Error(error.message || "Unable to follow user"); + } }, async unfollowUser(followerId: string, followingId: string): Promise { - try { - await supabase - .from("user_follows") - .delete() - .eq("follower_id", followerId) - .eq("following_id", followingId); - return; - } catch {} - const raw = localStorage.getItem("mock_follows"); - const map = raw ? JSON.parse(raw) : {}; - const list: string[] = (map[followerId] || []).filter( - (id: string) => id !== followingId, - ); - map[followerId] = list; - localStorage.setItem("mock_follows", JSON.stringify(map)); + const { error } = await supabase + .from("user_follows") + .delete() + .eq("follower_id", followerId) + .eq("following_id", followingId); + + if (error) { + throw new Error(error.message || "Unable to unfollow user"); + } }, };