Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create context for global app state #66

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ec92ee2
Started button to add favorite feeds
salamisodikiolawale Jan 29, 2023
def44ba
Created button to open future pop up
Jan 29, 2023
5202f86
Added favorite dialog component / pop up to display favorites
Jan 29, 2023
56a9c29
Moved searchHistory component call from UserForm.jsx to App.js to avo…
Jan 29, 2023
c0799ad
Merge pull request #1 from MargotRasamy/dev-sodiki
salamisodikiolawale Jan 29, 2023
bcafd1c
Merge pull request #2 from MargotRasamy/dev-margot
MargotRasamy Jan 29, 2023
3457921
Removed warnings
Jan 31, 2023
88359f0
Merge pull request #3 from MargotRasamy/dev-margot
MargotRasamy Jan 31, 2023
3c97afa
refactor the class component into function component for consistency
salamisodikiolawale Jan 31, 2023
fa01126
Stored favorites feed in the localstorage
salamisodikiolawale Jan 31, 2023
20073f4
Styled pop up favorite item
Jan 31, 2023
c9f7cb7
Add data in popup
salamisodikiolawale Jan 31, 2023
11bbe62
Merge pull request #4 from MargotRasamy/dev-sodiki
salamisodikiolawale Jan 31, 2023
cc3c92c
Moved state properties for favorite items to App.js for global synchr…
Jan 31, 2023
8f47cb6
Synchronized favorite feeds globally
MargotRasamy Jan 31, 2023
81d5c0f
Send getFeed method to FavoriteItem component to see favorite on item…
Jan 31, 2023
09c8ec8
Added a method to format URL to avoid duplicate favorites when URL en…
Jan 31, 2023
e835c60
Created method to format URL
MargotRasamy Jan 31, 2023
8feac3d
URL formatting to avoid duplicate favorites
Feb 6, 2023
9037684
Merge pull request #7 from MargotRasamy/dev-margot
MargotRasamy Feb 6, 2023
b738b50
Removed unused props
Feb 6, 2023
a7058f7
Removed unnecessary condition
Feb 6, 2023
f92a0e5
Removed unnecessary comment
Feb 6, 2023
8f45855
Initialized context and reducer with initial state and use dispatch f…
Feb 6, 2023
112a44e
Finalized context for all data related to global app state
Feb 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.App {
display: flex;
flex-direction: column;
text-align: center;
}

Expand Down Expand Up @@ -49,6 +51,14 @@ img {
border: 1px solid #ccc;
}

.favorite{
cursor: pointer;
margin: 0.5rem auto;
}
.favorite:hover {
fill: rgb(250, 218, 148);
}

