Skip to content

Commit bef11f8

Browse files
committed
Enhance token allocation UI: bigger controls, consistent data, rounded corners
- Fix token allocation inconsistency by implementing shared TokenBalanceContext - Increase plus/minus button size from 6x6 to 8x8 with 4x4 icons - Remove outer container background and reduce card padding for better screen real estate - Add rounded corners (rounded-md) to all token bar sections with 4px gaps - Implement optimistic updates for immediate UI feedback - Ensure consistent available token display across all components - Clean, minimal design that maximizes usable space
1 parent 925fda9 commit bef11f8

File tree

11 files changed

+372
-55
lines changed

11 files changed

+372
-55
lines changed

app/api/subscription-history/route.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import { NextRequest, NextResponse } from 'next/server';
1111
import { getUserIdFromRequest } from '../auth-helper';
1212
import { getCollectionName } from '../../utils/environmentConfig';
13-
import { initAdmin } from '../../firebase/admin';
13+
import { getFirebaseAdmin } from '../../firebase/firebaseAdmin';
1414
import Stripe from 'stripe';
1515

16-
// Initialize Firebase Admin
17-
const admin = initAdmin();
18-
const db = admin.firestore();
1916
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
2017
apiVersion: '2023-10-16',
2118
});
@@ -42,7 +39,7 @@ interface SubscriptionHistoryEvent {
4239
source: 'stripe' | 'system' | 'user';
4340
}
4441

