add realtime updates for collection total value in Collection and Community views
This commit is contained in:
@@ -95,6 +95,34 @@ export default function Collection() {
|
|||||||
calculateTotalValue();
|
calculateTotalValue();
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
// Subscribe to realtime updates for collection total value
|
||||||
|
useEffect(() => {
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
const profileChannel = supabase
|
||||||
|
.channel('profile-total-value-changes')
|
||||||
|
.on(
|
||||||
|
'postgres_changes',
|
||||||
|
{
|
||||||
|
event: 'UPDATE',
|
||||||
|
schema: 'public',
|
||||||
|
table: 'profiles',
|
||||||
|
filter: `id=eq.${user.id}`,
|
||||||
|
},
|
||||||
|
(payload: any) => {
|
||||||
|
if (payload.new?.collection_total_value !== undefined) {
|
||||||
|
console.log('Collection total value updated:', payload.new.collection_total_value);
|
||||||
|
setTotalCollectionValue(payload.new.collection_total_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.subscribe();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
supabase.removeChannel(profileChannel);
|
||||||
|
};
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
// Load user's collection from Supabase on mount
|
// Load user's collection from Supabase on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadCollection = async () => {
|
const loadCollection = async () => {
|
||||||
|
|||||||
@@ -405,6 +405,34 @@ export default function Community() {
|
|||||||
};
|
};
|
||||||
}, [selectedUser, hasMoreUserCards, isLoadingMoreUserCards, loadMoreUserCards]);
|
}, [selectedUser, hasMoreUserCards, isLoadingMoreUserCards, loadMoreUserCards]);
|
||||||
|
|
||||||
|
// Subscribe to realtime updates for selected user's collection total value
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedUser) return;
|
||||||
|
|
||||||
|
const userProfileChannel = supabase
|
||||||
|
.channel(`user-profile-value-${selectedUser.id}`)
|
||||||
|
.on(
|
||||||
|
'postgres_changes',
|
||||||
|
{
|
||||||
|
event: 'UPDATE',
|
||||||
|
schema: 'public',
|
||||||
|
table: 'profiles',
|
||||||
|
filter: `id=eq.${selectedUser.id}`,
|
||||||
|
},
|
||||||
|
(payload: any) => {
|
||||||
|
if (payload.new?.collection_total_value !== undefined) {
|
||||||
|
console.log(`User ${selectedUser.username}'s collection total value updated:`, payload.new.collection_total_value);
|
||||||
|
setUserCollectionTotalValue(payload.new.collection_total_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.subscribe();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
supabase.removeChannel(userProfileChannel);
|
||||||
|
};
|
||||||
|
}, [selectedUser]);
|
||||||
|
|
||||||
// ============ FRIENDS FUNCTIONS ============
|
// ============ FRIENDS FUNCTIONS ============
|
||||||
const loadFriendsData = async () => {
|
const loadFriendsData = async () => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user