diff --git a/api/follow_startup.php b/api/follow_startup.php new file mode 100644 index 0000000..4745b9d --- /dev/null +++ b/api/follow_startup.php @@ -0,0 +1,45 @@ + false, 'error' => 'Not logged in']); + exit; +} + +$startup_id = $_POST['startup_id'] ?? null; +$action = $_POST['action'] ?? 'follow'; // 'follow' or 'unfollow' + +if (!$startup_id) { + echo json_encode(['success' => false, 'error' => 'Startup ID is required']); + exit; +} + +try { + if ($action === 'follow') { + $stmt = db()->prepare("INSERT IGNORE INTO startup_followers (startup_id, user_id) VALUES (?, ?)"); + $stmt->execute([$startup_id, $user_id]); + + // Update denormalized count + $stmt = db()->prepare("UPDATE startups SET followers_count = (SELECT COUNT(*) FROM startup_followers WHERE startup_id = ?) WHERE id = ?"); + $stmt->execute([$startup_id, $startup_id]); + } else { + $stmt = db()->prepare("DELETE FROM startup_followers WHERE startup_id = ? AND user_id = ?"); + $stmt->execute([$startup_id, $user_id]); + + // Update denormalized count + $stmt = db()->prepare("UPDATE startups SET followers_count = (SELECT COUNT(*) FROM startup_followers WHERE startup_id = ?) WHERE id = ?"); + $stmt->execute([$startup_id, $startup_id]); + } + + // Get new count + $stmt = db()->prepare("SELECT followers_count FROM startups WHERE id = ?"); + $stmt->execute([$startup_id]); + $new_count = $stmt->fetchColumn(); + + echo json_encode(['success' => true, 'new_count' => $new_count]); +} catch (Exception $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); +} diff --git a/discover.php b/discover.php index 350f017..f0f94ff 100644 --- a/discover.php +++ b/discover.php @@ -17,6 +17,11 @@ if ($user_role === 'founder') { } $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; +// Get user's followed startups +$stmt = db()->prepare("SELECT startup_id FROM startup_followers WHERE user_id = ?"); +$stmt->execute([$user_id]); +$followedStartups = $stmt->fetchAll(PDO::FETCH_COLUMN); + // Leaderboard: Most Followed $stmt = db()->query(" SELECT s.*, u.full_name as founder_name @@ -79,13 +84,39 @@ $browseStartups = $stmt->fetchAll(); @media (max-width: 900px) { .leaderboard-grid { grid-template-columns: 1fr; } } .lb-card { background: var(--surface-color); border: 1px solid var(--border-color); border-radius: 16px; padding: 30px; } .lb-title { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; font-size: 20px; font-weight: 800; color: var(--text-primary); } - .lb-item { display: flex; align-items: center; gap: 15px; padding: 15px; background: var(--elevated-color); border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 12px; transition: all 0.3s; text-decoration: none; color: inherit; } + .lb-item { display: flex; align-items: center; gap: 15px; padding: 15px; background: var(--elevated-color); border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 12px; transition: all 0.3s; text-decoration: none; color: inherit; position: relative; } .lb-item:hover { transform: translateX(8px); border-color: var(--accent-primary); } .lb-rank { width: 32px; height: 32px; background: var(--bg-color); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent-primary); font-size: 14px; border: 1px solid var(--border-color); } .rank-1 { background: var(--warning-color); color: #000; border-color: var(--warning-color); } .rank-2 { background: var(--text-secondary); color: #000; border-color: var(--text-secondary); } .rank-3 { background: #cd7f32; color: #000; border-color: #cd7f32; } .startup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 25px; } + + .follow-btn { + background: var(--surface-color); + border: 1px solid var(--border-color); + color: var(--text-primary); + padding: 8px 16px; + border-radius: 50px; + font-size: 12px; + font-weight: 700; + cursor: pointer; + transition: all 0.2s; + display: flex; + align-items: center; + gap: 6px; + z-index: 2; + } + .follow-btn:hover { + border-color: var(--accent-primary); + color: var(--accent-primary); + } + .follow-btn.active { + background: var(--accent-primary); + color: #000; + border-color: var(--accent-primary); + } + .follow-btn i { font-size: 14px; } @@ -126,15 +157,28 @@ $browseStartups = $stmt->fetchAll();
Top Followed
- $s): ?> - -
-
-
-
by
-
-
-
+ $s): + $isFollowing = in_array($s['id'], $followedStartups); + ?> +
@@ -161,16 +205,24 @@ $browseStartups = $stmt->fetchAll();
- -
+ +
-
+
by
+

... @@ -196,6 +248,54 @@ $browseStartups = $stmt->fetchAll();

+ \ No newline at end of file