import { useState } from "react"; import Layout from "@/components/Layout"; import { useAuth } from "@/contexts/AuthContext"; import { useAethexToast } from "@/hooks/use-aethex-toast"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Loader2, Sparkles } from "lucide-react"; const ARMS = [ { id: "labs", label: "Labs", color: "bg-yellow-500" }, { id: "gameforge", label: "GameForge", color: "bg-green-500" }, { id: "corp", label: "Corp", color: "bg-blue-500" }, { id: "foundation", label: "Foundation", color: "bg-red-500" }, { id: "nexus", label: "Nexus", color: "bg-purple-500" }, { id: "staff", label: "Staff", color: "bg-indigo-500" }, ]; export default function AdminFeed() { const { user } = useAuth(); const { toast } = useAethexToast(); const [isLoading, setIsLoading] = useState(false); const [title, setTitle] = useState(""); const [content, setContent] = useState(""); const [selectedArm, setSelectedArm] = useState("labs"); const [tags, setTags] = useState([]); const [tagInput, setTagInput] = useState(""); const [isDraft, setIsDraft] = useState(false); // Check admin access if (!user?.user_metadata?.is_admin) { return (
Access Denied

Only administrators can access this page.

); } const addTag = () => { const trimmed = tagInput.trim(); if (trimmed && !tags.includes(trimmed)) { setTags([...tags, trimmed]); setTagInput(""); } }; const removeTag = (tag: string) => { setTags(tags.filter((t) => t !== tag)); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!title.trim() || !content.trim()) { toast({ description: "Title and content are required", variant: "destructive", }); return; } if (!user?.id) { toast({ description: "You must be logged in to create posts", variant: "destructive", }); return; } setIsLoading(true); try { const response = await fetch("/api/posts", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ title: title.trim(), content: content.trim(), arm_affiliation: selectedArm, author_id: user.id, tags: tags, category: "announcement", }), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to create post"); } const { post } = await response.json(); toast({ description: "Post created successfully! 🎉", }); // Reset form setTitle(""); setContent(""); setTags([]); setTagInput(""); setSelectedArm("labs"); } catch (error: any) { console.error("Failed to create post:", error); toast({ description: error.message || "Failed to create post", variant: "destructive", }); } finally { setIsLoading(false); } }; const selectedArmData = ARMS.find((arm) => arm.id === selectedArm); return (
{/* Header */}

Feed Manager

Create system announcements and showcase Arm-to-Arm partnerships. This is how we prove the Axiom Model in action.

{/* Main Form */} Create a New Post
{/* Title */}
setTitle(e.target.value)} maxLength={500} className="border-border/40 bg-background/80 text-sm" />

{title.length}/500 characters

{/* Content */}