Skip to content

Commit

Permalink
[#246] Refactor: 코드 스플리팅 적용 (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
choi-ik authored Apr 24, 2024
1 parent 00be31c commit 28f880c
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 197 deletions.
112 changes: 112 additions & 0 deletions src/components/common/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Fragment } from "react";
import { Link, useNavigate } from "@tanstack/react-router";
import { CircleUser, FolderUp, Heart, Home, LogOut, Plus } from "lucide-react";
import { useOverlay } from "@toss/use-overlay";
import { useAtom, useAtomValue } from "jotai";
import LoginModal from "@/components/LoginModal";
import { cn } from "@/utils/tailwind";
import { getLocalStorage, setLocalStorage } from "@/utils/localStorage";
import { $userInformation } from "@/store/user";
import { REDIRECT_PATH, REFRESH_TOKEN } from "@/constants/auth";
import useLogout from "@/hooks/api/auth/useLogout";
import { $scrollDirection } from "@/store/scroll";

const NavigationFooter = () => {
const loginModalOverlay = useOverlay();
const [userInformation, setUserInformation] = useAtom($userInformation);
const refreshToken = getLocalStorage(REFRESH_TOKEN);
const navigate = useNavigate();
const { logout } = useLogout();
const role = refreshToken && userInformation ? userInformation.role : "GUEST";
const scrollDirection = useAtomValue($scrollDirection);

const handleClickButton = (eventName: string) => () => {
gtag("event", "page_view", { event_category: eventName });
};

const handleClickLogin = () => {
setLocalStorage(REDIRECT_PATH, "/");
loginModalOverlay.open(({ isOpen, close }) => <LoginModal isOpen={isOpen} onClose={close} />);
gtag("event", "modal_open", { event_category: "로그인_모달_띄우기" });
};

const handleClickLogout = () => {
logout(undefined, {
onSuccess: () => {
setUserInformation({
userId: 0,
email: "",
role: "GUEST",
});
navigate({ to: "/" });
},
});
};

return (
<div
className={cn(
"absolute bottom-0 z-10 flex h-60pxr w-full items-center justify-evenly bg-background text-text-primary shadow-[0_-1px_10px_1px_rgba(0,0,0,0.1)] shadow-adaptive-shadow transition-transform sm:hidden",
scrollDirection === "up" ? "" : "translate-y-full",
)}
>
<Link
to="/"
className="flex w-65pxr flex-col items-center gap-1"
activeProps={{ className: "text-primary" }}
onClick={handleClickButton("홈_페이지로_이동")}
>
<Fragment>
<Home size={24} strokeWidth={1.5} aria-label="홈" />
<span className="text-xs font-bold"></span>
</Fragment>
</Link>
<Link
to="/my-liked-zzals"
className={cn("flex w-65pxr flex-col items-center gap-1", role === "GUEST" ? "hidden" : "")}
activeProps={{ className: "text-primary" }}
onClick={handleClickButton("좋아요한_짤_페이지로_이동")}
>
<Fragment>
<Heart size={24} strokeWidth={1.5} aria-label="좋아요한 짤" />
<span className="text-xs font-bold">좋아요한 짤</span>
</Fragment>
</Link>
<Link
to="/upload-zzal"
className="flex w-65pxr flex-col items-center gap-1"
activeProps={{ className: "text-primary" }}
onClick={handleClickButton("짤_업로드_페이지로_이동")}
>
<div className="flex h-45pxr w-45pxr items-center justify-center rounded-full bg-primary font-bold text-white">
<Plus size={24} strokeWidth={2} aria-label="업로드" />
</div>
</Link>
<Link
to="/my-uploaded-zzals"
className={cn("flex w-65pxr flex-col items-center gap-1", role === "GUEST" ? "hidden" : "")}
activeProps={{ className: "text-primary" }}
onClick={handleClickButton("업로드한_짤_페이지로_이동")}
>
<Fragment>
<FolderUp size={24} strokeWidth={1.5} aria-label="업로드한 짤" />
<span className="text-xs font-bold">업로드한 짤</span>
</Fragment>
</Link>
{role === "GUEST" && (
<div onClick={handleClickLogin} className="flex w-65pxr flex-col items-center gap-1">
<CircleUser size={24} strokeWidth={1.5} aria-label="" />
<span className="text-xs font-bold">로그인</span>
</div>
)}
{role === "USER" && (
<div onClick={handleClickLogout} className="flex w-65pxr flex-col items-center gap-1">
<LogOut size={24} strokeWidth={1.5} aria-label="" />
<span className="text-xs font-bold">로그아웃</span>
</div>
)}
</div>
);
};

