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

london-10-shadi-fakhri-full-stack-project #375

Closed
wants to merge 70 commits into from

Conversation

Shadi38
Copy link

@Shadi38 Shadi38 commented Aug 26, 2023

No description provided.

Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good, congrats!


function App() {

const [showVideos, setShowVideos] = useState(false);
const [loadData, setLoadData] = useState([]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more clear name than loadData you can think of for this state that describes what data is stored in this array?

Generally all apps deal with "data", so being specific can make things a lot more clear :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Daniel
thanks for your pieces of advice. I will try to do all of them.
here i changed loadData to loadVideo.

}
}

async function descClickHandler(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks a lot like the code in aseClickHandler - can you work out how to share code between them, rather than copying it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right I fixed it.

async function descClickHandler(e) {
e.preventDefault();
try {
const response = await fetch("https://web-server-5nme.onrender.com/videos");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you've loaded the data once, you probably don't actually need to load it again just to change the sort order - can you make this re-sort without fetching again?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted fetch from the function.

import ThumbUpIcon from "@mui/icons-material/ThumbUp";
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
function Videos(props) {
const {loadData,setLoadData}=props;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadData here sounds like it's probably a function you can call to load data, because its name starts with a verb. Can you think of a more clear name for this prop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it.

Comment on lines 7 to 8
const [titleData, setTitleData] = useState("");
const [urlData, setUrlData] = useState("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the Data suffixes on these state names are adding much - maybe remove them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed them to title and url

server/server.js Outdated
app.get("/videos", async function (req, res) {
const result = await db.query("SELECT * FROM videos");
if (result.rows.length === 0) {
return res.status(404).json({ error: "no videos found" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty common to only 404 if we're looking for one specific thing that couldn't be found, and if you're asking for "all the videos", to just return the empty array and let the client handle that. What you've done here isn't wrong, it's totally valid, just raising that there are alternatives too :) Can you think of some advantages/disadvantages of both approaches?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the good advice. I changed that.

// return res.json(orderVideos);
// });
//ordering by assending and dessending for example /videos?order=asc
app.get("/videos", async function (req, res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have a second handler function for the same method on the same path? Which one will end up getting used?

server/server.js Outdated
// });
//ordering by assending and dessending for example /videos?order=asc
app.get("/videos", async function (req, res) {
const result = await db.query("SELECT * FROM videos");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do the sorting in SQL rather than in javascript? (Both work, but doing it in SQL will probably be a bit faster :))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it.

//search video by query for example /videos/search?title=halleluja
app.get("/videos/search", function (req, res) {
const searchVideo = req.query.title;
const filteredVideo = videos.filter((video) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't use your database - can you rewrite this to do a SQL query (and like with the sorting, to do the filtering in SQL not JS? Again - the JS still works, but doing it in SQL will probably be faster).

server/server.js Outdated

//updating video with id
app.put("/videos/:id", function (req, res) {
const video = videos.find((m) => m.id == req.params.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this in SQL? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in Sql

@Shadi38
Copy link
Author

Shadi38 commented Sep 22, 2023 via email

@Dedekind561 Dedekind561 closed this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants