'use client'; import AdminShell from '@/components/AdminShell'; import { api } from '@/lib/api'; import { useEffect, useState } from 'react'; import { Sliders, Save, RefreshCw } from 'lucide-react'; export default function AlgorithmPage() { const [configs, setConfigs] = useState([]); const [loading, setLoading] = useState(true); const [editValues, setEditValues] = useState>({}); const [saving, setSaving] = useState(null); const fetchConfig = () => { setLoading(true); api.getAlgorithmConfig() .then((data) => { setConfigs(data.config || []); const vals: Record = {}; (data.config || []).forEach((c: any) => { vals[c.key] = c.value; }); setEditValues(vals); }) .catch(() => {}) .finally(() => setLoading(false)); }; useEffect(() => { fetchConfig(); }, []); const handleSave = async (key: string) => { setSaving(key); try { await api.updateAlgorithmConfig(key, editValues[key]); fetchConfig(); } catch {} setSaving(null); }; const groupedConfigs = { feed: configs.filter((c) => c.key.startsWith('feed_')), moderation: configs.filter((c) => c.key.startsWith('moderation_')), other: configs.filter((c) => !c.key.startsWith('feed_') && !c.key.startsWith('moderation_')), }; return (

Algorithm & Feed Settings

Configure feed ranking weights and moderation thresholds

{loading ? (
) : (
{/* Feed Settings */}

Feed Ranking Weights

These weights control how posts are ranked in users' feeds. Values should be between 0 and 1 and ideally sum to 1.0.

{groupedConfigs.feed.map((config) => (

{config.description || config.key}

setEditValues({ ...editValues, [config.key]: e.target.value })} />
))} {groupedConfigs.feed.length === 0 && (

No feed settings configured yet. They will appear once the algorithm_config table is populated.

)}
{/* Moderation Settings */}

AI Moderation Thresholds

Control the sensitivity of the AI moderation system. Lower thresholds = more aggressive flagging.

{groupedConfigs.moderation.map((config) => (

{config.description || config.key}

setEditValues({ ...editValues, [config.key]: e.target.value })} />
))} {groupedConfigs.moderation.length === 0 && (

No moderation thresholds configured yet.

)}
{/* Other */} {groupedConfigs.other.length > 0 && (

Other Settings

{groupedConfigs.other.map((config) => (

{config.description}

setEditValues({ ...editValues, [config.key]: e.target.value })} />
))}
)}
)} ); }