'use client'; import './style.scss'; import { useState, useEffect } from 'react'; import { fetchApi, throwError, getDateTime } from '@/lib/utils/client'; import type { NewsArticlesResponse } from '@/types/response/news'; import Loading from '@/app/component/Loading'; import Pagination from '@/app/component/Pagination'; function stripHtml(html: string | null): string { if (!html) { return ''; } const doc = new DOMParser().parseFromString(html, 'text/html'); return doc.body.textContent || ''; } export default function View() { const [error, setError] = useState(''); const [loading, setLoading] = useState(true); const [page, setPage] = useState(1); const [data, setData] = useState({ total: 0, list: [] }); useEffect(() => { if (error) { alert(error); setError(''); } }, [error]); useEffect(() => { setLoading(true); fetchApi(`/api/news/articles?page=${page}&perPage=20`).then((res) => { throwError(res); setData(res.data!); }).catch(err => { setError(err.message); }).finally(() => { setLoading(false); }); }, [page]); return (
{ loading && }

NEWS


{data.list.length > 0 ? ( data.list.map((row) => (
{row.title} { (e.target as HTMLImageElement).src = '/resources/no-image.png'; }} />
{row.title} {/*{row.sourceName || row.feedSourceName}*/} {getDateTime(row.publishedAt)}
{stripHtml(row.description)}

)) ) : ( !loading &&

뉴스가 없습니다.

)}
{data.list.length > 0 && ( )}
); }