Spaces:
Sleeping
Sleeping
eeshaAI commited on
Commit ·
aa6c85a
1
Parent(s): caaae09
fix: real seller names + lower FOMO threshold + interleaved feed (video/product alternating)
Browse files- src/app/page.tsx +30 -10
src/app/page.tsx
CHANGED
|
@@ -51,13 +51,22 @@ export default function HomePage() {
|
|
| 51 |
useEffect(() => {
|
| 52 |
(async () => {
|
| 53 |
try {
|
| 54 |
-
const [vidResp, homeResp, storiesResp, liveResp] = await Promise.all([
|
| 55 |
api.videos.feed(20),
|
| 56 |
api.products.home(),
|
| 57 |
api.stories.activeBar().catch(() => ({ success: false })),
|
| 58 |
api.live.list('live').catch(() => ({ success: false })),
|
|
|
|
| 59 |
]);
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
const posts: FeedPost[] = [];
|
| 62 |
|
| 63 |
// Add video posts
|
|
@@ -92,10 +101,13 @@ export default function HomePage() {
|
|
| 92 |
].filter((p, i, arr) => arr.findIndex(x => x.id === p.id) === i);
|
| 93 |
|
| 94 |
allProducts.forEach((p: Product) => {
|
|
|
|
| 95 |
posts.push({
|
| 96 |
type: 'product',
|
| 97 |
id: `prod-${p.id}`,
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
mediaUrl: p.image_url || '',
|
| 100 |
caption: p.name,
|
| 101 |
likes: Math.floor((p.units_sold || 0) * 0.3),
|
|
@@ -107,10 +119,16 @@ export default function HomePage() {
|
|
| 107 |
});
|
| 108 |
}
|
| 109 |
|
| 110 |
-
//
|
| 111 |
-
posts.
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if (storiesResp.success) {
|
| 116 |
setStories(storiesResp.stories || []);
|
|
@@ -300,10 +318,12 @@ function FeedPostCard({
|
|
| 300 |
|
| 301 |
const isVideo = post.type === 'video';
|
| 302 |
const likeCount = post.likes + (liked ? 1 : 0);
|
| 303 |
-
const fomoText = post.soldCount && post.soldCount >
|
| 304 |
-
? `🔥 ${post.soldCount > 1000 ? `${(post.soldCount / 1000).toFixed(1)}k` : post.soldCount}
|
| 305 |
-
: post.views && post.views >
|
| 306 |
-
? `👀 ${post.views}
|
|
|
|
|
|
|
| 307 |
: null;
|
| 308 |
|
| 309 |
return (
|
|
|
|
| 51 |
useEffect(() => {
|
| 52 |
(async () => {
|
| 53 |
try {
|
| 54 |
+
const [vidResp, homeResp, storiesResp, liveResp, sellersResp] = await Promise.all([
|
| 55 |
api.videos.feed(20),
|
| 56 |
api.products.home(),
|
| 57 |
api.stories.activeBar().catch(() => ({ success: false })),
|
| 58 |
api.live.list('live').catch(() => ({ success: false })),
|
| 59 |
+
api.social.discover(60).catch(() => ({ success: false })),
|
| 60 |
]);
|
| 61 |
|
| 62 |
+
// Build seller name lookup
|
| 63 |
+
const sellerMap = new Map<string, { name: string; image?: string }>();
|
| 64 |
+
if (sellersResp.success) {
|
| 65 |
+
(sellersResp.sellers || []).forEach((s: any) => {
|
| 66 |
+
sellerMap.set(s.id, { name: s.business_name || s.farm_name || 'Seller', image: s.profile_image });
|
| 67 |
+
});
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
const posts: FeedPost[] = [];
|
| 71 |
|
| 72 |
// Add video posts
|
|
|
|
| 101 |
].filter((p, i, arr) => arr.findIndex(x => x.id === p.id) === i);
|
| 102 |
|
| 103 |
allProducts.forEach((p: Product) => {
|
| 104 |
+
const sellerInfo = p.seller_id ? sellerMap.get(p.seller_id) : null;
|
| 105 |
posts.push({
|
| 106 |
type: 'product',
|
| 107 |
id: `prod-${p.id}`,
|
| 108 |
+
sellerId: p.seller_id,
|
| 109 |
+
sellerName: sellerInfo?.name || 'Cellex Seller',
|
| 110 |
+
sellerImage: sellerInfo?.image,
|
| 111 |
mediaUrl: p.image_url || '',
|
| 112 |
caption: p.name,
|
| 113 |
likes: Math.floor((p.units_sold || 0) * 0.3),
|
|
|
|
| 119 |
});
|
| 120 |
}
|
| 121 |
|
| 122 |
+
// Interleave videos and products for variable reward (slot machine effect)
|
| 123 |
+
const videoPosts = posts.filter(p => p.type === 'video');
|
| 124 |
+
const productPosts = posts.filter(p => p.type === 'product');
|
| 125 |
+
const interleaved: FeedPost[] = [];
|
| 126 |
+
const maxLen = Math.max(videoPosts.length, productPosts.length);
|
| 127 |
+
for (let i = 0; i < maxLen; i++) {
|
| 128 |
+
if (i < videoPosts.length) interleaved.push(videoPosts[i]);
|
| 129 |
+
if (i < productPosts.length) interleaved.push(productPosts[i]);
|
| 130 |
+
}
|
| 131 |
+
setFeed(interleaved);
|
| 132 |
|
| 133 |
if (storiesResp.success) {
|
| 134 |
setStories(storiesResp.stories || []);
|
|
|
|
| 318 |
|
| 319 |
const isVideo = post.type === 'video';
|
| 320 |
const likeCount = post.likes + (liked ? 1 : 0);
|
| 321 |
+
const fomoText = post.soldCount && post.soldCount > 5
|
| 322 |
+
? `🔥 ${post.soldCount > 1000 ? `${(post.soldCount / 1000).toFixed(1)}k` : post.soldCount} bought this`
|
| 323 |
+
: post.views && post.views > 50
|
| 324 |
+
? `👀 ${formatCount(post.views)} viewing now`
|
| 325 |
+
: post.soldCount && post.soldCount > 0
|
| 326 |
+
? `✨ ${post.soldCount} bought this`
|
| 327 |
: null;
|
| 328 |
|
| 329 |
return (
|