-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,56 @@ | ||
// src/App.jsx | ||
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom' | ||
import HomePage from './pages/HomePage' | ||
import AboutPage from './pages/AboutPage' | ||
|
||
function App() { | ||
import { useState, useEffect } from 'react'; | ||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
import Navbar from '@/components/layout/Navbar'; | ||
import HomePage from '@/pages/HomePage'; | ||
import AboutPage from '@/pages/AboutPage'; | ||
import ScrapPage from '@/pages/ScrapPage'; | ||
|
||
export default function App() { | ||
const [bookmarkedIds, setBookmarkedIds] = useState([]); | ||
|
||
// 로컬 스토리지에서 북마크된 기사 ID 불러오기 | ||
useEffect(() => { | ||
const storedBookmarks = localStorage.getItem('bookmarkedIds'); | ||
if (storedBookmarks) { | ||
setBookmarkedIds(JSON.parse(storedBookmarks)); | ||
} | ||
}, []); | ||
|
||
// 북마크 상태 변경 시 로컬 스토리지에 저장 | ||
useEffect(() => { | ||
localStorage.setItem('bookmarkedIds', JSON.stringify(bookmarkedIds)); | ||
}, [bookmarkedIds]); | ||
|
||
const handleBookmark = (id) => { | ||
setBookmarkedIds(prevIds => | ||
prevIds.includes(id) ? prevIds.filter(bookmarkId => bookmarkId !== id) : [...prevIds, id] | ||
); | ||
}; | ||
|
||
return ( | ||
<Router> | ||
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-50"> | ||
{/* 네비게이션 메뉴 */} | ||
<nav className="mb-8"> | ||
<Link to="/" className="mx-4 text-blue-500 hover:underline"> | ||
Home | ||
</Link> | ||
<Link to="/about" className="mx-4 text-blue-500 hover:underline"> | ||
About | ||
</Link> | ||
</nav> | ||
|
||
{/* 라우트 설정 */} | ||
<Routes> | ||
<Route path="/" element={<HomePage />} /> | ||
<Route path="/about" element={<AboutPage />} /> | ||
</Routes> | ||
<div className="min-h-screen bg-[#F8F9FA]"> | ||
<Navbar /> | ||
<main> | ||
<Routes> | ||
<Route | ||
path="/" | ||
element={<HomePage bookmarkedIds={bookmarkedIds} handleBookmark={handleBookmark} />} | ||
/> | ||
<Route | ||
path="/about" | ||
element={<AboutPage />} | ||
/> | ||
<Route | ||
path="/scrap" | ||
element={<ScrapPage bookmarkedIds={bookmarkedIds} handleBookmark={handleBookmark} />} | ||
/> | ||
{/* 추가적인 라우트를 여기에 정의할 수 있습니다. */} | ||
</Routes> | ||
</main> | ||
</div> | ||
</Router> | ||
) | ||
); | ||
} | ||
|
||
export default App |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
// src/pages/AboutPage.jsx | ||
export default function AboutPage() { | ||
return ( | ||
<div className="flex flex-col items-center justify-center min-h-screen bg-green-100"> | ||
<h1 className="text-4xl font-bold">About Us</h1> | ||
<p className="mt-4 text-gray-700"> | ||
This is the About page created with Tailwind CSS. | ||
<div className="container mx-auto px-4 py-8"> | ||
<h2 className="text-2xl font-semibold mb-4">About Us</h2> | ||
<p className="text-gray-700"> | ||
Welcome to Newsy! We provide the latest news articles across various categories. | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,12 @@ | ||
// src/pages/HomePage.jsx | ||
import reactLogo from '../assets/react.svg' | ||
import viteLogo from '/vite.svg' | ||
import { useState } from 'react' | ||
|
||
export default function HomePage() { | ||
const [count, setCount] = useState(0) | ||
import NewsList from '@/components/news/NewsList'; | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100"> | ||
<header className="flex space-x-4"> | ||
<a href="https://vite.dev" target="_blank" rel="noopener noreferrer"> | ||
<img src={viteLogo} className="w-24 h-24" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank" rel="noopener noreferrer"> | ||
<img src={reactLogo} className="w-24 h-24" alt="React logo" /> | ||
</a> | ||
</header> | ||
|
||
<main className="text-center mt-8"> | ||
<h1 className="text-4xl font-bold">Welcome to Vite + React + Tailwind</h1> | ||
<p className="mt-4 text-gray-600"> | ||
This is a simple page created with Tailwind CSS in React. | ||
</p> | ||
|
||
<div className="mt-8 p-6 bg-white rounded shadow-lg"> | ||
<button | ||
onClick={() => setCount(count + 1)} | ||
className="px-4 py-2 text-white bg-blue-500 rounded hover:bg-blue-600" | ||
> | ||
Count is {count} | ||
</button> | ||
<p className="mt-4 text-gray-700"> | ||
Click the button to increase the count. | ||
</p> | ||
</div> | ||
</main> | ||
|
||
<footer className="mt-12 text-gray-500 text-sm"> | ||
<p>Click on the logos above to learn more about Vite and React.</p> | ||
</footer> | ||
</div> | ||
) | ||
export default function HomePage({ bookmarkedIds, handleBookmark }) { | ||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<h2 className="text-2xl font-semibold mb-6">Latest News</h2> | ||
<NewsList bookmarkedIds={bookmarkedIds} handleBookmark={handleBookmark} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
// 스크랩한 기사 페이지를 구성 | ||
// src/pages/ScrapPage.jsx | ||
|
||
import NewsCard from '@/components/news/NewsCard'; | ||
import { articles } from '@/data/articles'; | ||
|
||
export default function ScrapPage({ bookmarkedIds, handleBookmark }) { | ||
const bookmarkedArticles = articles.filter(article => bookmarkedIds.includes(article.id)); | ||
|
||
if (bookmarkedArticles.length === 0) { | ||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<h2 className="text-2xl font-semibold mb-4">Scrap Page</h2> | ||
<p className="text-gray-700">북마크된 기사가 없습니다.</p> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<h2 className="text-2xl font-semibold mb-6">북마크된 뉴스</h2> | ||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> | ||
{bookmarkedArticles.map((article) => ( | ||
<NewsCard | ||
key={article.id} | ||
article={article} | ||
onBookmark={handleBookmark} | ||
isBookmarked={true} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |