Skip to content

Commit

Permalink
🛠 Update bookmark button style
Browse files Browse the repository at this point in the history
  • Loading branch information
jgudo committed Mar 21, 2021
1 parent 4b3f0cc commit 26b598e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/.eslintcache

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions frontend/src/components/main/BookmarkButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import { useDidMount } from '~/hooks';
import { bookmarkPost } from '~/services/api';

interface IProps {
Expand All @@ -10,6 +11,8 @@ interface IProps {

const BookmarkButton: React.FC<IProps> = (props) => {
const [isBookmarked, setIsBookmarked] = useState(props.initBookmarkState || false);
const [isLoading, setLoading] = useState(false);
const didMount = useDidMount(true);

useEffect(() => {
setIsBookmarked(props.initBookmarkState);
Expand All @@ -18,8 +21,13 @@ const BookmarkButton: React.FC<IProps> = (props) => {
const dispatchBookmark = async () => {
try {
// state = TRUE | FALSE
setLoading(true);
const { state } = await bookmarkPost(props.postID);
setIsBookmarked(state);

if (didMount) {
setIsBookmarked(state);
setLoading(false);
}

if (state) {
toast.dark('Post successfully bookmarked.', {
Expand All @@ -33,13 +41,14 @@ const BookmarkButton: React.FC<IProps> = (props) => {
});
}
} catch (e) {
didMount && setLoading(false);
console.log(e);
}
}

return (
<div>
{ props.children({ dispatchBookmark, isBookmarked })}
{ props.children({ dispatchBookmark, isBookmarked, isLoading })}
</div>
);
};
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/main/Options/PostOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ const PostOptions: React.FC<IProps> = (props) => {
</>
) : (
<BookmarkButton postID={props.post.id} initBookmarkState={props.post.isBookmarked}>
{({ dispatchBookmark, isBookmarked }) => (
{({ dispatchBookmark, isBookmarked, isLoading }) => (
<h4
className="p-4 flex items-center cursor-pointer dark:text-white"
className="group p-4 flex items-center cursor-pointer dark:text-white hover:bg-indigo-500 hover:text-white"
onClick={dispatchBookmark}
>
{isBookmarked ? (
<StarFilled className="text-red-600 text-2xl p-2 flex justify-center items-center rounded-full hover:bg-red-100" />
<StarFilled className="text-red-600 group-hover:text-white text-2xl p-2 flex justify-center items-center rounded-full" />
) : (
<StarOutlined className="text-red-600 text-2xl p-2 flex justify-center items-center rounded-full hover:bg-red-100" />
<StarOutlined className="text-red-600 group-hover:text-white text-2xl p-2 flex justify-center items-center rounded-full" />
)}
<span>{isBookmarked ? 'Unbookmark Post' : 'Bookmark Post'} </span>
<span className={`${isLoading && 'opacity-50'}`}>{isBookmarked ? 'Unbookmark Post' : 'Bookmark Post'} </span>
</h4>
)}
</BookmarkButton>
Expand Down
2 changes: 1 addition & 1 deletion frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = {
display: ['responsive'],
padding: ['important', 'responsive'],
borderRadius: ['important', 'responsive'],
textColor: ['important', 'hover', 'dark'],
textColor: ['important', 'group-hover', 'hover', 'dark'],
borderColor: ['important', 'focus', 'hover', 'dark'],
outlineOffset: ['hover'],
boxShadow: ['responsive', 'dark'],
Expand Down

1 comment on commit 26b598e

@vercel
Copy link

@vercel vercel bot commented on 26b598e Mar 21, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.