Skip to content

Commit d8e7d4f

Browse files
committed
Enhance PopularNews, Search, and Stories components with reading mode and font size adjustments
1 parent 3c34707 commit d8e7d4f

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

‎src/PopularNews.jsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { useGlobalContext } from './Context';
33

44
const PopularNews = () => {
5-
const { isLoading, popularNews } = useGlobalContext();
5+
const { isLoading, popularNews, fontSize, readingMode } = useGlobalContext();
66

77
if (isLoading) {
88
return <p>Loading popular news...</p>;
@@ -15,10 +15,18 @@ const PopularNews = () => {
1515
<ul>
1616
{popularNews.map((news) => (
1717
<li key={news.objectID} className="news-item">
18-
<a href={news.url} target="_blank" rel="noopener noreferrer">
18+
<a href={news.url} target="_blank" rel="noopener noreferrer"
19+
style={{
20+
fontSize: readingMode === true ? `${fontSize}px` : "",
21+
}}
22+
>
1923
{news.title}
2024
</a>
21-
<span className="badge">💬 {news.num_comments || 0} comments</span>
25+
<span className="badge"
26+
style={{
27+
fontSize: readingMode === true ? `${fontSize}px` : "",
28+
}}
29+
>💬 {news.num_comments || 0} comments</span>
2230
</li>
2331
))}
2432
</ul>

‎src/Search.jsx‎

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
import React from 'react'
2-
import{useGlobalContext} from './Context'
2+
import { useGlobalContext } from './Context'
33

44

55
const Search = () => {
6-
const {query,searchFn,showPopularNews}=useGlobalContext();
6+
const { query, searchFn, showPopularNews, setReadingMode, readingMode } = useGlobalContext();
77
return (
88
<>
9-
<h1 className="heading">
10-
<span className='subText'>T</span>ech
11-
<span className='subText'>P</span>ulse
12-
</h1>
13-
14-
{!showPopularNews &&
15-
<form>
16-
<div>
17-
<input type="text" placeholder="search here"
18-
value={query}
19-
onChange={(e)=> searchFn(e.target.value)}
20-
/>
9+
<div
10+
style={{
11+
display: "flex",
12+
justifyContent: "center",
13+
}}>
14+
<button
15+
onClick={() => setReadingMode(!readingMode)}
16+
>
17+
{readingMode ? "Exit Reading Mode" : "Enter Reading Mode"}
18+
</button>
2119
</div>
22-
</form>
23-
}
20+
<h1 className="heading">
21+
<span className='subText'>T</span>ech
22+
<span className='subText'>P</span>ulse
23+
</h1>
24+
25+
{!showPopularNews &&
26+
<form>
27+
<div>
28+
<input type="text" placeholder="search here"
29+
value={query}
30+
onChange={(e) => searchFn(e.target.value)}
31+
/>
32+
</div>
33+
</form>
34+
}
2435
</>
25-
26-
36+
37+
2738
)
2839
}
2940

‎src/Stories.jsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React, { useCallback, memo } from "react";
22
import { useGlobalContext } from "./Context";
33

44
const Stories = () => {
5-
const { hits, isLoading, bookMark, setBookMark } = useGlobalContext();
5+
const { hits, isLoading, bookMark, setBookMark, readingMode, fontSize } = useGlobalContext();
66

77
const toggleBookmark = useCallback((news) => {
88
const isBookmarked = bookMark.some((item) => item.objectID === news.objectID);
9-
9+
1010
const updatedBookmarks = isBookmarked
1111
? bookMark.filter((item) => item.objectID !== news.objectID)
1212
: [...bookMark, news];
@@ -28,13 +28,23 @@ const Stories = () => {
2828

2929
return (
3030
<div className="card" key={objectID}>
31-
<h2>{title}</h2>
32-
<p>
31+
<h2
32+
style={{
33+
fontSize: readingMode === true ? `${fontSize}px` : "",
34+
}}
35+
>{title}</h2>
36+
<p style={{
37+
fontSize: readingMode === true ? `${fontSize}px` : "",
38+
}}>
3339
By <span>{author}</span> | <span>{num_comments}</span> comments
3440
</p>
3541

3642
<div className="card-button">
37-
<a href={url} target="_blank" rel="noreferrer">
43+
<a href={url} target="_blank" rel="noreferrer"
44+
style={{
45+
fontSize: readingMode === true ? `${fontSize}px` : "",
46+
}}
47+
>
3848
Read More
3949
</a>
4050

@@ -49,7 +59,7 @@ const Stories = () => {
4959
);
5060
})}
5161

52-
<p>Made with ❤️ by
62+
<p>Made with ❤️ by
5363
<a href="https://www.linkedin.com/in/choudhury-mehbub-alam-b6b191219/">
5464
DevLeo
5565
</a>

0 commit comments

Comments
 (0)