Skip to content

Commit

Permalink
💄 Add: 즐겨찾기 개수 뱃지 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
romantech committed Nov 10, 2021
1 parent eca22b6 commit c3dc58b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/Components/Nav.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
/* eslint-disable react/prop-types */
import React from 'react';
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { Layout, Menu } from 'antd';
import { Layout, Menu, Badge } from 'antd';
import { sitemap } from '../Constants';

const { Header } = Layout;
const badgeStyle = {
backgroundColor: 'gray',
color: 'white',
boxShadow: 'none',
};

// withRouter를 이용해 라우터 호출이 아닌 컴포넌트도 history 객체에 접근하도록 설정
const Nav = ({ history }) => {
const { favorites } = useSelector(state => state.favoriteListReducer);
const { pathname } = history.location;
const [badgeCount, setBadgeCount] = useState(favorites?.length);

return (
<Header>
Expand All @@ -23,9 +31,15 @@ const Nav = ({ history }) => {
key={path}
onClick={() => {
history.push(path);
if (path === '/favorite') {
setBadgeCount(0);
}
}}
>
{name}
{path === '/favorite' && path !== pathname && (
<Badge count={badgeCount} style={badgeStyle} offset={[0, -25]} />
)}
</Menu.Item>
))}
</Menu>
Expand Down
7 changes: 5 additions & 2 deletions src/Pages/FavoritePage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled, { css } from 'styled-components/macro';
import { useSelector, useDispatch } from 'react-redux';
import { Modal, message } from 'antd';
import { Modal, message, Empty } from 'antd';
import { clearFavorite } from '../Modules/favoriteList';
import FavoriteEntry from '../Components/FavoriteEntry';
import { ContainerStyle } from '../Styles/commonStyles';
Expand Down Expand Up @@ -41,7 +41,10 @@ const FavoritePage = () => {
{favorites.length > 0 ? (
renderData.map(entry => <FavoriteEntry key={entry.id} data={entry} />)
) : (
<h1>空空如也 🍻</h1>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description="아직 즐겨찾기한 맥주가 없네요"
/>
)}
</S.ListWrapper>
</S.Container>
Expand Down

1 comment on commit c3dc58b

@vercel
Copy link

@vercel vercel bot commented on c3dc58b Nov 10, 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.