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

๐Ÿ› ๏ธ refactor: ๊ฐœ์ธ ๋ฐ ๊ฐœ๊ฐœ์ธ ์žฅ์†Œ ์ž…๋ ฅ ์ฝ”๋“œ ๋ฆฌํŒฉํ† ๋ง #15

Merged
merged 4 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@heroicons/react": "^2.1.3",
"@tanstack/react-query": "^5.29.2",
"axios": "^1.6.8",
"framer-motion": "^11.1.1",
"framer-motion": "^11.2.10",
"jotai": "^2.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/apis/enter-location.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import axiosInstance from '.';
import { axiosInstance } from '.';

export const fetchIsValidRoomId = async (roomId: string) => {
const { data } = await axios.get(`/api/rooms/${roomId}/duplicate`);
Expand Down
26 changes: 12 additions & 14 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import axios from 'axios';

const REFRESH_URL = ''; // Refresh Token์„ ์‚ฌ์šฉํ•ด ์ƒˆ๋กœ์šด Access Token์„ ๋ฐ›์„๋•Œ ์š”์ฒญํ•˜๋Š” URL
const REFRESH_URL = '';

// access token ์žฌ๋ฐœ๊ธ‰ํ•˜๋Š” ํ•จ์ˆ˜
export const axiosInstance = axios.create({
baseURL: '',
});

// ๋กœ๊ทธ ์•„์›ƒ ํ•จ์ˆ˜
const logout = () => {
localStorage.removeItem('accessToken');
};

// accessToken, refreshToken ์žฌ๋ฐœ๊ธ‰ํ•˜๋Š” ํ•จ์ˆ˜
const getNewToken = async () => {
try {
const accessToken = '';
Expand All @@ -17,15 +26,6 @@ const getNewToken = async () => {
}
};

// ๋กœ๊ทธ ์•„์›ƒ ํ•จ์ˆ˜
const logout = () => {
localStorage.removeItem('accessToken');
};

const axiosInstance = axios.create({
baseURL: '',
});

// ์š”์ฒญ ์ธํ„ฐ์…‰ํ„ฐ
axiosInstance.interceptors.request.use(
(config) => {
Expand Down Expand Up @@ -60,8 +60,6 @@ axiosInstance.interceptors.response.use(
localStorage.setItem('refreshToken', newToken.refreshToken);
config.headers.Authorization = `Bearer ${newToken.accessToken}`;
}
return axios(config); // ์žฌ์š”์ฒญ
return axiosInstance(config); // ์žฌ์š”์ฒญ
},
);

export default axiosInstance;
124 changes: 87 additions & 37 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,129 @@
import { Link, useLocation } from 'react-router-dom';

import HomeLogo from '@/assets/imgs/Navbar/home-logo.svg?react';
// import HomeLogoActive from '@/assets/imgs/Navbar/home-logo-active.svg?react';
import PinLogo from '@/assets/imgs/Navbar/pin-logo.svg?react';
import VoteLogo from '@/assets/imgs/Navbar/vote-logo.svg?react';
import ClockLogo from '@/assets/imgs/Navbar/clock-logo.svg?react';

import styled from 'styled-components';
import { useState } from 'react';
import { AnimatePresence, motion } from 'framer-motion';

interface LogoProps {
active: boolean;
// ๋ฉ”๋‰ด enum ์ •์˜
enum Menu {
Home = 'home',
Pin = 'pin',
Vote = 'vote',
Clock = 'clock',
}

export default function SideBar() {
const location = useLocation();
const [isOpen, setIsOpen] = useState(false);
const [selectedMenu, setSelectedMenu] = useState<Menu | null>(null);

const handleMenuClick = (menu: Menu) => {
setIsOpen(true);
setSelectedMenu(menu);
};

const handleCloseSidebar = () => {
setIsOpen(false);
setSelectedMenu(null);
};

return (
<>
<SidebarContainer>
<ul className="flex flex-col gap-2 *:font-semibold">
<NavItem className="mt-16 transition">
<Link to="/">
<Logo active={location.pathname === '/'}>
{/* {location.pathname === '/' ? <HomeLogoActive /> : <HomeLogo />} */}
<HomeLogo />
</Logo>
</Link>
<ul>
<NavItem className="transition" onClick={() => handleMenuClick(Menu.Home)}>
<Logo>
<HomeLogo />
</Logo>
</NavItem>
<NavItem className="transition">
<Link to="/midpoint">
<Logo active={location.pathname === '/midpoint'}>
<PinLogo />
</Logo>
</Link>
<NavItem className="transition" onClick={() => handleMenuClick(Menu.Pin)}>
<Logo>
<PinLogo />
</Logo>
</NavItem>
<NavItem className="transition">
<Link to="/vote">
<Logo active={location.pathname === '/vote'}>
<VoteLogo />
</Logo>
</Link>
<NavItem className="transition" onClick={() => handleMenuClick(Menu.Vote)}>
<Logo>
<VoteLogo />
</Logo>
</NavItem>
<NavItem className="transition">
<Link to="/time">
<Logo active={location.pathname === '/time'}>
<ClockLogo />
</Logo>
</Link>
<NavItem className="transition" onClick={() => handleMenuClick(Menu.Clock)}>
<Logo>
<ClockLogo />
</Logo>
</NavItem>
</ul>
</SidebarContainer>
<AnimatePresence initial={false}>
{isOpen && (
<Content
initial={{ x: -100, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: -100, opacity: 0 }}
transition={{ type: 'tween', duration: 0.2 }}
>
<CloseButton onClick={handleCloseSidebar}>Close</CloseButton>
{selectedMenu === Menu.Home && <p>Home Content</p>}
{selectedMenu === Menu.Pin && <p>Pin Content</p>}
{selectedMenu === Menu.Vote && <p>Vote Content</p>}
{selectedMenu === Menu.Clock && <p>Clock Content</p>}
</Content>
)}
</AnimatePresence>
</>
);
}

const SidebarContainer = styled.div`
position: sticky;
position: absolute;
top: 0;
left: 0;
height: 100vh;
min-width: 120px;
width: 100px;
background-color: #5142ff;
color: white;
z-index: 1000;
padding-top: 50px;
`;

const NavItem = styled.li`
text-transform: uppercase;
cursor: pointer;
padding: 1rem;
list-style: none;
text-align: center;
`;

const Logo = styled.span<LogoProps>`
const Logo = styled.span`
width: 3.5rem;
height: 3.5rem;
border-radius: 100%;
display: block;
margin: 0 auto;
background-color: ${({ active }) => (active ? 'white' : 'transparent')};
`;

const Content = styled(motion.div)`
position: absolute;
top: 0;
left: 100px;
height: 100vh;
width: 350px;
background-color: white;
z-index: 999;
padding: 1rem;
overflow-y: auto;
`;

const CloseButton = styled.button`
margin: 1rem;
padding: 0.5rem 1rem;
background-color: #5142ff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;

&:hover {
background-color: #524abd;
}
`;
Loading
Loading