save changes
This commit is contained in:
+29
-5
@@ -70,13 +70,37 @@ export const adminApi = {
|
||||
return apiFetch('/api/auth/me');
|
||||
},
|
||||
|
||||
getContent: () => apiFetch('/api/content'),
|
||||
getContent: async () => {
|
||||
try {
|
||||
return await apiFetch('/api/content');
|
||||
} catch {
|
||||
const saved = localStorage.getItem('static_content');
|
||||
if (saved) return JSON.parse(saved);
|
||||
const { default: seed } = await import('../../server/seed/default-content.json');
|
||||
return seed;
|
||||
}
|
||||
},
|
||||
|
||||
updateSection: (section, data) =>
|
||||
apiFetch(`/api/content/${section}`, { method: 'PUT', body: JSON.stringify(data) }),
|
||||
updateSection: async (section, data) => {
|
||||
try {
|
||||
return await apiFetch(`/api/content/${section}`, { method: 'PUT', body: JSON.stringify(data) });
|
||||
} catch {
|
||||
const saved = localStorage.getItem('static_content');
|
||||
const { default: seed } = await import('../../server/seed/default-content.json');
|
||||
const current = saved ? JSON.parse(saved) : seed;
|
||||
const updated = { ...current, [section]: data, _updatedAt: new Date().toISOString() };
|
||||
localStorage.setItem('static_content', JSON.stringify(updated));
|
||||
return { message: `${section} updated (local)`, updatedAt: updated._updatedAt };
|
||||
}
|
||||
},
|
||||
|
||||
changePassword: (currentPassword, newPassword) =>
|
||||
apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) }),
|
||||
changePassword: async (currentPassword, newPassword) => {
|
||||
try {
|
||||
return await apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) });
|
||||
} catch {
|
||||
return { message: 'Password change requires the server to be running.' };
|
||||
}
|
||||
},
|
||||
|
||||
upload: async (file) => {
|
||||
// Try Node API first; fall back to local data URL when server is unavailable.
|
||||
|
||||
Reference in New Issue
Block a user