diff --git a/src/api/news.tsx b/src/api/news.tsx new file mode 100644 index 0000000..0fb721a --- /dev/null +++ b/src/api/news.tsx @@ -0,0 +1,36 @@ +'use client' +import { useEffect, useState } from 'react'; +import { Root } from '@/interface/interfaceNews'; // Certifique-se de que o caminho para a interface está correto + +export default function NewsApi() { + // const apiKey = process.env.REACT_APP_NEWS_API_KEY; + const [dataNews, setDataNews] = useState(null); + + useEffect(() => { + async function fetchData() { + try { + const responseNews = await fetch( + `https://newsapi.org/v2/top-headlines?sources=google-news-br&apiKey=8c18442db94a48f5a1149d114f75ddef` + ); + + + console.log('1',responseNews) + if (!responseNews.ok) { + throw new Error('Erro ao buscar notícias'); + } + + console.log('2',responseNews) + + const data: Root = await responseNews.json(); + console.log('2',responseNews) + setDataNews(data); + } catch (error) { + console.error('Erro ao buscar notícias:', error); + setDataNews(null); + } + } + fetchData(); + }, []); + + return dataNews; +} diff --git a/src/app/contato/page.tsx b/src/app/contato/page.tsx index f908709..e2003b5 100644 --- a/src/app/contato/page.tsx +++ b/src/app/contato/page.tsx @@ -1,7 +1,9 @@ export default function Contato() { return ( -
- Contato -
+ <> +
+

Contato

+
+ ); } diff --git a/src/app/edicoes/page.tsx b/src/app/edicoes/page.tsx index d5efa39..db36a08 100644 --- a/src/app/edicoes/page.tsx +++ b/src/app/edicoes/page.tsx @@ -1,7 +1,9 @@ export default function Edicoes() { return ( -
- Edições -
+ <> +
+

Edições

+
+ ); } diff --git a/src/app/editoriais/automobilismo/page.tsx b/src/app/editoriais/automobilismo/page.tsx index e4dbaf6..f47a499 100644 --- a/src/app/editoriais/automobilismo/page.tsx +++ b/src/app/editoriais/automobilismo/page.tsx @@ -1,7 +1,9 @@ export default function Automobilismo() { return ( -
- Automobilismo -
+ <> +
+

Automobilismo

+
+ ); } diff --git a/src/app/editoriais/brasil/page.tsx b/src/app/editoriais/brasil/page.tsx index f39e049..36bbf7f 100644 --- a/src/app/editoriais/brasil/page.tsx +++ b/src/app/editoriais/brasil/page.tsx @@ -1,7 +1,11 @@ export default function Brasil() { return ( -
- Brasil -
+ <> +
+

Brasil

+
+ + + ); } diff --git a/src/app/entretenimento/page.tsx b/src/app/entretenimento/page.tsx index 10bab98..541fb99 100644 --- a/src/app/entretenimento/page.tsx +++ b/src/app/entretenimento/page.tsx @@ -1,27 +1,23 @@ +'use client' import React from 'react'; -import { Article, Root } from '@/interface/interfaceNews'; +import { Article } from '@/interface/interfaceNews'; +import NewsApi from '@/api/news'; -export default async function Entertainment() { - const apiKey = process.env.REACT_APP_NEWS; //chave no arquivo env - const responseNews = await fetch( - `https://newsapi.org/v2/top-headlines?sources=google-news-br&apiKey=${apiKey}`, - { next: { revalidate: 3600 } } - ); - const dataNews: Root = await responseNews.json(); //analisa a resposta como tipo Root - console.log(dataNews); +export default function Entertainment() { + const dataNews = NewsApi(); return ( <>

Entretenimento

-
+
- {dataNews.articles.map((article: Article, index: number) => ( -
- {article.title} + {dataNews?.articles.map((article: Article, index: number) => ( +
+ {article.author}

{article.title}

{article.description}

@@ -29,7 +25,8 @@ export default async function Entertainment() { Saber mais
- ))} + ) + )}
diff --git a/src/app/esportes/page.tsx b/src/app/esportes/page.tsx index 830b929..f6a2afc 100644 --- a/src/app/esportes/page.tsx +++ b/src/app/esportes/page.tsx @@ -1,7 +1,9 @@ export default function Esportes() { return ( -
- Esportes -
+ <> +
+

Esportes

+
+ ); } diff --git a/src/app/header.tsx b/src/app/header.tsx index 9b7363e..365d61c 100644 --- a/src/app/header.tsx +++ b/src/app/header.tsx @@ -45,7 +45,7 @@ export default async function Header() {
-
+
{/*

{JSON.stringify(data.main.temp)}ºC

*/} @@ -56,12 +56,12 @@ export default async function Header() {
-
+
Home
-
+
Saúde @@ -108,5 +108,6 @@ export default async function Header() {
+ ); } diff --git a/src/app/midiakit/page.tsx b/src/app/midiakit/page.tsx index f860166..1124402 100644 --- a/src/app/midiakit/page.tsx +++ b/src/app/midiakit/page.tsx @@ -1,5 +1,9 @@ export default function Midiakit() { return ( -
Mídiakit
+ <> +
+

Midiakit

+
+ ) } \ No newline at end of file diff --git a/src/app/multmidia/page.tsx b/src/app/multmidia/page.tsx index 5887434..a5eb26e 100644 --- a/src/app/multmidia/page.tsx +++ b/src/app/multmidia/page.tsx @@ -1,8 +1,10 @@ export default function Multmidia() { return ( -
- Multmídia -
+ <> +
+

Multmidia

+
+ ); } diff --git a/src/app/page.tsx b/src/app/page.tsx index ca3d45d..f75aed9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,43 +1,42 @@ -import { Article, Root } from '@/interface/interfaceNews'; +'use client' +import NewsApi from '@/api/news'; +import { Article } from '@/interface/interfaceNews'; +import Image from 'next/image'; import React from 'react'; -export default async function Home() { - const apiKey = process.env.REACT_APP_NEWS; //chave no arquivo env - const responseNews = await fetch( - `https://newsapi.org/v2/top-headlines?sources=google-news-br&apiKey=${apiKey}`, - { next: { revalidate: 3600 } } - ); - const dataNews: Root = await responseNews.json(); //analisa a resposta como tipo Root +export default function Home() { + const dataNews = NewsApi(); + if (!dataNews) { + return

Carregando...

; + } + const mainArticle = dataNews.articles[0]; const otherArticles = dataNews.articles.slice(1); - console.log(dataNews); - return (
-
-

Notícias do Dia

+
+

Notícias do Dia

- -
+
-
+

Principal

- Imagem da Notícia + Imagem da Notícia

{mainArticle.title}

{mainArticle.description}

- Saber mais + Saber mais

Outras

diff --git a/src/app/servicos/page.tsx b/src/app/servicos/page.tsx index fd0953f..bc868a7 100644 --- a/src/app/servicos/page.tsx +++ b/src/app/servicos/page.tsx @@ -1,7 +1,9 @@ export default function Servicos() { return ( -
- Serviços -
+ <> +
+

Servicos

+
+ ); } diff --git a/src/app/video/page.tsx b/src/app/video/page.tsx index a4bd736..9361782 100644 --- a/src/app/video/page.tsx +++ b/src/app/video/page.tsx @@ -1,7 +1,9 @@ export default function Video() { return ( -
- Video -
+ <> +
+

Vídeos

+
+ ); }