Skip to content

Commit 211d5c5

Browse files
committed
Enhance UserGridClient and BarList components by adding distance sorting and out-of-range handling. Update MOCK_BARS with distance values for improved functionality.
1 parent f208bc6 commit 211d5c5

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

app/bar/[id]/UserGridClient.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MapPin, Music, Users } from "lucide-react";
77
import Image from "next/image";
88
import { useRouter } from "next/navigation";
99
import { useEffect, useState } from "react";
10+
import { cn } from "@/lib/utils";
1011

1112

1213
interface UserGridClientProps {
@@ -22,6 +23,9 @@ export default function UserGridClient({ bar }: UserGridClientProps) {
2223
const [sortBy, setSortBy] = useState<"newest" | "oldest" | "alphabetical">("newest");
2324
const [loading, setLoading] = useState(true);
2425

26+
// Determine if bar is out of range
27+
const isOutOfRange = parseFloat((bar.distance || '').replace(/[^\d.]/g, '')) > 1;
28+
2529
useEffect(() => {
2630
// Simulate loading data
2731
setLoading(true);
@@ -188,21 +192,29 @@ export default function UserGridClient({ bar }: UserGridClientProps) {
188192
</div>
189193

190194
{/* User List */}
191-
<div className="flex-1 h-full px-0 pt-4 pb-8 overflow-y-auto">
192-
<div className="flex flex-col gap-4 max-w-lg mx-auto">
195+
<div className={"flex-1 h-full px-0 pt-4 pb-8 overflow-y-auto"}>
196+
<div className={cn(
197+
"flex flex-col gap-4 max-w-lg mx-auto",
198+
isOutOfRange && "pointer-events-none"
199+
)}>
193200
{filteredUsers.map((user) => (
194201
<div
195202
key={user.id}
196-
className="bg-card rounded-xl shadow border border-border flex items-center px-4 py-3 gap-3 cursor-pointer hover:bg-muted/60 transition"
197-
onClick={() => router.push(`/profile/${user.id}`)}
203+
className={cn(
204+
"bg-card rounded-xl shadow border border-border flex items-center px-4 py-3 gap-3 transition",
205+
!isOutOfRange && "cursor-pointer hover:bg-muted/60"
206+
)}
207+
onClick={() => {
208+
if (!isOutOfRange) router.push(`/profile/${user.id}`);
209+
}}
198210
>
199211
{/* Profile Image */}
200212
<Image
201213
src={user.avatar || "/default-avatar.png"}
202214
alt={user.username}
203215
width={56}
204216
height={56}
205-
className="rounded-full object-cover border-2 border-theme-pink flex-shrink-0 w-12 h-12"
217+
className={cn("rounded-full object-cover border-2 border-theme-pink flex-shrink-0 w-12 h-12", isOutOfRange && "blur-sm")}
206218
/>
207219
{/* User Info */}
208220
<div className="flex-1 min-w-0">

components/bars/bar-list.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export function BarList() {
3636
return a.isOpen ? -1 : 1;
3737
}
3838

39+
// Then sort by distance (ascending)
40+
const aDist = parseFloat((a.distance || '').replace(/[^\d.]/g, '')) || 9999;
41+
const bDist = parseFloat((b.distance || '').replace(/[^\d.]/g, '')) || 9999;
42+
if (aDist !== bDist) {
43+
return aDist - bDist;
44+
}
45+
3946
// Then sort by number of people (descending)
4047
const aUsers = activeUsersMap[a.id] || 0;
4148
const bUsers = activeUsersMap[b.id] || 0;

lib/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const MOCK_BARS: Bar[] = [
3131
rating: 4.5,
3232
location: "เอกมัย, กรุงเทพฯ",
3333
category: "club",
34+
distance: "0.3 กม.",
3435
features: ["Modern Sound System", "LED & Laser Show", "EDM DJs"],
3536
genre: "EDM",
3637
todaysBand: "YOUNG T",
@@ -47,6 +48,7 @@ export const MOCK_BARS: Bar[] = [
4748
category: "club",
4849
features: ["Festival Vibe", "Multiple Zones", "High Ceiling"],
4950
genre: "EDM",
51+
distance: "1 กม.",
5052
todaysBand: "DJ SODA",
5153
isOpen: true,
5254
coordinates: { lat: 13.735, lng: 100.586 }
@@ -63,6 +65,7 @@ export const MOCK_BARS: Bar[] = [
6365
genre: "แจ๊ส",
6466
todaysBand: "-",
6567
isOpen: true,
68+
distance: "5 กม.",
6669
coordinates: { lat: 13.723, lng: 100.514 }
6770
}
6871
];

0 commit comments

Comments
 (0)