Skip to content

Commit 674b294

Browse files
committed
Fix admin interface and daily notes layout issues
- Fix admin landing page cards functionality by creating missing /api/admin/check-permissions endpoint - Remove outdated testing tools card from admin interface - Remove icons from Design System and Background Images cards in admin - Fix daily notes carousel clipping issues with simplified layout structure - Refactor Home container to prevent clipping (remove px-4 from main container) - Simplify DailyNotesSection and DailyNotesCarousel with clear documentation - Implement selected text as initial search query for insert link modal - Add getSelectedText() function to SlateEditor to extract selected text - Pass selectedText prop to LinkEditorModal and use as initialSearch in FilteredSearchResults - Improve UX by pre-populating link search with user's selected text
1 parent a882331 commit 674b294

File tree

12 files changed

+166
-143
lines changed

12 files changed

+166
-143
lines changed

app/admin/page.tsx

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default function AdminPage() {
4141
// Removed user management state - users tab deleted
4242

4343
// Testing tools state
44-
const [statusCheckLoading, setStatusCheckLoading] = useState(false);
4544
const [showPWABanner, setShowPWABanner] = useState(false);
4645
const [showUnverifiedEmailBanner, setShowUnverifiedEmailBanner] = useState(false);
4746
const [noSubscriptionMode, setNoSubscriptionMode] = useState(false);
@@ -137,63 +136,6 @@ export default function AdminPage() {
137136
});
138137
};
139138

