feat: implement My Trees, admin UI, rating modal, and bundle optimization (Issues #15, #18, #19, #31)

Frontend features:
- My Trees personal dashboard with fork tracking (Issue #15)
- Tree sharing UI with token generation and copy (Issue #16)
- Draft tree badges and validation UI (Issue #25)
- Save session as tree modal (Issue #17)
- Rate/review modal with localStorage tracking (Issue #19)
- Admin category management with drag-and-drop (Issue #18)
- Bundle size optimization with code splitting (Issue #31)

Components created:
- MyTreesPage: Personal tree organization
- AdminCategoriesPage: Category CRUD with @dnd-kit
- ShareTreeModal: Tree sharing interface
- SaveSessionAsTreeModal: Session conversion UI
- StepRatingModal: Post-session rating with stars
- StarRating: Reusable rating component
- PageLoader: Loading fallback for lazy routes
- CreateCategoryModal, EditCategoryModal: Admin modals

Bundle optimization:
- Reduced from 892 KB to 221 KB (75% reduction)
- Dynamic imports for 9 heavy pages
- Vendor chunk splitting for optimal caching
- 6 separate vendor chunks (react, markdown, utils, dnd, icons, state)

Dependencies added:
- @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities

API clients:
- stepCategories: Full CRUD for admin
- Enhanced sessions: saveAsTree endpoint
- Enhanced trees: share, fork, canPublish endpoints

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-02-07 23:06:46 -05:00
parent c7b2c59ef6
commit 996b664ca9
30 changed files with 2973 additions and 92 deletions

View File

@@ -0,0 +1,279 @@
import { useState, useEffect } from 'react'
import { X, Copy, Check, Link2, Users, Lock, Globe } from 'lucide-react'
import type { TreeListItem, TreeShare, TreeVisibility } from '@/types'
import { treesApi } from '@/api'
import { cn } from '@/lib/utils'
import { toast } from '@/lib/toast'
interface ShareTreeModalProps {
tree: TreeListItem
isOpen: boolean
onClose: () => void
}
export function ShareTreeModal({ tree, isOpen, onClose }: ShareTreeModalProps) {
const [isGenerating, setIsGenerating] = useState(false)
const [shares, setShares] = useState<TreeShare[]>([])
const [activeShare, setActiveShare] = useState<TreeShare | null>(null)
const [copied, setCopied] = useState(false)
const [allowForking, setAllowForking] = useState(true)
const [visibility, setVisibility] = useState<TreeVisibility>('private')
useEffect(() => {
if (isOpen) {
loadShares()
// Reset state
setCopied(false)
setAllowForking(true)
}
}, [isOpen, tree.id])
const loadShares = async () => {
try {
const sharesData = await treesApi.listShares(tree.id)
setShares(sharesData)
// Set active share to most recent
if (sharesData.length > 0) {
setActiveShare(sharesData[0])
}
} catch (err) {
console.error('Failed to load shares:', err)
}
}
const handleGenerateLink = async () => {
setIsGenerating(true)
try {
const newShare = await treesApi.createShare(tree.id, {
allow_forking: allowForking,
})
setShares([newShare, ...shares])
setActiveShare(newShare)
toast.success('Share link generated')
} catch (err) {
console.error('Failed to generate share link:', err)
toast.error('Failed to generate share link')
} finally {
setIsGenerating(false)
}
}
const handleCopyLink = async () => {
if (!activeShare) return
try {
await navigator.clipboard.writeText(activeShare.share_url)
setCopied(true)
toast.success('Link copied to clipboard')
setTimeout(() => setCopied(false), 2000)
} catch (err) {
console.error('Failed to copy link:', err)
toast.error('Failed to copy link')
}
}
const handleVisibilityChange = async (newVisibility: TreeVisibility) => {
try {
await treesApi.updateVisibility(tree.id, { visibility: newVisibility })
setVisibility(newVisibility)
toast.success('Visibility updated')
} catch (err) {
console.error('Failed to update visibility:', err)
toast.error('Failed to update visibility')
}
}
const getVisibilityIcon = (level: TreeVisibility) => {
switch (level) {
case 'private':
return <Lock className="h-4 w-4" />
case 'team':
return <Users className="h-4 w-4" />
case 'link':
return <Link2 className="h-4 w-4" />
case 'public':
return <Globe className="h-4 w-4" />
}
}
const getVisibilityDescription = (level: TreeVisibility) => {
switch (level) {
case 'private':
return 'Only you can access'
case 'team':
return 'Team members can access'
case 'link':
return 'Anyone with the link'
case 'public':
return 'Discoverable by everyone'
}
}
if (!isOpen) return null
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
{/* Backdrop */}
<div
className="absolute inset-0 bg-background/80 backdrop-blur-sm"
onClick={onClose}
/>
{/* Modal */}
<div className="relative w-full max-w-lg rounded-lg border border-border bg-card shadow-lg">
{/* Header */}
<div className="flex items-center justify-between border-b border-border px-6 py-4">
<h2 className="text-lg font-semibold text-card-foreground">Share Tree</h2>
<button
onClick={onClose}
className="rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground"
>
<X className="h-5 w-5" />
</button>
</div>
{/* Body */}
<div className="px-6 py-4 space-y-6">
{/* Tree Info */}
<div>
<h3 className="font-medium text-card-foreground">{tree.name}</h3>
{tree.description && (
<p className="mt-1 text-sm text-muted-foreground line-clamp-2">
{tree.description}
</p>
)}
</div>
{/* Visibility Settings */}
<div>
<label className="mb-2 block text-sm font-medium text-card-foreground">
Visibility
</label>
<div className="space-y-2">
{(['private', 'team', 'link', 'public'] as TreeVisibility[]).map((level) => (
<button
key={level}
onClick={() => handleVisibilityChange(level)}
className={cn(
'flex w-full items-center gap-3 rounded-md border px-4 py-3 text-left transition-colors',
visibility === level
? 'border-primary bg-primary/5 text-card-foreground'
: 'border-border bg-background text-muted-foreground hover:border-primary/50 hover:bg-accent'
)}
>
{getVisibilityIcon(level)}
<div className="flex-1">
<div className="text-sm font-medium capitalize">{level}</div>
<div className="text-xs text-muted-foreground">
{getVisibilityDescription(level)}
</div>
</div>
{visibility === level && (
<div className="h-2 w-2 rounded-full bg-primary" />
)}
</button>
))}
</div>
</div>
{/* Share Link Generation */}
{visibility !== 'private' && (
<div>
<label className="mb-2 block text-sm font-medium text-card-foreground">
Share Link
</label>
{/* Allow Forking Checkbox */}
<div className="mb-3 flex items-center gap-2">
<input
type="checkbox"
id="allow-forking"
checked={allowForking}
onChange={(e) => setAllowForking(e.target.checked)}
className="h-4 w-4 rounded border-input text-primary focus:ring-2 focus:ring-primary focus:ring-offset-2"
/>
<label
htmlFor="allow-forking"
className="text-sm text-muted-foreground cursor-pointer"
>
Allow recipients to fork this tree
</label>
</div>
{/* Generate Button */}
{!activeShare && (
<button
onClick={handleGenerateLink}
disabled={isGenerating}
className={cn(
'w-full rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground',
'hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed'
)}
>
{isGenerating ? 'Generating...' : 'Generate Share Link'}
</button>
)}
{/* Active Share Link */}
{activeShare && (
<div className="space-y-2">
<div className="flex items-center gap-2 rounded-md border border-border bg-background p-3">
<input
type="text"
value={activeShare.share_url}
readOnly
className="flex-1 bg-transparent text-sm text-foreground outline-none"
/>
<button
onClick={handleCopyLink}
className={cn(
'flex items-center gap-2 rounded-md border border-input px-3 py-1.5 text-sm font-medium transition-colors',
copied
? 'border-green-500 bg-green-500/10 text-green-600'
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
)}
>
{copied ? (
<>
<Check className="h-4 w-4" />
Copied
</>
) : (
<>
<Copy className="h-4 w-4" />
Copy
</>
)}
</button>
</div>
<p className="text-xs text-muted-foreground">
{activeShare.allow_forking
? 'Recipients can fork this tree'
: 'Forking disabled for this share'}
</p>
{shares.length > 1 && (
<p className="text-xs text-muted-foreground">
{shares.length} active share links
</p>
)}
</div>
)}
</div>
)}
</div>
{/* Footer */}
<div className="flex justify-end gap-3 border-t border-border px-6 py-4">
<button
onClick={onClose}
className={cn(
'rounded-md border border-input px-4 py-2 text-sm font-medium text-muted-foreground',
'hover:bg-accent hover:text-accent-foreground'
)}
>
Close
</button>
</div>
</div>
</div>
)
}