Skip to content

Commit 30512d9

Browse files
authored
Merge pull request #593 from Priyanka0205-CSE/feat/recently-visited-profiles
feat: add recently visited profiles section on leaderboard
2 parents 2d2e1e9 + ffe6baf commit 30512d9

2 files changed

Lines changed: 48 additions & 28 deletions

File tree

src/pages/GitRank.jsx

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ export const GitRank = () => {
7474
const [repos, setRepos] = useState([]);
7575
const [loadingCharts, setLoadingCharts] = useState(true);
7676
const [chartRateLimitError, setChartRateLimitError] = useState("");
77+
// Issue #585: Recently visited profiles from localStorage
78+
const [recentProfiles] = useState(() => {
79+
try {
80+
return JSON.parse(localStorage.getItem("rh_recently_visited") || "[]");
81+
} catch { return []; }
82+
});
83+
7784
// Jump to My Rank
7885
const [myRank, setMyRank] = useState(null);
7986
const [rankLoading, setRankLoading] = useState(false);
@@ -1047,33 +1054,31 @@ const handleJumpToMyRank = async () => {
10471054

10481055
{/* 3. Leaderboard Table / Search & Filters Controls */}
10491056
<Card className="!p-3 sm:!p-6">
1050-
1051-
{/* Jump to My Rank - Issue #483 */}
1052-
{user && (
1053-
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-3 mb-4">
1054-
<button
1055-
onClick={handleJumpToMyRank}
1056-
disabled={rankLoading}
1057-
className="flex items-center gap-2 px-4 py-2 rounded-xl bg-violet-600 hover:bg-violet-700 disabled:opacity-50 disabled:cursor-not-allowed text-white text-xs font-bold transition-colors shadow-md"
1058-
>
1059-
{rankLoading ? "⏳ Finding rank..." : "📍 My Rank"}
1060-
</button>
1061-
1062-
{myRank && (
1063-
<div className="px-4 py-2 rounded-xl bg-violet-50 dark:bg-violet-500/10 border border-violet-200 dark:border-violet-500/20 text-violet-700 dark:text-violet-300 text-xs font-bold flex items-center gap-2">
1064-
🏅 You are ranked <span className="text-violet-600 dark:text-violet-400 font-black">#{myRank}</span> on the leaderboard
1065-
</div>
1066-
)}
1067-
1068-
{rankError && (
1069-
<div className="px-4 py-2 rounded-xl bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/20 text-amber-700 dark:text-amber-300 text-xs font-bold flex items-center gap-2">
1070-
⚠️ {rankError}
1071-
</div>
1072-
)}
1073-
</div>
1074-
)}
10751057

1076-
{/* NEW TAB SYSTEM FOR REFERRAL LEADERBOARD */}
1058+
1059+
{/* Issue #585: Recently Visited Profiles */}
1060+
{recentProfiles.length > 0 && (
1061+
<div className="mb-5">
1062+
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-2 flex items-center gap-1.5">
1063+
🕐 Recently Visited
1064+
</p>
1065+
<div className="flex flex-wrap gap-2">
1066+
{recentProfiles.map((p) => (
1067+
<a
1068+
key={p.username}
1069+
href={`/dashboard/profile/${encodeURIComponent(p.username)}`}
1070+
className="flex items-center gap-2 px-3 py-1.5 rounded-xl border border-slate-200 dark:border-slate-800 bg-slate-50 dark:bg-slate-900 hover:border-violet-500/40 hover:bg-violet-500/5 transition-all"
1071+
>
1072+
<img src={p.avatar} alt={p.name} className="w-5 h-5 rounded-full object-cover" />
1073+
<span className="text-xs font-bold text-slate-700 dark:text-slate-300">{p.name}</span>
1074+
<span className="text-[10px] text-slate-400">@{p.username}</span>
1075+
</a>
1076+
))}
1077+
</div>
1078+
</div>
1079+
)}
1080+
1081+
{/* NEW TAB SYSTEM FOR REFERRAL LEADERBOARD */}
10771082

10781083
<div className="flex items-center gap-2 mb-6 p-1 bg-slate-100 dark:bg-slate-800/50 rounded-xl w-fit">
10791084
<button
@@ -1293,4 +1298,4 @@ const handleJumpToMyRank = async () => {
12931298
);
12941299
};
12951300

1296-
export default GitRank;
1301+
export default GitRank;

src/pages/Profile.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,22 @@ export const Profile = () => {
7272
const q1 = query(collection(db, "users"), where("githubUsername", "==", username));
7373
const snapshot1 = await getDocs(q1);
7474
if (!snapshot1.empty) {
75-
setPublicProfile(snapshot1.docs[0].data());
75+
const profileData = snapshot1.docs[0].data();
76+
setPublicProfile(profileData);
77+
// Issue #585: Save to recently visited profiles in localStorage
78+
try {
79+
const key = "rh_recently_visited";
80+
const existing = JSON.parse(localStorage.getItem(key) || "[]");
81+
const entry = {
82+
username: profileData.githubUsername,
83+
name: profileData.name,
84+
avatar: profileData.avatar,
85+
visitedAt: Date.now()
86+
};
87+
const filtered = existing.filter(e => e.username !== entry.username);
88+
const updated = [entry, ...filtered].slice(0, 5);
89+
localStorage.setItem(key, JSON.stringify(updated));
90+
} catch (e) { console.error(e); }
7691
} else {
7792
const docRef = doc(db, "users", username);
7893
const docSnap = await getDoc(docRef);

0 commit comments

Comments
 (0)