export default NavigationFooter;
117 changes: 54 additions & 63 deletions src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// This file is auto-generated by TanStack Router

import { createFileRoute, lazyRouteComponent } from "@tanstack/react-router"

// Import Routes

import { Route as rootRoute } from "./routes/__root"
Expand All @@ -18,15 +16,10 @@ import { Route as AuthenticationImport } from "./routes/_authentication"
import { Route as LayoutWithChatIndexRouteImport } from "./routes/_layout-with-chat/index.route"
import { Route as LayoutWithChatMyUploadedZzalsRouteImport } from "./routes/_layout-with-chat/my-uploaded-zzals/route"
import { Route as LayoutWithChatMyLikedZzalsRouteImport } from "./routes/_layout-with-chat/my-liked-zzals/route"
import { Route as AuthenticationUploadZzalIndexImport } from "./routes/_authentication/upload-zzal/index"
import { Route as AuthenticationDeleteAccountIndexImport } from "./routes/_authentication/delete-account/index"
import { Route as AuthenticationAdminReportsIndexImport } from "./routes/_authentication/admin/reports/index"
import { Route as AuthenticationAdminReportsImageIdIndexImport } from "./routes/_authentication/admin/reports/$imageId/index"

// Create Virtual Routes

const AuthenticationAdminReportsAdminReportsPendingComponentImport =
createFileRoute("/_authentication/admin/reports/AdminReports")()
import { Route as AuthenticationUploadZzalRouteImport } from "./routes/_authentication/upload-zzal/route"
import { Route as AuthenticationDeleteAccountRouteImport } from "./routes/_authentication/delete-account/route"
import { Route as AuthenticationAdminReportsRouteImport } from "./routes/_authentication/admin/reports/route"
import { Route as AuthenticationAdminReportsImageIdRouteImport } from "./routes/_authentication/admin/reports/$imageId/route"

// Create/Update Routes

Expand Down Expand Up @@ -67,43 +60,45 @@ const LayoutWithChatMyLikedZzalsRouteRoute =
),
)

const AuthenticationUploadZzalIndexRoute =
AuthenticationUploadZzalIndexImport.update({
path: "/upload-zzal/",
getParentRoute: () => AuthenticationRoute,
} as any)

const AuthenticationDeleteAccountIndexRoute =
AuthenticationDeleteAccountIndexImport.update({
path: "/delete-account/",
const AuthenticationUploadZzalRouteRoute =
AuthenticationUploadZzalRouteImport.update({
path: "/upload-zzal",
getParentRoute: () => AuthenticationRoute,
} as any)
} as any).lazy(() =>
import("./routes/_authentication/upload-zzal/route.lazy").then(
(d) => d.Route,
),
)

const AuthenticationAdminReportsIndexRoute =
AuthenticationAdminReportsIndexImport.update({
path: "/admin/reports/",
const AuthenticationDeleteAccountRouteRoute =
AuthenticationDeleteAccountRouteImport.update({
path: "/delete-account",
getParentRoute: () => AuthenticationRoute,
} as any)
} as any).lazy(() =>
import("./routes/_authentication/delete-account/route.lazy").then(
(d) => d.Route,
),
)