@keyframes spin {
0% {
transform: rotate(0deg);
Expand All @@ -65,4 +75,85 @@ img {
to {
transform: rotate(360deg);
}


}

.options-nav {
display: flex;
}

/* Favorites list section */
.favorites-list-section {
/* padding: 1rem; */
display: flex;
flex-direction: column;
justify-content: space-between;
}

.favorite-item {
background-color: rgb(242, 242, 242);
border-radius: 2px;
margin: 1rem;
padding:1rem;
display: flex;
justify-content: space-between;
}

.favorite-item .action-container {
cursor: pointer;
display: flex;
justify-content: space-between;
/* height: 200px; */
}

.favorite-item .action-container > * {
margin: 5px;
}

.favorite-item .img-container {
flex-grow: 0;
flex-shrink: 0;
flex-basis: 150px;
height: 150px;
}

.favorite-item .img-container > img {
max-height: 100%;
max-width: 100%;
object-position: center;
object-fit: cover;
}

.favorite-item .action-container .informations {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
}

.favorite-item .informations > .title {
font-weight: bold;
font-size: 21px;
}

.favorite-item .informations > .description {
text-overflow: ellipsis;
overflow: hidden;
/* CSS properties for ellipsis overflow after 5 lines of text */
display: block;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
max-height: 5 * 1.6rem;
}

@media screen and (max-width: 600px) {
.favorite-item {
flex-direction: column;
}

.favorite-item .action-container {
flex-direction: column;
}
}
102 changes: 35 additions & 67 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useContext } from "react";
import {
Button,
Dialog,
Expand All @@ -12,66 +12,30 @@ import "./App.css";
import EpisodeList from "./components/EpisodeList";
import UserForm from "./components/UserForm";
import LoadingStatus from "./components/LoadingStatus";
import FavoriteDialog from "./components/FavoriteDialog";
import { useRef } from "react";
import SearchHistory from "./components/SearchHistory";
import { Context } from "./context/Context";

const App = ({ fetching }) => {
const [fetched, setFetched] = useState({});
const [onFetching, setFetching] = useState(false);
const [previousFeeds, setPreviousFeeds] = useState([]);
const [past, setPast] = useState(false);
const [error, setError] = useState(false);
const App = () => {
const { state, dispatch } = useContext(Context);

const getFeed = (event) => {
setFetching((prev) => !prev);
if (event.preventDefault != null)
event.preventDefault();
const feed_url = event.target.elements.feed_url.value;
const Parser = require("rss-parser");
const parser = new Parser({
customFields: {
item: [["enclosure", { keepArray: true }]],
},
});
const favoritesPopUpRef = useRef();

const CORS_PROXY = "https://cors-anywhere.herokuapp.com/";

if (feed_url) {
const loadRSS = async () => {
try {
const feed = await parser.parseURL(CORS_PROXY + feed_url);
setFetched({
episodes: feed.items,
program_title: feed.title,
program_image: feed.image.url,
program_description: feed.description,
});
setFetching((prev) => !prev);
setPreviousFeeds([...new Set([...previousFeeds, feed_url])]);
setPast(true);

return setError(false);
} catch (error) {
setFetching(false);
setError(true);

return error;
}
};

return loadRSS();
} else {
return;
}
};
// Check if the current feed is filled.
const isCurrentFeedFetched = () => {
return state.currentFeed.program_link && state.currentFeed.program_link !== '';
}

const handleClose = () => {
setFetching(false);
setError(false);
dispatch({ type: 'SET_FETCHING', payload: false });
dispatch({ type: 'SET_ERROR', payload: false });
};

const renderAlert = () => (
<div>
<Dialog
open={error}
open={state.error}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
Expand All @@ -95,23 +59,27 @@ const App = ({ fetching }) => {
<header className="App-header">
<h1 className="App-title">quick-feed</h1>
</header>
<UserForm
getFeed={getFeed}
onClick={() => setFetching(true)}
past={past}
previous_feeds={[...previousFeeds]}
/>
{error ? renderAlert() : <div />}
{!past ? <p>Please enter an RSS feed</p> : <div></div>}
<LoadingStatus fetching={onFetching} />
<UserForm />

{isCurrentFeedFetched() ? <>
<nav className="options-nav">
<SearchHistory />
<div style={{ padding: "20px 0" }}><Button onClick={() => {favoritesPopUpRef.current.handleClickOpen()}}>Favorites Section</Button></div>
</nav>
<EpisodeList
episodes={state.currentFeed.episodes}
program_title={state.currentFeed.program_title}
program_description={state.currentFeed.program_description}
program_image={state.currentFeed.program_image}
program_link={state.currentFeed.program_link}
/>
</> : <p>Please enter an RSS feed</p>}

{state.error ? renderAlert() : <div />}
<LoadingStatus fetching={state.onFetching} />

<EpisodeList
episodes={fetched.episodes}
program_title={fetched.program_title}
program_description={fetched.program_description}
program_image={fetched.program_image}
fetching={fetching}
/>
{/* Favorite feeds list dialog component */}
<FavoriteDialog ref={favoritesPopUpRef} />
</div>
);
};
Expand Down
23 changes: 0 additions & 23 deletions src/components/Episode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,4 @@ const Episode = ({ link, title }) => {
);
};

// class Episode extends Component {
// divStyles = {
// width: "77vw",
// float: "right",
// marginRight: "1vw",
// };
// render() {
// return (
// <div className="list-group" style={this.divStyles}>
// <a
// href={this.props.link}
// className="list-group-item list-group-item-action text-left"
// >
// {this.props.title}
// </a>
// <Collapse>
// <p>{this.props.title}</p>
// </Collapse>
// </div>
// );
// }
// }

export default Episode;
Loading