feat(db,admin): Add logo URL support and refactor bot schema with owner relationships

- Add logo_url column to nodes table for custom branding
- Refactor bots table to use owner_id foreign key relationship with users
- Add is_bot and bot_owner_id columns to users table for bot account tracking
- Add bot_id foreign key to posts table for bot-generated content tracking
- Create database indexes on owner_id, bot_id, is_bot, and bot_owner_id for query performance
- Remove bot handle, bio, avatar_url, and cryptographic keys from bots table (moved to user accounts)
- Update bot_content_sources schema and remove fetch_interval_minutes column
- Fix bot_content_items foreign key constraint with set null on delete
- Remove hardcoded NODE_NAME and NODE_DESCRIPTION from environment configuration
- Update admin panel, bot settings, and layout components to support new schema
- Add AccentColorContext and ToastContext for improved UI state management
- Update PostCard, Sidebar, RightSidebar, and LayoutWrapper components for context integration
This commit is contained in:
AskIt
2026-01-25 20:15:35 +01:00
parent d36c1c93e5
commit b9316552c2
16 changed files with 3386 additions and 61 deletions
+67
View File
@@ -0,0 +1,67 @@
'use client';
import { createContext, useContext, useEffect, useState, useCallback, ReactNode } from 'react';
interface AccentColorContextType {
accentColor: string;
refreshAccentColor: () => void;
}
const AccentColorContext = createContext<AccentColorContextType | null>(null);
function applyAccentColor(color: string) {
const cleaned = color.trim();
const normalized = cleaned.startsWith('#') ? cleaned : `#${cleaned}`;
const hexMatch = /^#([0-9a-fA-F]{6})$/.exec(normalized);
if (!hexMatch) return;
const hex = hexMatch[1];
const r = parseInt(hex.slice(0, 2), 16);
const g = parseInt(hex.slice(2, 4), 16);
const b = parseInt(hex.slice(4, 6), 16);
const mix = (channel: number, target: number, amount: number) =>
Math.round(channel + (target - channel) * amount);
const hover = `rgb(${mix(r, 255, 0.12)}, ${mix(g, 255, 0.12)}, ${mix(b, 255, 0.12)})`;
const muted = `rgba(${r}, ${g}, ${b}, 0.12)`;
const root = document.documentElement;
root.style.setProperty('--accent', `#${hex}`);
root.style.setProperty('--accent-hover', hover);
root.style.setProperty('--accent-muted', muted);
}
export function AccentColorProvider({ children }: { children: ReactNode }) {
const [accentColor, setAccentColor] = useState('#00D4AA');
const refreshAccentColor = useCallback(() => {
fetch('/api/node', { cache: 'no-store' })
.then((res) => res.json())
.then((data) => {
if (data?.accentColor) {
setAccentColor(data.accentColor);
applyAccentColor(data.accentColor);
}
})
.catch(() => {});
}, []);
useEffect(() => {
refreshAccentColor();
}, [refreshAccentColor]);
return (
<AccentColorContext.Provider value={{ accentColor, refreshAccentColor }}>
{children}
</AccentColorContext.Provider>
);
}
export function useAccentColor() {
const context = useContext(AccentColorContext);
if (!context) {
throw new Error('useAccentColor must be used within an AccentColorProvider');
}
return context;
}
+108
View File
@@ -0,0 +1,108 @@
'use client';
import { createContext, useContext, useState, useCallback, ReactNode } from 'react';
type ToastType = 'success' | 'error' | 'info';
interface Toast {
id: string;
message: string;
type: ToastType;
}
interface ToastContextType {
toasts: Toast[];
showToast: (message: string, type?: ToastType) => void;
removeToast: (id: string) => void;
}
const ToastContext = createContext<ToastContextType | null>(null);
export function ToastProvider({ children }: { children: ReactNode }) {
const [toasts, setToasts] = useState<Toast[]>([]);
const showToast = useCallback((message: string, type: ToastType = 'info') => {
const id = Math.random().toString(36).slice(2);
setToasts(prev => [...prev, { id, message, type }]);
setTimeout(() => {
setToasts(prev => prev.filter(t => t.id !== id));
}, 3500);
}, []);
const removeToast = useCallback((id: string) => {
setToasts(prev => prev.filter(t => t.id !== id));
}, []);
return (
<ToastContext.Provider value={{ toasts, showToast, removeToast }}>
{children}
<ToastContainer toasts={toasts} removeToast={removeToast} />
</ToastContext.Provider>
);
}
export function useToast() {
const context = useContext(ToastContext);
if (!context) {
throw new Error('useToast must be used within a ToastProvider');
}
return context;
}
function ToastContainer({ toasts, removeToast }: { toasts: Toast[]; removeToast: (id: string) => void }) {
if (toasts.length === 0) return null;
return (
<div style={{
position: 'fixed',
bottom: '24px',
right: '24px',
zIndex: 9999,
display: 'flex',
flexDirection: 'column',
gap: '8px',
pointerEvents: 'none',
}}>
{toasts.map(toast => (
<div
key={toast.id}
onClick={() => removeToast(toast.id)}
style={{
pointerEvents: 'auto',
cursor: 'pointer',
padding: '12px 16px',
borderRadius: '8px',
background: toast.type === 'error'
? 'var(--danger)'
: toast.type === 'success'
? 'var(--accent)'
: 'var(--background-secondary)',
color: toast.type === 'error' || toast.type === 'success'
? '#fff'
: 'var(--foreground)',
boxShadow: '0 4px 12px rgba(0, 0, 0, 0.3)',
fontSize: '14px',
fontWeight: 500,
maxWidth: '320px',
animation: 'toastSlideIn 0.2s ease-out',
border: '1px solid var(--border)',
}}
>
{toast.message}
</div>
))}
<style jsx global>{`
@keyframes toastSlideIn {
from {
opacity: 0;
transform: translateX(100%);
}
to {
opacity: 1;
transform: translateX(0);
}
}
`}</style>
</div>
);
}