140-
// Testing tools handlers
141-
142-
143-
144-
145-
const handleCheckPayoutStatus = async () => {
146-
console.log('[Admin Testing] Starting payout status check...');
147-
setStatusCheckLoading(true);
148-
try {
149-
console.log('[Admin Testing] Sending request to /api/admin/payout-status');
150-
151-
const response = await fetch('/api/admin/payout-status', {
152-
method: 'GET',
153-
headers: {
154-
'Content-Type': 'application/json'}
155-
});
156-
157-
console.log('[Admin Testing] Status check response status:', response.status);
158-
console.log('[Admin Testing] Status check response headers:', Object.fromEntries(response.headers.entries()));
159-
160-
const result = await response.json();
161-
console.log('[Admin Testing] Status check response body:', result);
162-
163-
if (result.success) {
164-
console.log('[Admin Testing] System status check completed successfully');
165-
console.log('[Admin Testing] Payout System Status:', result.data);
166-
toast({
167-
title: "System Status Check Complete",
168-
description: "Check console for detailed status information"});
169-
} else {
170-
console.error('[Admin Testing] Status check failed:', result);
171-
toast({
172-
title: "Status Check Failed",
173-
description: result.error || "An error occurred",
174-
variant: "destructive"
175-
});
176-
}
177-
} catch (error) {
178-
console.error('[Admin Testing] Exception in status check:', error);
179-
console.error('[Admin Testing] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
180-
toast({
181-
title: "Error",
182-
description: "Failed to check system status - check console for details",
183-
variant: "destructive"
184-
});
185-
} finally {
186-
console.log('[Admin Testing] Status check completed, setting loading to false');
187-
setStatusCheckLoading(false);
188-
}
189-
};
190-
191-
192-
193-
194-
195-
196-
197139
// Feature flags have been removed
198140

199141
// Enhanced loading and error states
@@ -344,19 +286,6 @@ export default function AdminPage() {
344286
/>
345287
</div>
346288
</div>
347-
{/* Testing Tools */}
348-
<div className="wewrite-card flex flex-col hover:bg-muted/50 transition-colors">
349-
<div className="flex items-center justify-between mb-2">
350-
<h3 className="font-medium">Testing Tools</h3>
351-
</div>
352-
<span className="text-sm text-muted-foreground mb-3">
353-
Test payout systems, token earnings, and subscription states
354-
</span>
355-
<div className="mt-2 space-y-4">
356-
<p className="text-sm text-muted-foreground">Testing tools have been moved to the main admin dashboard.</p>
357-
</div>
358-
</div>
359-
360289
{/* Landing Page Management */}
361290
<div className="wewrite-card flex flex-col hover:bg-muted/50 transition-colors">
362291
<div className="flex items-center justify-between mb-2">
@@ -382,7 +311,6 @@ export default function AdminPage() {
382311
<div className="wewrite-card flex flex-col hover:bg-muted/50 transition-colors">
383312
<div className="flex items-center justify-between mb-2">
384313
<h3 className="font-medium">Design System</h3>
385-
<Palette className="h-5 w-5 text-primary" />
386314
</div>
387315
<span className="text-sm text-muted-foreground mb-3">
388316
Interactive showcase of all WeWrite components with their states and documentation
@@ -404,7 +332,6 @@ export default function AdminPage() {
404332
<div className="wewrite-card flex flex-col hover:bg-muted/50 transition-colors">
405333
<div className="flex items-center justify-between mb-2">
406334
<h3 className="font-medium">Background Images</h3>
407-
<ImageIcon className="h-5 w-5 text-primary" />
408335
</div>
409336
<span className="text-sm text-muted-foreground mb-3">
410337
Manage default background images available to all users. Upload, delete, and reorder images.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Admin Permissions Check API
3+
* Provides a simple endpoint to check if the current user has admin permissions
4+
*/
5+
6+
import { NextRequest, NextResponse } from 'next/server';
7+
import { checkAdminPermissions } from '../../admin-auth-helper';
8+
9+
export async function GET(request: NextRequest) {
10+
try {
11+
// Check admin permissions
12+
const adminCheck = await checkAdminPermissions(request);
13+
14+
if (adminCheck.success) {
15+
return NextResponse.json({
16+
success: true,
17+
isAdmin: true,
18+
userEmail: adminCheck.userEmail
19+
});
20+
} else {
21+
return NextResponse.json({
22+
success: false,
23+
isAdmin: false,
24+
error: adminCheck.error
25+
});
26+
}
27+
} catch (error) {
28+
console.error('Error checking admin permissions:', error);
29+
return NextResponse.json({
30+
success: false,
31+
isAdmin: false,
32+
error: 'Failed to check admin permissions'
33+
}, { status: 500 });
34+
}
35+
}

app/components/daily-notes/DailyNotesCarousel.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ interface DailyNotesCarouselProps {
4242
* - Shows multiple notes per day in container format
4343
* - Groups pages by their creation date (createdAt field)
4444
* - Maintains scroll position when loading new dates
45+
*
46+
* LAYOUT STRUCTURE (simplified for easy debugging):
47+
* - Single overflow-x-auto container with generous bottom padding
48+
* - Inner flex container for horizontal layout
49+
* - No nested clipping containers
50+
* - Today pill has 3rem bottom padding space to prevent clipping
4551
*/
4652
export default function DailyNotesCarousel({
4753
accentColor = '#1768FF',
@@ -519,13 +525,23 @@ export default function DailyNotesCarousel({
519525

520526
if (loading) {
521527
return (
522-
<div className="flex gap-4 overflow-x-auto pb-2 px-6 pt-2">
523-
{Array.from({ length: 5 }).map((_, index) => (
524-
<div
525-
key={index}
526-
className="flex-shrink-0 w-48 h-[200px] bg-muted/50 rounded-xl animate-pulse border-theme-light"
527-
/>
528-
))}
528+
<div
529+
className="w-full overflow-x-auto scrollbar-hide"
530+
style={{
531+
paddingLeft: '1rem',
532+
paddingRight: '1rem',
533+
paddingTop: '0.5rem',
534+
paddingBottom: '3rem' // Extra space for Today pill
535+
}}
536+
>
537+
<div className="flex gap-4">
538+
{Array.from({ length: 5 }).map((_, index) => (
539+
<div
540+
key={index}
541+
className="flex-shrink-0 w-48 h-[200px] bg-muted/50 rounded-xl animate-pulse border-theme-light"
542+
/>
543+
))}
544+
</div>
529545
</div>
530546
);
531547
}
@@ -534,17 +550,19 @@ export default function DailyNotesCarousel({
534550
<div
535551
ref={carouselRef}
536552
id="daily-notes-carousel"
537-
className={cn(
538-
"flex overflow-x-auto pb-2 px-6 pt-2 scrollbar-hide",
539-
isFullPage ? "gap-8" : "gap-4" // Larger gaps for full page
540-
)}
553+
className="w-full overflow-x-auto scrollbar-hide"
541554
style={{
542555
scrollbarWidth: 'none',
543556
msOverflowStyle: 'none',
544-
WebkitOverflowScrolling: 'touch'
557+
WebkitOverflowScrolling: 'touch',
558+
paddingLeft: '1rem',
559+
paddingRight: '1rem',
560+
paddingTop: '0.5rem',
561+
paddingBottom: '3rem' // Extra space for Today pill and any other elements
545562
}}
546563
>
547-
{/* Load More Past Button */}
564+
<div className={cn("flex", isFullPage ? "gap-8" : "gap-4")}>
565+
{/* Load More Past Button */}
548566
<div className="flex-shrink-0 flex items-center justify-center min-w-48 h-[200px]">
549567
<Button
550568
variant="secondary"
@@ -617,6 +635,7 @@ export default function DailyNotesCarousel({
617635
)}
618636
</Button>
619637
</div>
638+
</div>
620639
</div>
621640
);
622641
}

app/components/daily-notes/DailyNotesSection.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ interface DailyNotesSectionProps {
2020
* Uses YYYY-MM-DD format for all daily note titles.
2121
* Now uses the standardized sticky header pattern.
2222
* Uses accent color from context and respects pill style settings.
23+
*
24+
* LAYOUT STRUCTURE (simplified for easy debugging):
25+
* - Header with horizontal padding (px-4)
26+
* - Carousel with no padding wrapper (full width to prevent clipping)
27+
* - Parent container has no horizontal padding to allow carousel overflow
2328
*/
2429
export default function DailyNotesSection({}: DailyNotesSectionProps) {
2530
const { user, isAuthenticated } = useAuth();
@@ -61,26 +66,26 @@ export default function DailyNotesSection({}: DailyNotesSectionProps) {
6166

6267
return (
6368
<div className="space-y-4">
64-
{/* Static Section Header */}
65-
<SectionTitle
66-
icon={Calendar}
67-
title="My Daily Notes"
68-
>
69-
<Button
70-
variant="secondary"
71-
size="sm"
72-
onClick={scrollToToday}
73-
className="rounded-2xl"
74-
aria-label="Scroll to today's notes"
69+
{/* Section Header - with horizontal padding */}
70+
<div className="px-4">
71+
<SectionTitle
72+
icon={Calendar}
73+
title="My Daily Notes"
7574
>
76-
<Calendar className="h-4 w-4" />
77-
</Button>
78-
</SectionTitle>
79-
80-
{/* Content container with fade effect applied to scroll container */}
81-
<div className="carousel-container-with-fade">
82-
<DailyNotesCarousel accentColor={getAccentColorValue()} />
75+
<Button
76+
variant="secondary"
77+
size="sm"
78+
onClick={scrollToToday}
79+
className="rounded-2xl"
80+
aria-label="Scroll to today's notes"
81+
>
82+
<Calendar className="h-4 w-4" />
83+
</Button>
84+
</SectionTitle>
8385
</div>
86+
87+
{/* Carousel - full width, no clipping containers */}
88+
<DailyNotesCarousel accentColor={getAccentColorValue()} />
8489
</div>
8590
);
8691
}

app/components/editor/LinkEditorModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,14 @@ export default function LinkEditorModal({
272272
/>
273273
</div>
274274

275-
{/* Search Results */}
275+
{/* Search Results - uses selectedText as initial search query */}
276276
<div className="h-48 sm:h-64">
277277
<FilteredSearchResults
278278
ref={searchInputRef}
279279
onSelect={handlePageSelect}
280280
userId={user?.uid}
281281
placeholder="Search for pages..."
282+
initialSearch={selectedText} // Pre-populate search with selected text
282283
autoFocus={!selectedText}
283284
className="h-full p-2 sm:p-3"
284285
preventRedirect={true}

0 commit comments

Comments
 (0)