Skip to content
Open
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
26 changes: 26 additions & 0 deletions week4/week4_assignment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.env
50 changes: 50 additions & 0 deletions week4/week4_assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions week4/week4_assignment/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions week4/week4_assignment/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>API통신</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions week4/week4_assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "week4_assignment",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.28.0",
"styled-components": "^6.1.13"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-router-dom": "^5.3.3",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
}
}
16 changes: 16 additions & 0 deletions week4/week4_assignment/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RouterProvider } from "react-router-dom";
import { router } from "./Router";
import GlobalStyle from "./styles/GlobalStyle";
import { ThemeProvider } from "styled-components";
import theme from "./styles/\btheme";

const App = () => {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />
<RouterProvider router={router} />
</ThemeProvider>
);
};

export default App;
21 changes: 21 additions & 0 deletions week4/week4_assignment/src/Roots.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Outlet } from "react-router-dom";
import styled from "styled-components";

const Roots = () => {
return (
<OutletContainer>
<Outlet />
</OutletContainer>
);
};

export default Roots;

const OutletContainer = styled.main`
width: 100%;
height: 100dvh;
display: flex;
justify-content: center;

background: ${({ theme }) => theme.colors.orange7};
`;
30 changes: 30 additions & 0 deletions week4/week4_assignment/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createBrowserRouter } from "react-router-dom";
import LoginPage from "./pages/LoginPage/LoginPage";
import SignUpPage from "./pages/SignUpPage/SignUpPage";
import MyPage from "./pages/Mypage/MyPage";
import Roots from "./Roots";

export const router = createBrowserRouter([
{
path: "/",
element: <Roots />,
children: [
{
index: true,
element: <LoginPage />,
},
{
path: "/login",
element: <LoginPage />,
},
{
path: "/signup",
element: <SignUpPage />,
},
{
path: "/mypage",
element: <MyPage />,
},
],
},
]);
84 changes: 84 additions & 0 deletions week4/week4_assignment/src/components/MyPage/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import styled from "styled-components";
import { useNavigate } from "react-router-dom";

interface HeaderProps {
activeTab: string;
setActiveTab: (tab: string) => void;
}

const Header = ({ activeTab, setActiveTab }: HeaderProps) => {
const navigate = useNavigate();

const handleLogout = () => {
localStorage.removeItem("authToken");
navigate("/login");
};

return (
<HeaderContainer>
<HeaderRight>
<Title>마이페이지</Title>
<Nav>
<NavItem
active={activeTab === "hobby"}
onClick={() => setActiveTab("hobby")}
>
취미
</NavItem>
<NavItem
active={activeTab === "info"}
onClick={() => setActiveTab("info")}
>
내 정보
</NavItem>
Comment on lines +22 to +33

Choose a reason for hiding this comment

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

p5: 저는 취미랑 정보페이지를 따로 만들어서 이동하게 했는데, 이렇게도 구현할 수 있었네요. 배워갑니다!

</Nav>
</HeaderRight>
<LogoutButton onClick={handleLogout}>로그아웃</LogoutButton>
</HeaderContainer>
);
};

export default Header;

const HeaderContainer = styled.header`
width: 100%;
padding: 1rem 2rem;
background: ${({ theme }) => theme.colors.bookmark_click};
display: flex;
align-items: center;
justify-content: space-between;
color: ${({ theme }) => theme.colors.white1};
`;

const HeaderRight = styled.div`
display: flex;
gap: 5rem;
`;

const Title = styled.h1`
font-size: 1.5rem;
font-weight: 700;
`;

const Nav = styled.nav`
display: flex;
gap: 1.5rem;
`;

const NavItem = styled.span<{ active: boolean }>`
font-size: 1.2rem;
cursor: pointer;
color: ${({ active }) => (active ? "white" : "#ddd")};

Choose a reason for hiding this comment

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

p4: 저는 active 상태에 따라 다른 색을 보여주고 싶을때, inactive, active로 이름을 붙여서 사용하는 편인데 참고해주셔도 좋을것 같아요! 여기 하나는 #ddd로 색상이 정의되어있어서 제안드립니다 ㅎㅎ

font-weight: ${({ active }) => (active ? "bold" : "normal")};
`;

const LogoutButton = styled.button`
display: flex;
width: 5rem;
height: 2rem;
font-size: 1rem;
background: none;
border: none;
color: ${({ theme }) => theme.colors.white1};
cursor: pointer;
`;
Loading