feat: enhance admin settings handling and update RightSidebar to use dynamic node description
This commit is contained in:
@@ -163,13 +163,14 @@ export default function AdminPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveSettings = async () => {
|
||||
const handleSaveSettings = async (override?: typeof nodeSettings) => {
|
||||
const payload = override ?? nodeSettings;
|
||||
setSavingSettings(true);
|
||||
try {
|
||||
const res = await fetch('/api/admin/node', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(nodeSettings),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (res.ok) {
|
||||
alert('Settings saved!');
|
||||
@@ -204,10 +205,12 @@ export default function AdminPage() {
|
||||
throw new Error(data.error || 'Upload failed');
|
||||
}
|
||||
|
||||
setNodeSettings((prev) => ({
|
||||
...prev,
|
||||
const nextSettings = {
|
||||
...nodeSettings,
|
||||
bannerUrl: data.media?.url || data.url,
|
||||
}));
|
||||
};
|
||||
setNodeSettings(nextSettings);
|
||||
await handleSaveSettings(nextSettings);
|
||||
} catch (error) {
|
||||
console.error('Banner upload failed', error);
|
||||
setBannerUploadError('Upload failed. Please try again.');
|
||||
|
||||
@@ -3,21 +3,28 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function RightSidebar() {
|
||||
const fallbackDescription = process.env.NEXT_PUBLIC_NODE_DESCRIPTION || 'A federated social network node.';
|
||||
const [nodeInfo, setNodeInfo] = useState({
|
||||
name: process.env.NEXT_PUBLIC_NODE_NAME || 'Synapsis Node',
|
||||
description: 'A federated social network designed as global communication infrastructure. Signal over noise. Identity that is truly yours.',
|
||||
description: fallbackDescription,
|
||||
longDescription: '',
|
||||
rules: '',
|
||||
bannerUrl: '',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/node')
|
||||
fetch('/api/node', { cache: 'no-store' })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.name) {
|
||||
setNodeInfo(prev => ({ ...prev, ...data }));
|
||||
}
|
||||
setNodeInfo(prev => ({
|
||||
...prev,
|
||||
...data,
|
||||
name: data?.name ?? prev.name,
|
||||
description: data?.description ?? prev.description,
|
||||
longDescription: data?.longDescription ?? prev.longDescription,
|
||||
rules: data?.rules ?? prev.rules,
|
||||
bannerUrl: data?.bannerUrl ?? prev.bannerUrl,
|
||||
}));
|
||||
})
|
||||
.catch(() => { });
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user