-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 레이아웃 개선 * refactor: 이벤트 위임 개선 * fix: navigation 로그인 상태 반영
- Loading branch information
Showing
10 changed files
with
97 additions
and
39 deletions.
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
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 |
---|---|---|
@@ -1,26 +1,9 @@ | ||
import { getUser } from "@/state/handle-state"; | ||
|
||
export const Header = () => { | ||
const user = getUser().user; | ||
|
||
const content = ` | ||
<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> | ||
<li><a href="/profile" class="text-gray-600">프로필</a></li> | ||
<li> | ||
${ | ||
user | ||
? '<a href="/login" id="logout" class="text-gray-600">로그아웃</a>' | ||
: '<a href="/login" id="login" class="text-gray-600">로그인</a>' | ||
} | ||
</li> | ||
</ul> | ||
</nav> | ||
`; | ||
<header class="bg-blue-600 text-white p-4 sticky top-0"> | ||
<h1 class="text-2xl font-bold">항해플러스</h1> | ||
</header> | ||
`; | ||
|
||
return content; | ||
}; |
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,17 @@ | ||
export const NavigationLinks = (navigator) => { | ||
const { id, href, text } = navigator; | ||
const currentPath = window.location.pathname; | ||
const isCurrentPath = currentPath === href; | ||
|
||
return ` | ||
<li> | ||
<a | ||
href="${href}" | ||
id="${id}" | ||
class="${isCurrentPath ? "font-bold text-blue-600" : "text-gray-600"}" | ||
> | ||
${text} | ||
</a> | ||
</li> | ||
`; | ||
}; |
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,54 @@ | ||
import { clearUser, getUser } from "@/state/handle-state"; | ||
import { NavigationLinks } from "@/layout/NavigationLinks"; | ||
|
||
export const Navigator = () => { | ||
const user = getUser().user; | ||
|
||
const content = ` | ||
<nav class="bg-white shadow-md p-2 sticky top-14"> | ||
<ul class="flex justify-around"> | ||
${navigatorList({ isLoggedIn: user }) | ||
.map((navigator) => NavigationLinks(navigator)) | ||
.join("")} | ||
</ul> | ||
</nav> | ||
`; | ||
|
||
return content; | ||
}; | ||
|
||
const navigatorList = ({ isLoggedIn }) => [ | ||
{ | ||
id: "home", | ||
href: "/", | ||
text: "홈", | ||
}, | ||
...(isLoggedIn | ||
? [ | ||
{ | ||
id: "profile", | ||
href: "/profile", | ||
text: "프로필", | ||
}, | ||
{ | ||
id: "logout", | ||
href: "/login", | ||
text: "로그아웃", | ||
}, | ||
] | ||
: [ | ||
{ | ||
id: "register", | ||
href: "/login", | ||
text: "로그인", | ||
}, | ||
]), | ||
]; | ||
|
||
document.addEventListener("click", (e) => { | ||
if (e.target.id === "logout") { | ||
e.preventDefault(); | ||
clearUser(); | ||
alert("로그아웃 되었습니다."); | ||
} | ||
}); |
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 @@ | ||
export const PlainLayout = (content) => { | ||
return ` | ||
<main id="root" class="bg-gray-100 flex items-center justify-center min-h-screen"> | ||
${content} | ||
</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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { DefaultLayout } from "@/layout/DefaultLayout"; | ||
export { PlainLayout } from "@/layout/PlainLayout"; | ||
export { Header } from "@/layout/Header"; | ||
export { Navigator } from "@/layout/Navigator"; | ||
export { Footer } from "@/layout/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
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
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
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