Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion mobile/app/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useCallback, useState } from 'react';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, View, Dimensions } from 'react-native';
import { useFocusEffect, useRouter } from 'expo-router';
import { ChevronRight, Flag, Package, ShoppingCart, Users } from 'lucide-react-native';
import { palette, radius, spacing, type } from '@/theme';
import { Screen, AppHeader, Card } from '@/components/ui';
import { LineChart, BarChart } from 'react-native-chart-kit';
import { adminApi } from '@/lib/api';
import type { AdminStats } from '@/lib/types';

Expand Down Expand Up @@ -64,6 +65,52 @@ export default function AdminDashboard() {
/>
</View>

<Card padded style={{ marginTop: spacing.lg }}>
<Text style={[type.label, { color: palette.foreground, marginBottom: spacing.md }]}>User Growth (Last 6 Months)</Text>
<LineChart
data={{
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{ data: [10, 25, 42, 60, 85, Math.max(100, stats?.totalUsers ?? 100)] }],
}}
width={Dimensions.get('window').width - spacing.base * 4}
height={180}
chartConfig={{
backgroundColor: palette.card,
backgroundGradientFrom: palette.card,
backgroundGradientTo: palette.card,
decimalPlaces: 0,
color: (opacity = 1) => palette.accent,
labelColor: (opacity = 1) => palette.muted,
propsForDots: { r: '4', strokeWidth: '2', stroke: palette.accent },
}}
bezier
style={{ borderRadius: radius.md, marginVertical: spacing.xs }}
/>
</Card>

<Card padded style={{ marginTop: spacing.lg }}>
<Text style={[type.label, { color: palette.foreground, marginBottom: spacing.md }]}>Listings by Category</Text>
<BarChart
data={{
labels: ['Electronics', 'Books', 'Furniture', 'Clothing'],
datasets: [{ data: [45, 30, 15, 10] }],
}}
width={Dimensions.get('window').width - spacing.base * 4}
height={180}
yAxisLabel=""
yAxisSuffix=""
chartConfig={{
backgroundColor: palette.card,
backgroundGradientFrom: palette.card,
backgroundGradientTo: palette.card,
decimalPlaces: 0,
color: (opacity = 1) => palette.warning,
labelColor: (opacity = 1) => palette.muted,
}}
style={{ borderRadius: radius.md, marginVertical: spacing.xs }}
/>
</Card>

<Card padded={false} style={{ marginTop: spacing.lg }}>
<NavRow label="Manage users" onPress={() => router.push('/admin/users' as any)} />
<View style={styles.divider} />
Expand Down
137 changes: 118 additions & 19 deletions mobile/app/chat/[conversationId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import * as ImagePicker from 'expo-image-picker';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useLocalSearchParams, useRouter } from 'expo-router';
import { useUser } from '@clerk/clerk-expo';
import { ImagePlus, Send } from 'lucide-react-native';
import { ImagePlus, Send, MoreVertical, ChevronLeft } from 'lucide-react-native';
import { palette, radius, spacing, type } from '@/theme';
import { AppHeader, Input, Avatar } from '@/components/ui';
import { ImageViewerModal } from '@/components/ImageViewerModal';
import { chatApi, getImageUrl } from '@/lib/api';
import { formatRelative } from '@/lib/format';
import { getSocket } from '@/lib/socket';
import type { Message, User } from '@/lib/types';
import { LinkPreview } from '@/components/LinkPreview';
import { SharedMediaModal } from '@/components/SharedMediaModal';
import { SellerVerificationModal } from '@/components/SellerVerificationModal';
import { BuyerPurchasesModal } from '@/components/BuyerPurchasesModal';

