Skip to content

Commit

Permalink
Revert "Fetch URL for likes added"
Browse files Browse the repository at this point in the history
This reverts commit 5ea28fc.
  • Loading branch information
evelinabe committed Jan 18, 2021
1 parent ef4a67a commit 3df28ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
16 changes: 1 addition & 15 deletions code/src/components/Thought.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@ export const Thought = ({
id,
onLikedThought
}) => {
const [likedThought, setLikedThougt] = useState([]);

const getLikedThought = (id) => {
const updatedThoughts = thoughts.map((thought) => {
if (id === thought._id) {
thought.hearts += 1;
}
return thought;
});
setThoughts(updatedThoughts);
if (!likedThought.includes(id)) {
setLikedThougt([...likedThought, id]);
}
};
return (
<div className="thought-container">
<p className="thought" id={id}>
{message}
</p>
<div className="liked-container">
<ThoughtLikes id={id} onLikedThought={() => onLikedThought(id)} />
<ThoughtLikes id={id} onLikedThought={onLikedThought} />
<p className="liked"> x {hearts}</p>
</div>
<p className="thought-time">{time}</p>
Expand Down
9 changes: 1 addition & 8 deletions code/src/components/ThoughtLikes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import React from 'react';
import { LIKES_URL } from '../urls';

export const onLikedThought = (id) => {
fetch(`${LIKES_URL}`, {
method: 'POST',
body: '',
headers: { 'Content-Type': 'application/json' }
}).then(() => getLikedThought(id));

export const ThoughtLikes = ({ id, onLikedThought }) => {
return (
<button type="button" onClick={() => onLikedThought(id)} className="liked-button">
<span role="img" aria-label="red heart" className="heart">❤️</span>
Expand Down
21 changes: 21 additions & 0 deletions code/src/components/ThoughtList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@ import { Thought } from './Thought'
import { THOUGHTS_URL } from '../urls';

export const ThoughtList = ({ thoughts, setThoughts }) => {
const [likedThought, setLikedThougt] = useState([]);

const getLikedThought = (id) => {
const updatedThoughts = thoughts.map((thought) => {
if (id === thought._id) {
thought.hearts += 1;
}
return thought;
});
setThoughts(updatedThoughts);
if (!likedThought.includes(id)) {
setLikedThougt([...likedThought, id]);
}
};

const onLikedThought = (id) => {
fetch(`${THOUGHTS_URL}/${id}/like`, {
method: 'POST',
body: '',
headers: { 'Content-Type': 'application/json' }
}).then(() => getLikedThought(id));
};

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion code/src/urls.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const THOUGHTS_URL = 'https://happy-thoughts-technigo.herokuapp.com/thoughts'
export const THOUGHTS_URL = 'https://happiest-happy-thoughts.herokuapp.com/thoughts'

0 comments on commit 3df28ee

Please sign in to comment.