diff --git a/src/app/clasificados/page.tsx b/src/app/clasificados/page.tsx index 2abf152..1b64727 100644 --- a/src/app/clasificados/page.tsx +++ b/src/app/clasificados/page.tsx @@ -13,7 +13,12 @@ async function fetchClasificadosData() { // 1. Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); - const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : {}) as Settings; + const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : { + ticker_count: 10, + rotation_seconds: 5, + feed_news_count: 12, + show_news_date: true + }) as Settings; const postsCount = settings.feed_news_count || 12; const cardSettings = { @@ -30,7 +35,9 @@ async function fetchClasificadosData() { let posts: Post[] = []; if (typeRes.documents.length > 0) { - const typeId = typeRes.documents[0].$id; + const firstType = typeRes.documents[0]; + const typeId = firstType?.$id; + if (!typeId) return { posts: [], cardSettings }; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'), diff --git a/src/app/dashboard/settings/page.tsx b/src/app/dashboard/settings/page.tsx index 7b1bd42..805b39e 100644 --- a/src/app/dashboard/settings/page.tsx +++ b/src/app/dashboard/settings/page.tsx @@ -2,11 +2,12 @@ import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite'; import { createSessionClient } from '@/lib/appwrite.server'; import { getEntity, updateEntity } from '@/app/actions/entity'; import { revalidatePath } from 'next/cache'; -import { Settings, Save, Clock, Menu, Building, Image as ImageIcon, Link as LinkIcon, Share2 } from 'lucide-react'; +import { Settings as SettingsIcon, Save, Clock, Menu, Building, Image as ImageIcon, Link as LinkIcon, Share2 } from 'lucide-react'; +import { Settings as SettingsInterface } from '@/types/settings'; export default async function SettingsPage() { - let settings = { ticker_count: 10, rotation_seconds: 5 }; - let docId = 'global_config'; + let settings: SettingsInterface = { ticker_count: 10, rotation_seconds: 5 }; + let docId = ''; let entity: any = null; try { @@ -18,7 +19,7 @@ export default async function SettingsPage() { [] ); if (response.documents.length > 0) { - settings = response.documents[0] as any; + settings = response.documents[0] as unknown as SettingsInterface; docId = response.documents[0].$id; } } @@ -69,7 +70,7 @@ export default async function SettingsPage() {
- +

@@ -109,7 +110,7 @@ export default async function SettingsPage() { diff --git a/src/app/eventos/page.tsx b/src/app/eventos/page.tsx index a672242..18d0462 100644 --- a/src/app/eventos/page.tsx +++ b/src/app/eventos/page.tsx @@ -13,7 +13,12 @@ async function fetchEventosData() { // 1. Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); - const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : {}) as Settings; + const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : { + ticker_count: 10, + rotation_seconds: 5, + feed_news_count: 12, + show_news_date: true + }) as Settings; const postsCount = settings.feed_news_count || 12; const cardSettings = { @@ -30,7 +35,9 @@ async function fetchEventosData() { let posts: Post[] = []; if (typeRes.documents.length > 0) { - const typeId = typeRes.documents[0].$id; + const firstType = typeRes.documents[0]; + const typeId = firstType?.$id; + if (!typeId) return { posts: [], cardSettings }; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'), diff --git a/src/app/page.tsx b/src/app/page.tsx index 44cba2b..3196a58 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -15,7 +15,12 @@ async function fetchHomeData() { // 1. Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); - const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : {}) as Settings; + const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : { + ticker_count: 10, + rotation_seconds: 5, + feed_news_count: 12, + show_news_date: true + }) as Settings; const postsCount = settings.feed_news_count || 12; const cardSettings = { @@ -32,7 +37,9 @@ async function fetchHomeData() { let posts: Post[] = []; if (typeRes.documents.length > 0) { - const typeId = typeRes.documents[0].$id; + const firstType = typeRes.documents[0]; + const typeId = firstType?.$id; + if (!typeId) return { posts: [], cardSettings }; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'), diff --git a/src/components/AdWrappers.tsx b/src/components/AdWrappers.tsx index a79e101..539bbe3 100644 --- a/src/components/AdWrappers.tsx +++ b/src/components/AdWrappers.tsx @@ -8,12 +8,12 @@ import { Settings } from '@/types/settings'; async function fetchSettings(): Promise { try { const client = await createAdminClient(); - const res = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', [Query.limit(1)]); - if (res.documents.length > 0) return res.documents[0] as unknown as Settings; + const res = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', [Query.limit(1)]); + if (res.documents.length > 0) return res.documents[0] as unknown as Settings; } catch(e) { console.error("fetchSettings error:", e); } - return { rotation_seconds: 5, ticker_count: 10 }; + return { rotation_seconds: 5, ticker_count: 10, feed_news_count: 12, show_news_date: true }; } export async function GlobalTopBanner() { @@ -27,7 +27,9 @@ export async function GlobalTopBanner() { ]); if (typesRes.documents.length > 0) { - const typeId = typesRes.documents[0].$id; + const firstType = typesRes.documents[0]; + const typeId = firstType?.$id; + if (!typeId) return null; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), diff --git a/src/components/NewsTicker.tsx b/src/components/NewsTicker.tsx index 368d736..311f5de 100644 --- a/src/components/NewsTicker.tsx +++ b/src/components/NewsTicker.tsx @@ -19,7 +19,12 @@ export default async function NewsTicker() { // 1. Fetch Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); - const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : {}) as Settings; + const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : { + ticker_count: 10, + rotation_seconds: 5, + feed_news_count: 12, + show_news_date: true + }) as Settings; const tickerCount = settings.ticker_count || 10; // 2. Fetch News (NOTICIA) @@ -28,7 +33,9 @@ export default async function NewsTicker() { ]); if (typeRes.documents.length > 0) { - const typeId = typeRes.documents[0].$id; + const firstType = typeRes.documents[0]; + const typeId = firstType?.$id; + if (!typeId) throw new Error("Could not find typeId for NOTICIA"); const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'),