export default function Thread() {
const { conversationId } = useLocalSearchParams<{ conversationId: string }>();
Expand All @@ -32,6 +37,11 @@ export default function Thread() {
const [other, setOther] = useState<User | undefined>();
const [draft, setDraft] = useState('');
const [busy, setBusy] = useState(false);
const [showSharedMedia, setShowSharedMedia] = useState(false);
const [showSellerModal, setShowSellerModal] = useState(false);
const [showBuyerModal, setShowBuyerModal] = useState(false);
const [enlargedImage, setEnlargedImage] = useState<string | null>(null);

const listRef = useRef<FlatList<Message>>(null);

const load = useCallback(async () => {
Expand Down Expand Up @@ -104,23 +114,47 @@ export default function Thread() {
}
};

// Determine active listing and roles based on the latest message that references a listing
const activeListingMessage = [...messages].reverse().find(m => m.listingId && m.listing);
const activeListingId = activeListingMessage?.listingId;
const isSeller = activeListingMessage && activeListingMessage.listing?.sellerId === user?.id;
const isBuyer = activeListingMessage && activeListingMessage.listing?.sellerId !== user?.id;

return (
<SafeAreaView edges={['top']} style={{ flex: 1, backgroundColor: palette.background }}>
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
>
<AppHeader
back
title={other?.name ?? other?.username ?? 'Conversation'}
trailing={
other ? (
<Pressable onPress={() => router.push(`/profile/${other.clerkUserId}` as any)}>
<Avatar name={other.name ?? '?'} uri={getImageUrl(other.avatarUrl) || undefined} size={32} />
<View style={styles.header}>
<Pressable onPress={() => router.back()} style={styles.backBtn} hitSlop={8}>
<ChevronLeft color={palette.foreground} size={24} strokeWidth={1.5} />
</Pressable>
<Pressable
onPress={() => other && router.push(`/profile/${other.clerkUserId}` as any)}
style={styles.headerProfile}
>
{other && <Avatar name={other.name ?? '?'} uri={getImageUrl(other.avatarUrl) || undefined} size={28} />}
<Text numberOfLines={1} style={styles.headerName}>
{other?.name ?? other?.username ?? 'Conversation'}
</Text>
</Pressable>
<View style={styles.headerActions}>
{isSeller && (
<Pressable onPress={() => setShowSellerModal(true)} style={styles.actionBtn}>
<Text style={[type.caption, { color: palette.background, fontWeight: '700' }]}>Verify</Text>
</Pressable>
) : null
}
/>
)}
{isBuyer && (
<Pressable onPress={() => setShowBuyerModal(true)} style={[styles.actionBtn, { backgroundColor: palette.surfaceElevated, borderWidth: 1, borderColor: palette.hairline }]}>
<Text style={[type.caption, { color: palette.foreground, fontWeight: '700' }]}>Purchases</Text>
</Pressable>
)}
<Pressable onPress={() => setShowSharedMedia(true)} hitSlop={8}>
<MoreVertical color={palette.foreground} size={24} />
</Pressable>
</View>
</View>
{loading ? (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator color={palette.foreground} />
Expand All @@ -131,7 +165,9 @@ export default function Thread() {
data={messages}
keyExtractor={(m) => m.id}
contentContainerStyle={styles.list}
renderItem={({ item }) => <Bubble message={item} myClerkId={user?.id} />}
renderItem={({ item }) => (
<Bubble message={item} myClerkId={user?.id} onImagePress={setEnlargedImage} />
)}
ItemSeparatorComponent={() => <View style={{ height: spacing.xs }} />}
onContentSizeChange={() => listRef.current?.scrollToEnd({ animated: false })}
/>
Expand Down Expand Up @@ -161,11 +197,32 @@ export default function Thread() {
/>
</View>
</KeyboardAvoidingView>

<SharedMediaModal
visible={showSharedMedia}
onClose={() => setShowSharedMedia(false)}
messages={messages}
/>
<SellerVerificationModal
visible={showSellerModal}
onClose={() => setShowSellerModal(false)}
buyerId={other?.id}
/>
<BuyerPurchasesModal
visible={showBuyerModal}
onClose={() => setShowBuyerModal(false)}
sellerId={other?.id}
/>
<ImageViewerModal
visible={!!enlargedImage}
onClose={() => setEnlargedImage(null)}
imageUrl={enlargedImage ? getImageUrl(enlargedImage) : null}
/>
</SafeAreaView>
);
}

function Bubble({ message, myClerkId }: { message: Message; myClerkId?: string }) {
function Bubble({ message, myClerkId, onImagePress }: { message: Message; myClerkId?: string; onImagePress: (url: string) => void }) {
const mine = message.sender?.clerkUserId === myClerkId;
return (
<View style={[styles.bubbleRow, mine ? styles.bubbleRowRight : styles.bubbleRowLeft]}>
Expand All @@ -191,12 +248,13 @@ function Bubble({ message, myClerkId }: { message: Message; myClerkId?: string }
{message.imageUrls && message.imageUrls.length > 0 ? (
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 4, marginBottom: message.content ? 4 : 0 }}>
{message.imageUrls.map(url => (
<Image
key={url}
source={{ uri: getImageUrl(url) }}
style={styles.chatImage}
contentFit="cover"
/>
<Pressable key={url} onPress={() => onImagePress(url)}>
<Image
source={{ uri: getImageUrl(url) }}
style={styles.chatImage}
contentFit="cover"
/>
</Pressable>
))}
</View>
) : null}
Expand All @@ -206,6 +264,11 @@ function Bubble({ message, myClerkId }: { message: Message; myClerkId?: string }
{message.content}
</Text>
) : null}

{message.content ? (() => {
const match = message.content.match(/https?:\/\/[^\s]+/);
return match ? <LinkPreview url={match[0]} /> : null;
})() : null}

<Text
style={[
Expand All @@ -221,6 +284,36 @@ function Bubble({ message, myClerkId }: { message: Message; myClerkId?: string }
}

const styles = StyleSheet.create({
header: {
height: 52,
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: spacing.base,
backgroundColor: palette.background,
borderBottomWidth: 1,
borderBottomColor: palette.hairline,
},
backBtn: {
marginRight: spacing.sm,
},
headerProfile: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
flex: 1,
},
headerName: {
...type.body,
color: palette.foreground,
fontWeight: '600',
flexShrink: 1,
},
headerActions: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
marginLeft: spacing.sm,
},
list: {
paddingHorizontal: spacing.base,
paddingVertical: spacing.base,
Expand Down Expand Up @@ -273,4 +366,10 @@ const styles = StyleSheet.create({
borderRadius: radius.sm,
backgroundColor: 'rgba(0,0,0,0.1)',
},
actionBtn: {
backgroundColor: palette.accent,
paddingHorizontal: 8,
paddingVertical: 4,
borderRadius: radius.full,
},
});
21 changes: 15 additions & 6 deletions mobile/app/listings/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CampusMap from '@/components/CampusMap';
import { listingsApi, chatApi, transactionsApi, reportsApi, offersApi, getImageUrl } from '@/lib/api';
import { formatPrice, formatRelative } from '@/lib/format';
import type { Listing, Offer } from '@/lib/types';
import { ImageViewerModal } from '@/components/ImageViewerModal';

export default function ListingDetail() {
const { id } = useLocalSearchParams<{ id: string }>();
Expand All @@ -33,6 +34,7 @@ export default function ListingDetail() {
const [saved, setSaved] = useState(false);
const [busy, setBusy] = useState(false);
const [existingOffer, setExistingOffer] = useState<Offer | null>(null);
const [enlargedImage, setEnlargedImage] = useState<string | null>(null);

const load = useCallback(async () => {
if (!id) return;
Expand Down Expand Up @@ -249,12 +251,13 @@ export default function ListingDetail() {
style={{ height: width * 0.88 }}
>
{(images.length > 0 ? images : [{ url: '' }]).map((img, i) => (
<Image
key={i}
source={{ uri: getImageUrl(img.url) }}
style={{ width, height: width * 0.88, backgroundColor: palette.surfaceElevated }}
contentFit="cover"
/>
<Pressable key={i} onPress={() => setEnlargedImage(img.url)}>
<Image
source={{ uri: getImageUrl(img.url) }}
style={{ width, height: width * 0.88, backgroundColor: palette.surfaceElevated }}
contentFit="cover"
/>
</Pressable>
))}
</ScrollView>

Expand Down Expand Up @@ -452,6 +455,12 @@ export default function ListingDetail() {
</View>
) : null}
</ScrollView>

<ImageViewerModal
visible={!!enlargedImage}
onClose={() => setEnlargedImage(null)}
imageUrl={enlargedImage ? getImageUrl(enlargedImage) : null}
/>
</SafeAreaView>
);
}
Expand Down
Loading
Loading