const AuthenticationAdminReportsAdminReportsPendingComponentRoute =
AuthenticationAdminReportsAdminReportsPendingComponentImport.update({
path: "/admin/reports/AdminReports",
const AuthenticationAdminReportsRouteRoute =
AuthenticationAdminReportsRouteImport.update({
path: "/admin/reports",
getParentRoute: () => AuthenticationRoute,
} as any).update({
pendingComponent: lazyRouteComponent(
() =>
import(
"./routes/_authentication/admin/reports/AdminReports.pendingComponent"
),
"pendingComponent",
} as any).lazy(() =>
import("./routes/_authentication/admin/reports/route.lazy").then(
(d) => d.Route,
),
})
)

const AuthenticationAdminReportsImageIdIndexRoute =
AuthenticationAdminReportsImageIdIndexImport.update({
path: "/admin/reports/$imageId/",
getParentRoute: () => AuthenticationRoute,
} as any)
const AuthenticationAdminReportsImageIdRouteRoute =
AuthenticationAdminReportsImageIdRouteImport.update({
path: "/$imageId",
getParentRoute: () => AuthenticationAdminReportsRouteRoute,
} as any).lazy(() =>
import("./routes/_authentication/admin/reports/$imageId/route.lazy").then(
(d) => d.Route,
),
)

// Populate the FileRoutesByPath interface

Expand All @@ -117,6 +112,14 @@ declare module "@tanstack/react-router" {
preLoaderRoute: typeof LayoutWithChatImport
parentRoute: typeof rootRoute
}
"/_authentication/delete-account": {
preLoaderRoute: typeof AuthenticationDeleteAccountRouteImport
parentRoute: typeof AuthenticationImport
}
"/_authentication/upload-zzal": {
preLoaderRoute: typeof AuthenticationUploadZzalRouteImport
parentRoute: typeof AuthenticationImport
}
"/_layout-with-chat/my-liked-zzals": {
preLoaderRoute: typeof LayoutWithChatMyLikedZzalsRouteImport
parentRoute: typeof LayoutWithChatImport
Expand All @@ -129,25 +132,13 @@ declare module "@tanstack/react-router" {
preLoaderRoute: typeof LayoutWithChatIndexRouteImport
parentRoute: typeof LayoutWithChatImport
}
"/_authentication/delete-account/": {
preLoaderRoute: typeof AuthenticationDeleteAccountIndexImport
parentRoute: typeof AuthenticationImport
}
"/_authentication/upload-zzal/": {
preLoaderRoute: typeof AuthenticationUploadZzalIndexImport
parentRoute: typeof AuthenticationImport
}
"/_authentication/admin/reports/AdminReports": {
preLoaderRoute: typeof AuthenticationAdminReportsAdminReportsPendingComponentImport
parentRoute: typeof AuthenticationImport
}
"/_authentication/admin/reports/": {
preLoaderRoute: typeof AuthenticationAdminReportsIndexImport
"/_authentication/admin/reports": {
preLoaderRoute: typeof AuthenticationAdminReportsRouteImport
parentRoute: typeof AuthenticationImport
}
"/_authentication/admin/reports/$imageId/": {
preLoaderRoute: typeof AuthenticationAdminReportsImageIdIndexImport
parentRoute: typeof AuthenticationImport
"/_authentication/admin/reports/$imageId": {
preLoaderRoute: typeof AuthenticationAdminReportsImageIdRouteImport
parentRoute: typeof AuthenticationAdminReportsRouteImport
}
}
}
Expand All @@ -156,11 +147,11 @@ declare module "@tanstack/react-router" {

export const routeTree = rootRoute.addChildren([
AuthenticationRoute.addChildren([
AuthenticationDeleteAccountIndexRoute,
AuthenticationUploadZzalIndexRoute,
AuthenticationAdminReportsAdminReportsPendingComponentRoute,
AuthenticationAdminReportsIndexRoute,
AuthenticationAdminReportsImageIdIndexRoute,
AuthenticationDeleteAccountRouteRoute,
AuthenticationUploadZzalRouteRoute,
AuthenticationAdminReportsRouteRoute.addChildren([
AuthenticationAdminReportsImageIdRouteRoute,
]),
]),
LayoutWithChatRoute.addChildren([
LayoutWithChatMyLikedZzalsRouteRoute,
Expand Down
Loading

0 comments on commit 28f880c

Please sign in to comment.