sojorn/_legacy/supabase/functions/_shared/validation.ts
Patrick Britton 3c4680bdd7 Initial commit: Complete threaded conversation system with inline replies
**Major Features Added:**
- **Inline Reply System**: Replace compose screen with inline reply boxes
- **Thread Navigation**: Parent/child navigation with jump functionality
- **Chain Flow UI**: Reply counts, expand/collapse animations, visual hierarchy
- **Enhanced Animations**: Smooth transitions, hover effects, micro-interactions

 **Frontend Changes:**
- **ThreadedCommentWidget**: Complete rewrite with animations and navigation
- **ThreadNode Model**: Added parent references and descendant counting
- **ThreadedConversationScreen**: Integrated navigation handlers
- **PostDetailScreen**: Replaced with threaded conversation view
- **ComposeScreen**: Added reply indicators and context
- **PostActions**: Fixed visibility checks for chain buttons

 **Backend Changes:**
- **API Route**: Added /posts/:id/thread endpoint
- **Post Repository**: Include allow_chain and visibility fields in feed
- **Thread Handler**: Support for fetching post chains

 **UI/UX Improvements:**
- **Reply Context**: Clear indication when replying to specific posts
- **Character Counting**: 500 character limit with live counter
- **Visual Hierarchy**: Depth-based indentation and styling
- **Smooth Animations**: SizeTransition, FadeTransition, hover states
- **Chain Navigation**: Parent/child buttons with visual feedback

 **Technical Enhancements:**
- **Animation Controllers**: Proper lifecycle management
- **State Management**: Clean separation of concerns
- **Navigation Callbacks**: Reusable navigation system
- **Error Handling**: Graceful fallbacks and user feedback

This creates a Reddit-style threaded conversation experience with smooth
animations, inline replies, and intuitive navigation between posts in a chain.
2026-01-30 07:40:19 -06:00

54 lines
1.4 KiB
TypeScript

/**
* Shared validation utilities
*/
export class ValidationError extends Error {
constructor(message: string, public field?: string) {
super(message);
this.name = 'ValidationError';
}
}
export function validatePostBody(body: string): void {
const trimmed = body.trim();
if (trimmed.length === 0) {
throw new ValidationError('Post cannot be empty.', 'body');
}
if (body.length > 500) {
throw new ValidationError('Post is too long (max 500 characters).', 'body');
}
}
export function validateCommentBody(body: string): void {
const trimmed = body.trim();
if (trimmed.length === 0) {
throw new ValidationError('Comment cannot be empty.', 'body');
}
if (body.length > 300) {
throw new ValidationError('Comment is too long (max 300 characters).', 'body');
}
}
export function validateReportReason(reason: string): void {
const trimmed = reason.trim();
if (trimmed.length < 10) {
throw new ValidationError('Report reason must be at least 10 characters.', 'reason');
}
if (reason.length > 500) {
throw new ValidationError('Report reason is too long (max 500 characters).', 'reason');
}
}
export function validateUUID(value: string, fieldName: string): void {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (!uuidRegex.test(value)) {
throw new ValidationError(`Invalid ${fieldName}.`, fieldName);
}
}