45-
async function getSubscriptionHistory(userId: string): Promise<SubscriptionHistoryEvent[]> {
42+
async function getSubscriptionHistory(userId: string, db: any): Promise<SubscriptionHistoryEvent[]> {
4643
const events: SubscriptionHistoryEvent[] = [];
4744

4845
try {
@@ -252,6 +249,10 @@ export async function GET(request: NextRequest) {
252249
try {
253250
console.log('[SUBSCRIPTION HISTORY API] Starting request');
254251

252+
// Initialize Firebase Admin
253+
const admin = getFirebaseAdmin();
254+
const db = admin.firestore();
255+
255256
// Get authenticated user ID
256257
const userId = await getUserIdFromRequest(request);
257258
if (!userId) {
@@ -272,7 +273,7 @@ export async function GET(request: NextRequest) {
272273
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
273274
}
274275

275-
const history = await getSubscriptionHistory(targetUserId);
276+
const history = await getSubscriptionHistory(targetUserId, db);
276277

277278
console.log(`[SUBSCRIPTION HISTORY API] Successfully fetched ${history.length} events for user ${targetUserId}`);
278279

app/api/subscription/cancel/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import { NextRequest, NextResponse } from 'next/server';
88
import { getUserIdFromRequest } from '../../auth-helper';
99
import { getSubCollectionPath, PAYMENT_COLLECTIONS } from '../../../utils/environmentConfig';
10-
import { initAdmin } from '../../../firebase/admin';
10+
import { getFirebaseAdmin } from '../../../firebase/firebaseAdmin';
1111
import { subscriptionAuditService } from '../../../services/subscriptionAuditService';
12-
13-
// Initialize Firebase Admin
14-
const admin = initAdmin();
15-
const adminDb = admin.firestore();
1612
import { serverTimestamp } from 'firebase-admin/firestore';
1713

1814
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
1915

2016
export async function POST(request: NextRequest) {
2117
try {
18+
// Initialize Firebase Admin
19+
const admin = getFirebaseAdmin();
20+
const adminDb = admin.firestore();
21+
2222
// Get authenticated user
2323
const userId = await getUserIdFromRequest(request);
2424
if (!userId) {

app/api/tokens/pending-allocations/route.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { NextRequest, NextResponse } from 'next/server';
99
import { getUserIdFromRequest } from '../../auth-helper';
1010
import { PendingTokenAllocationService } from '../../../services/pendingTokenAllocationService';
11+
import { ServerTokenService } from '../../../services/tokenService.server';
1112
import { getDoc, doc } from 'firebase/firestore';
1213
import { db } from '../../../firebase/config';
1314
import { getCollectionName } from "../../../utils/environmentConfig";
@@ -59,7 +60,7 @@ export async function POST(request: NextRequest) {
5960
}
6061

6162
const body = await request.json();
62-
const { recipientUserId, resourceType, resourceId, tokens } = body;
63+
const { recipientUserId, resourceType, resourceId, tokens, source } = body;
6364

6465
// Validate input
6566
if (!recipientUserId || !resourceType || !resourceId || !tokens) {
@@ -138,10 +139,20 @@ export async function POST(request: NextRequest) {
138139
}, { status: 400 });
139140
}
140141

141-
// Get updated summary
142-
const updatedSummary = await PendingTokenAllocationService.getUserAllocationSummary(userId);
142+
// Get updated summary, current allocation, and balance
143+
const [updatedSummary, currentAllocation, balance] = await Promise.all([
144+
PendingTokenAllocationService.getUserAllocationSummary(userId),
145+
PendingTokenAllocationService.getCurrentPageAllocation(userId, resourceId),
146+
ServerTokenService.getUserTokenBalance(userId)
147+
]);
148+
149+
// Log allocation with source tracking
150+
console.log(`Pending tokens allocated: ${tokens} from ${userId} to ${recipientUserId} for ${resourceType}:${resourceId} (source: ${source || 'unknown'})`);
143151

144-
console.log(`Pending tokens allocated: ${tokens} from ${userId} to ${recipientUserId} for ${resourceType}:${resourceId}`);
152+
// Track allocation source for analytics
153+
if (source) {
154+
console.log(`[ANALYTICS] TokenAllocation: source=${source}, tokens=${tokens}, resourceType=${resourceType}, userId=${userId}`);
155+
}
145156

146157
return NextResponse.json({
147158
success: true,
@@ -152,7 +163,13 @@ export async function POST(request: NextRequest) {
152163
resourceType,
153164
resourceId
154165
},
155-
summary: updatedSummary
166+
summary: updatedSummary,
167+
currentAllocation: currentAllocation,
168+
balance: {
169+
totalTokens: balance?.totalTokens || 0,
170+
allocatedTokens: balance?.allocatedTokens || 0,
171+
availableTokens: (balance?.totalTokens || 0) - (balance?.allocatedTokens || 0)
172+
}
156173
});
157174

158175
} catch (error) {

app/api/tokens/pledge-bar-data/route.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ export async function GET(request: NextRequest) {
3232
PendingTokenAllocationService.getCurrentPageAllocation(userId, pageId)
3333
]);
3434

35+
console.log(`🎯 [PLEDGE_BAR_DATA] pageId=${pageId}, userId=${userId}, currentAllocation=${currentAllocation}`);
36+
3537
// Calculate basic token info
3638
const totalTokens = balance?.totalTokens || 0;
3739
const allocatedTokens = balance?.allocatedTokens || 0;
3840
const availableTokens = totalTokens - allocatedTokens;
3941

40-
return NextResponse.json({
42+
const responseData = {
4143
success: true,
4244
data: {
4345
tokenBalance: {
@@ -49,8 +51,18 @@ export async function GET(request: NextRequest) {
4951
currentPageAllocation: currentAllocation,
5052
hasSubscription: !!balance && totalTokens > 0
5153
}
54+
};
55+
56+
console.log(`🎯 [PLEDGE_BAR_DATA] Response for pageId=${pageId}, userId=${userId}:`, {
57+
totalTokens,
58+
allocatedTokens,
59+
availableTokens,
60+
currentPageAllocation: currentAllocation,
61+
hasSubscription: !!balance && totalTokens > 0
5262
});
5363

64+
return NextResponse.json(responseData);
65+
5466
} catch (error) {
5567
console.error('Error getting pledge bar data:', error);
5668
return NextResponse.json(

app/components/activity/ActivityCard.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useDateFormat } from "../../contexts/DateFormatContext";
2424
import { useToast } from "../ui/use-toast";
2525
import { Button } from "../ui/button";
2626
import { RotateCcw } from "lucide-react";
27+
import { EmbeddedTokenAllocation } from "../payments/EmbeddedTokenAllocation";
2728

2829

2930
/**
@@ -321,8 +322,8 @@ const ActivityCard = ({ activity, isCarousel = false, compactLayout = false }) =
321322
className={cn(
322323
"w-full border border-theme-strong rounded-xl shadow-sm dark:bg-card/90 dark:hover:bg-card/100 hover:bg-muted/30 cursor-pointer no-underline bg-card overflow-hidden",
323324
"flex flex-col",
324-
// Mobile-first padding with better spacing
325-
"p-5 md:p-4",
325+
// Reduced padding for better screen real estate
326+
"p-3 md:p-3",
326327
// Ensure proper spacing between cards (handled by grid gap)
327328
"md:mb-0"
328329
)}
@@ -468,6 +469,19 @@ const ActivityCard = ({ activity, isCarousel = false, compactLayout = false }) =
468469
</div>
469470
</div>
470471
)}
472+
473+
{/* Token allocation UI */}
474+
{activity.userId && activity.pageId && (
475+
<div className="pt-3 border-t border-border/20 mt-3">
476+
<EmbeddedTokenAllocation
477+
pageId={activity.pageId}
478+
authorId={activity.userId}
479+
pageTitle={currentPageName}
480+
source="HomePage"
481+
className="w-full"
482+
/>
483+
</div>
484+
)}
471485
</div>
472486
</div>
473487
);

app/components/features/Home.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { useRouter } from "next/navigation";
55
import Link from "next/link";
66
import Header from "../layout/Header";
77
// Removed useOptimizedHome - now using UnifiedRecentActivity
8-
import { Activity, Search } from "lucide-react";
8+
import { Activity } from "lucide-react";
99
import SimpleRecentEdits from "./SimpleRecentEdits";
10-
11-
import { Input } from "../ui/input";
1210
import DailyNotesSection from "../daily-notes/DailyNotesSection";
1311
import EmailVerificationAlert from "../utils/EmailVerificationAlert";
1412
import EmptyState from "../ui/EmptyState";
@@ -24,12 +22,6 @@ const Home: React.FC = () => {
2422
const router = useRouter();
2523
// Removed recentEditsFilterState - now handled by UnifiedRecentActivity component
2624

27-
// Handle search functionality - navigate to search page
28-
const handleSearchFocus = () => {
29-
// Navigate to search page when user clicks on the search input
30-
router.push('/search');
31-
};
32-
3325
useEffect(() => {
3426
if (!isLoading && !isAuthenticated) {
3527
router.push("/auth/login");
@@ -58,26 +50,10 @@ const Home: React.FC = () => {
5850
<Header />
5951
{/* Main content area with proper sidebar spacing */}
6052
<main className="transition-all duration-300 ease-in-out">
61-
<div className="container mx-auto px-4 py-6 space-y-8">
53+
<div className="container mx-auto px-4 py-4 space-y-6">
6254
{/* Email Verification Alert */}
6355
<EmailVerificationAlert className="max-w-2xl mx-auto" />
6456

65-
{/* Search Section */}
66-
<div className="max-w-2xl mx-auto">
67-
<div className="relative cursor-pointer" onClick={handleSearchFocus}>
68-
<Input
69-
type="text"
70-
placeholder="Search for pages, users..."
71-
className="w-full pl-10 pr-4 rounded-2xl cursor-pointer"
72-
readOnly
73-
onClick={handleSearchFocus}
74-
/>
75-
<div className="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
76-
<Search className="h-5 w-5 text-muted-foreground" />
77-
</div>
78-
</div>
79-
</div>
80-
8157
{/* Daily Notes Section */}
8258
<DailyNotesSection />
8359

app/components/features/SimpleRecentEdits.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function SimpleRecentEdits() {
5858
const [hasMore, setHasMore] = useState(true);
5959
const [nextCursor, setNextCursor] = useState<string | null>(null);
6060
const [filters, setFilters] = useState<Filters>({
61-
includeOwn: true, // TEMPORARILY show own edits by default for debugging
61+
includeOwn: false, // Hide my edits by default
6262
followingOnly: false
6363
});
6464
const [isFollowingAnyone, setIsFollowingAnyone] = useState<boolean | null>(null);
@@ -167,13 +167,13 @@ export default function SimpleRecentEdits() {
167167

168168
if (loading) {
169169
return (
170-
<div className="space-y-4">
170+
<div className="space-y-3">
171171
<div className="flex items-center justify-between">
172172
<h2 className="text-xl font-semibold">Recent Edits</h2>
173173
</div>
174-
<div className="space-y-3">
174+
<div className="space-y-2">
175175
{[...Array(5)].map((_, i) => (
176-
<div key={i} className="h-24 bg-muted rounded-lg animate-pulse" />
176+
<div key={i} className="h-20 bg-muted rounded-lg animate-pulse" />
177177
))}
178178
</div>
179179
</div>
@@ -182,7 +182,7 @@ export default function SimpleRecentEdits() {
182182

183183
if (error) {
184184
return (
185-
<div className="space-y-4">
185+
<div className="space-y-3">
186186
<div className="flex items-center justify-between">
187187
<h2 className="text-xl font-semibold">Recent Edits</h2>
188188
</div>
@@ -194,7 +194,7 @@ export default function SimpleRecentEdits() {
194194
}
195195

196196
return (
197-
<div className="space-y-4">
197+
<div className="space-y-3">
198198
{/* Static Section Header */}
199199
<SectionTitle
200200
icon={Activity}
@@ -284,7 +284,7 @@ export default function SimpleRecentEdits() {
284284
</p>
285285
</div>
286286
) : (
287-
<div className="space-y-4">
287+
<div className="space-y-3">
288288
{edits.map((edit) => {
289289
const activityCardData = {
290290
pageId: edit.id,

0 commit comments

Comments
 (0)