-
Notifications
You must be signed in to change notification settings - Fork 77
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
[15팀 이규리] [Chapter 1-1] 프레임워크 없이 SPA 만들기 #17
Open
9yurilee
wants to merge
35
commits into
hanghae-plus:main
Choose a base branch
from
9yurilee:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1f9f326
refactor: 페이지 및 컴포넌트 모듈 분리
9yurilee 81248b1
refactor: 헤더, 푸터 모듈 적용
9yurilee d79060c
feat: 라우팅 구현 및 라우팅 예외 처리(#1, #7)
9yurilee 742d43f
fix: 네비게이션 a태그 검색 방법 수정
9yurilee 596dbc6
refactor: UI/이벤트 파일 분리
9yurilee 622c479
feat: 로그인 기능 추가
9yurilee 6bdf1e6
refactor: 초기화함수 대표함수 initEvents로 설정 및 적용
9yurilee 16883ab
feat: 네비게이션 탭 노출조건 localStorage의 user 활용
9yurilee 954a47f
refactor: export default로 변경
9yurilee 37ff5ca
feat: 로그인 전 profile 접근 막기 추가
9yurilee 1927a35
chore: 로그인 input id 수정
9yurilee 318968c
feat: 로그아웃 기능 추가
1cf4f0f
fix: 로그인 버튼과 프로필 업데이트 버튼과의 중복 이슈 수정
7085e1c
feat: 프로필 업데이트 기능 기본 작업 완료
e931a37
feat: 네비게이션 상태 관리 적용 기초 작업
f724373
fix: 로그인 폼 이벤트 id 타겟 수정
21c1073
fix: 함수 연결 이슈 초기화함수 분리해서 적용하는 것으로 수정
d999b8f
fix: 로그인 유효성 검사 조건 수정
8e7ed74
refactor: 로그아웃 이벤트 네비게이션 이벤트핸들러로 위치 이동
9yurilee 77f66d5
refactor: 로그아웃 이벤트 네비게이션 이벤트핸들러로 위치 이동
a4e0bd6
Merge branch 'main' of https://github.com/9yurilee/front_4th_chapter1-1
9yurilee 0530c7c
fix: 프로필 업데이트 로그인 submit과 중복 문제해결
9yurilee 905ff67
refactor: 로그아웃 이벤트 네비게이션 이벤트 핸들러에서 처리하는 것으로 수정
9yurilee 5ea3228
docs: 필요없는 주석 제거 및 추가
9yurilee 5659e3c
chore: 개행 맞춤
9yurilee 08c5453
fix: e2e 테스트 SPA 기본 기능 1 수정
9yurilee 916d2ee
feat: 로그인한 사용자가 로그인 페이지 접근 막기(심화)
9yurilee 69dfdb4
style: 네비게이션 홈 탭 스타일링 추가
9yurilee f525cdb
refactor: props drilling 수정 위해 Header의 로그인 유무는 state활용하는 것으로 수정
9yurilee ac4e194
fix: form 이벤트 버블링으로 로그인 안되는 문제 해결
9yurilee 461a27f
refactor: 상수 적용, 로컬스토리지 핸들러 분리 등 리팩토링 진행
9yurilee 6a40333
fix: handleLogin username 옵셔널 체이닝 추가
9yurilee 88a00ee
refactor: 복잡도 증가로 인한 상수화 복구
9yurilee 9c4924c
feat: 해시 라우터 추가 완료
9yurilee ed86af9
rename: 컴포넌트명 변경
9yurilee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Footer = () => ` | ||
<footer class="bg-gray-200 p-4 text-center"> | ||
<p>© 2024 항해플러스. All rights reserved.</p> | ||
</footer> | ||
`; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { state } from "../../store/store"; | ||
|
||
const Header = () => { | ||
const LoginMenu = (isLoggedIn) => { | ||
return isLoggedIn | ||
? ` | ||
<li><a href="/profile" class="text-gray-600">프로필</a></li> | ||
<li><a href="/login" id="logout" class="text-gray-600">로그아웃</a></li> | ||
` | ||
: ` | ||
<li><a href="/login" class="text-gray-600">로그인</a></li> | ||
`; | ||
}; | ||
|
||
return ` | ||
<header class="bg-blue-600 text-white p-4 sticky top-0"> | ||
<h1 class="text-2xl font-bold">항해플러스</h1> | ||
</header> | ||
|
||
<nav class="bg-white shadow-md p-2 sticky top-14"> | ||
<ul class="flex justify-around"> | ||
<li><a href="/" class="text-blue-600 font-bold">홈</a></li> | ||
${LoginMenu(state.user)} | ||
</ul> | ||
</nav> | ||
`; | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import Header from "../common/Header"; | ||
import Footer from "../common/Footer"; | ||
|
||
export const HomePage = () => ` | ||
<div class="bg-gray-100 min-h-screen flex justify-center"> | ||
<div class="max-w-md w-full"> | ||
${Header()} | ||
<main class="p-4"> | ||
<div class="mb-4 bg-white rounded-lg shadow p-4"> | ||
<textarea class="w-full p-2 border rounded" placeholder="무슨 생각을 하고 계신가요?"></textarea> | ||
<button class="mt-2 bg-blue-600 text-white px-4 py-2 rounded">게시</button> | ||
</div> | ||
|
||
<div class="space-y-4"> | ||
|
||
<div class="bg-white rounded-lg shadow p-4"> | ||
<div class="flex items-center mb-2"> | ||
<img src="https://via.placeholder.com/40" alt="프로필" class="rounded-full mr-2"> | ||
<div> | ||
<p class="font-bold">홍길동</p> | ||
<p class="text-sm text-gray-500">5분 전</p> | ||
</div> | ||
</div> | ||
<p>오늘 날씨가 정말 좋네요. 다들 좋은 하루 보내세요!</p> | ||
<div class="mt-2 flex justify-between text-gray-500"> | ||
<button>좋아요</button> | ||
<button>댓글</button> | ||
<button>공유</button> | ||
</div> | ||
</div> | ||
|
||
<div class="bg-white rounded-lg shadow p-4"> | ||
<div class="flex items-center mb-2"> | ||
<img src="https://via.placeholder.com/40" alt="프로필" class="rounded-full mr-2"> | ||
<div> | ||
<p class="font-bold">김철수</p> | ||
<p class="text-sm text-gray-500">15분 전</p> | ||
</div> | ||
</div> | ||
<p>새로운 프로젝트를 시작했어요. 열심히 코딩 중입니다!</p> | ||
<div class="mt-2 flex justify-between text-gray-500"> | ||
<button>좋아요</button> | ||
<button>댓글</button> | ||
<button>공유</button> | ||
</div> | ||
</div> | ||
|
||
<div class="bg-white rounded-lg shadow p-4"> | ||
<div class="flex items-center mb-2"> | ||
<img src="https://via.placeholder.com/40" alt="프로필" class="rounded-full mr-2"> | ||
<div> | ||
<p class="font-bold">이영희</p> | ||
<p class="text-sm text-gray-500">30분 전</p> | ||
</div> | ||
</div> | ||
<p>오늘 점심 메뉴 추천 받습니다. 뭐가 좋을까요?</p> | ||
<div class="mt-2 flex justify-between text-gray-500"> | ||
<button>좋아요</button> | ||
<button>댓글</button> | ||
<button>공유</button> | ||
</div> | ||
</div> | ||
|
||
<div class="bg-white rounded-lg shadow p-4"> | ||
<div class="flex items-center mb-2"> | ||
<img src="https://via.placeholder.com/40" alt="프로필" class="rounded-full mr-2"> | ||
<div> | ||
<p class="font-bold">박민수</p> | ||
<p class="text-sm text-gray-500">1시간 전</p> | ||
</div> | ||
</div> | ||
<p>주말에 등산 가실 분 계신가요? 함께 가요!</p> | ||
<div class="mt-2 flex justify-between text-gray-500"> | ||
<button>좋아요</button> | ||
<button>댓글</button> | ||
<button>공유</button> | ||
</div> | ||
</div> | ||
|
||
<div class="bg-white rounded-lg shadow p-4"> | ||
<div class="flex items-center mb-2"> | ||
<img src="https://via.placeholder.com/40" alt="프로필" class="rounded-full mr-2"> | ||
<div> | ||
<p class="font-bold">정수연</p> | ||
<p class="text-sm text-gray-500">2시간 전</p> | ||
</div> | ||
</div> | ||
<p>새로 나온 영화 재미있대요. 같이 보러 갈 사람?</p> | ||
<div class="mt-2 flex justify-between text-gray-500"> | ||
<button>좋아요</button> | ||
<button>댓글</button> | ||
<button>공유</button> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
${Footer()} | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const LoginPage = () => ` | ||
<main class="bg-gray-100 flex items-center justify-center min-h-screen"> | ||
<div class="bg-white p-8 rounded-lg shadow-md w-full max-w-md"> | ||
<h1 class="text-2xl font-bold text-center text-blue-600 mb-8">항해플러스</h1> | ||
<form id="login-form"> | ||
<div class="mb-4"> | ||
<input type="text" id="username" placeholder="사용자 이름" class="w-full p-2 border rounded"> | ||
</div> | ||
<div class="mb-6"> | ||
<input type="password" id="password" placeholder="비밀번호" class="w-full p-2 border rounded"> | ||
</div> | ||
<button type="submit" class="w-full bg-blue-600 text-white p-2 rounded font-bold">로그인</button> | ||
</form> | ||
<div class="mt-4 text-center"> | ||
<a href="#" class="text-blue-600 text-sm">비밀번호를 잊으셨나요?</a> | ||
</div> | ||
<hr class="my-6"> | ||
<div class="text-center"> | ||
<button class="bg-green-500 text-white px-4 py-2 rounded font-bold">새 계정 만들기</button> | ||
</div> | ||
</div> | ||
</main> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const NotFoundPage = () => ` | ||
<main class="bg-gray-100 flex items-center justify-center min-h-screen"> | ||
<div class="bg-white p-8 rounded-lg shadow-md w-full text-center" style="max-width: 480px"> | ||
<h1 class="text-2xl font-bold text-blue-600 mb-4">항해플러스</h1> | ||
<p class="text-4xl font-bold text-gray-800 mb-4">404</p> | ||
<p class="text-xl text-gray-600 mb-8">페이지를 찾을 수 없습니다</p> | ||
<p class="text-gray-600 mb-8"> | ||
요청하신 페이지가 존재하지 않거나 이동되었을 수 있습니다. | ||
</p> | ||
<a href="/" class="bg-blue-600 text-white px-4 py-2 rounded font-bold"> | ||
홈으로 돌아가기 | ||
</a> | ||
</div> | ||
</main> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Header from "../common/Header"; | ||
import Footer from "../common/Footer"; | ||
import { state } from "../../store/store"; | ||
|
||
export const ProfilePage = () => { | ||
return ` | ||
<div id="root"> | ||
<div class="bg-gray-100 min-h-screen flex justify-center"> | ||
<div class="max-w-md w-full"> | ||
${Header()} | ||
<main class="p-4"> | ||
<div class="bg-white p-8 rounded-lg shadow-md"> | ||
<h2 class="text-2xl font-bold text-center text-blue-600 mb-8"> | ||
내 프로필 | ||
</h2> | ||
<form id="profile-form"> | ||
<div class="mb-4"> | ||
<label | ||
for="username" | ||
class="block text-gray-700 text-sm font-bold mb-2" | ||
>사용자 이름</label | ||
> | ||
<input | ||
type="text" | ||
id="username" | ||
name="username" | ||
value="${state.user?.username || ""}" | ||
class="w-full p-2 border rounded" | ||
/> | ||
</div> | ||
<div class="mb-4"> | ||
<label | ||
for="email" | ||
class="block text-gray-700 text-sm font-bold mb-2" | ||
>이메일</label | ||
> | ||
<input | ||
type="email" | ||
id="email" | ||
name="email" | ||
value="${state.user?.email || ""}" | ||
class="w-full p-2 border rounded" | ||
/> | ||
</div> | ||
<div class="mb-6"> | ||
<label | ||
for="bio" | ||
class="block text-gray-700 text-sm font-bold mb-2" | ||
>자기소개</label | ||
> | ||
<textarea | ||
id="bio" | ||
name="bio" | ||
rows="4" | ||
class="w-full p-2 border rounded" | ||
>${state.user?.bio || ""}</textarea | ||
> | ||
</div> | ||
<button | ||
type="submit" | ||
class="w-full bg-blue-600 text-white p-2 rounded font-bold" | ||
> | ||
프로필 업데이트 | ||
</button> | ||
</form> | ||
</div> | ||
</main> | ||
|
||
${Footer()} | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { navigateTo } from "../router/router.js"; | ||
import { setState } from "../store/store.js"; | ||
import { setStorage } from "../utils/storageHandler.js"; | ||
|
||
export const handleLogin = () => { | ||
const username = document.getElementById("username")?.value || ""; | ||
|
||
const userInfo = { username, email: "", bio: "" }; | ||
|
||
if (username) { | ||
setState({ user: userInfo }); // 상태 업데이트 | ||
|
||
setStorage("user", userInfo); | ||
|
||
navigateTo("/"); | ||
} else { | ||
alert("아이디 혹은 비밀번호를 확인해주세요."); | ||
} | ||
}; | ||
|
||
export const initLogin = () => { | ||
document.body.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
|
||
// login-form을 정확히 찾기 위해 closest 사용 | ||
const loginForm = e.target.closest("#login-form"); | ||
if (!loginForm) return; | ||
|
||
handleLogin(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { navigateTo } from "../router/router.js"; | ||
import { clearStorage } from "../utils/storageHandler.js"; | ||
import { setState } from "./../store/store"; | ||
|
||
export const handleNavigation = (e) => { | ||
const selected = e.target.closest("a"); | ||
if (!selected) return; | ||
|
||
const isLogoutBtn = selected.hasAttribute("id") && selected.id === "logout"; | ||
|
||
if (isLogoutBtn) { | ||
clearStorage(); | ||
setState({ user: null }); // 상태 초기화 | ||
navigateTo("/login"); | ||
} else { | ||
const path = selected.getAttribute("href"); | ||
navigateTo(path); | ||
} | ||
}; | ||
|
||
export const initNavigation = () => { | ||
document.body.addEventListener("click", handleNavigation); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { setStorage } from "../utils/storageHandler"; | ||
import { setState } from "./../store/store"; | ||
|
||
const handleProfileUpdate = () => { | ||
const usernameInput = document.getElementById("username")?.value; | ||
const emailInput = document.getElementById("email")?.value; | ||
const bioInput = document.getElementById("bio")?.value; | ||
|
||
const updatedInfo = { | ||
username: usernameInput, | ||
email: emailInput, | ||
bio: bioInput, | ||
}; | ||
|
||
setStorage("user", updatedInfo); | ||
|
||
setState({ user: updatedInfo }); | ||
}; | ||
|
||
export const initProfile = () => { | ||
document.body.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
|
||
// profile-form을 정확히 찾기 위해 closest 사용 | ||
const profileForm = e.target.closest("#profile-form"); | ||
if (!profileForm) return; | ||
|
||
handleProfileUpdate(); | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLogoutBtn을 함수로 만들면 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아이고 석호님- 2주차 후딱 끝내고 리뷰해주신거 확인해야지 했는데 2주차를 꽉꽉 채워버렸네요..!
오 한 곳에서만 쓰인다는 생각에 함수로 뺄 생각은 한 번도 못해본 것 같아요!
단순히 변수로만 생각했었는데, 의견 감사합니다!