Skip to content

Commit

Permalink
♻️ Context 관련 리팩터링 (#149)
Browse files Browse the repository at this point in the history
* design: QA

* refactor: font-yoon, font-noto 제거

* refactor: nvmrc 추가

* refactor: 메인 화면 제거

* refactor: NavbarContext 리팩터링

* refactor: SegmentNode의 children에서 null 제거

* refactor: MarginedMain 구현

* refactor: SessionContextProvider 제거

* feat: SessionContext 재구현

* fix: .internal 관련 빌드 에러 임시 수정

* feat: 주석 처리한 LoginVisible 주석 해제
  • Loading branch information
yeolyi authored Mar 8, 2024
1 parent f9fa92c commit e6abe3b
Show file tree
Hide file tree
Showing 118 changed files with 615 additions and 679 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.11.1
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"i18n-ally.localesPaths": ["messages"]
}
2 changes: 1 addition & 1 deletion actions/newsServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { News, NewsPreviewList } from '@/types/news';
import { PostSearchQueryParams } from '@/types/post';

import { deleteRequest, getRequest } from '../apis/serverIndex';
import { deleteRequest, getRequest } from '../apis/common/server';

const newsPath = '/news';

Expand Down
2 changes: 1 addition & 1 deletion actions/noticeServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NoticePreviewList, Notice } from '@/types/notice';
import { PostSearchQueryParams } from '@/types/post';

import { deleteRequest, getRequest, patchRequest } from '../apis/serverIndex';
import { deleteRequest, getRequest, patchRequest } from '../apis/common/server';

const noticePath = '/notice';

Expand Down
2 changes: 1 addition & 1 deletion actions/reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cookies } from 'next/dist/client/components/headers';

import { Reservation, ReservationPostBody, ReservationPreview } from '@/types/reservation';

import { deleteRequest, getRequest, postRequest } from '../apis';
import { deleteRequest, getRequest, postRequest } from '../apis/common/client';

const reservationPath = '/reservation';

Expand Down
2 changes: 1 addition & 1 deletion actions/seminarServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PostSearchQueryParams } from '@/types/post';
import { SeminarList, Seminar } from '@/types/seminar';

import { deleteRequest, getRequest } from '../apis/serverIndex';
import { deleteRequest, getRequest } from '../apis/common/server';

const seminarPath = '/seminar';

Expand Down
38 changes: 38 additions & 0 deletions actions/sessionActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use server';

import { cookies } from 'next/headers';

import { UserState } from '@/contexts/SessionContext';

import { getRequest } from '@/apis/common/server';

import { COOKIE_SESSION_ID } from '@/constants/network';

export const getMockAuth = async () => {
// TODO: getRequest 함수로 구현
// 지금은 /v1이 segment에 없어서 임시로 fetch를 사용해 직접 구현
const resp = await fetch(`https://cse-dev-waffle.bacchus.io/api/mock-login`, {
method: 'GET',
});

const cookie = resp.headers.getSetCookie()[0];
const value = cookie.split(/=|;/)[1];

cookies().set(COOKIE_SESSION_ID, value, { httpOnly: true, secure: true });
};

export const removeAuth = () => {
cookies().delete(COOKIE_SESSION_ID);
};

export const getIsStaff = async (): Promise<UserState> => {
if (cookies().get(COOKIE_SESSION_ID) === undefined) return 'logout';

try {
const resp = await getRequest<{ isStaff: boolean }>('/user/is-staff');
return resp.isStaff ? 'staff' : 'non-staff';
} catch {
// removeAuth();
return 'logout';
}
};
14 changes: 0 additions & 14 deletions apis/academics.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { getMockAcademicsGuide, getMockCourseChanges, getMockCourses } from '@/data/academics';

import { Course, CourseChange, Guide } from '@/types/academics';

import { getRequest } from '.';

type StudentType = 'undergraduate' | 'graduate';

export const getAcademicsGuide = getMockAcademicsGuide;

export const getCourses = getMockCourses;

export const getEngCourses = getMockCourses;

export const getCourseChanges = getMockCourseChanges;

// export const getAcademicsGuide = (type: StudentType) =>
// getRequest(`/academics/${type}/guide`) as Promise<Guide>;

// export const getCourses = (type: StudentType) =>
// getRequest(`/academics/${type}/courses`) as Promise<Course[]>;

// export const getCourseChanges = (): Promise<CourseChange[]> => courseChangesData;
2 changes: 1 addition & 1 deletion apis/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ImportantPreview, SlidePreview } from '@/types/admin';

import { getRequest } from '.';
import { getRequest } from './common/client';

export const getSlides = (pageNum: number) =>
getRequest(
Expand Down
37 changes: 6 additions & 31 deletions apis/adminServer.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
import { ImportantPreview, SlidePreview } from '@/types/admin';

import { getRequest, patchRequest } from './serverIndex';
import { patchRequest } from './common/server';

// export const getSlides = (pageNum: number) =>
// getRequest(
// '/admin/slide',
// { pageNum },
// {
// next: { tags: ['slide'] },
// },
// ) as Promise<{
// slides: SlidePreview[];
// total: number;
// }>;

// export const getImportants = (pageNum: number) =>
// getRequest(
// '/admin/important',
// { pageNum },
// {
// next: { tags: ['important'] },
// },
// ) as Promise<{
// importants: ImportantPreview[];
// total: number;
// }>;

export const getSlides = async (
page: number,
): Promise<{ slides: SlidePreview[]; total: number }> => ({
export const getSlides = async (): Promise<{ slides: SlidePreview[]; total: number }> => ({
slides: [],
total: 0,
});

export const getImportants = async (
page: number,
): Promise<{ importants: ImportantPreview[]; total: number }> => ({
export const getImportants = async (): Promise<{
importants: ImportantPreview[];
total: number;
}> => ({
importants: [],
total: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion apis/index.ts → apis/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const checkError = (response: Response) => {
export class NetworkError extends Error {
statusCode: number;
constructor(statusCode: number) {
super(`네트워크 에러\nstatus: ${statusCode}`);
super(`${statusCode} 에러`);
this.statusCode = statusCode;
}
}
2 changes: 1 addition & 1 deletion apis/serverIndex.ts → apis/common/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cookies } from 'next/headers';

import { BASE_URL, checkError } from '@/apis';
import { BASE_URL, checkError } from '@/apis/common/client';

import { objToQueryString } from '@/utils/convertParams';

Expand Down
6 changes: 1 addition & 5 deletions apis/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { getMockMainContents } from '@/data/main';

import { MainContents } from '@/types/main';

import { getRequest } from '.';
import { getRequest } from './common/client';

export const getMainContents = () => getRequest('') as Promise<MainContents>;

// export const getMainContents = getMockMainContents;
2 changes: 1 addition & 1 deletion apis/news.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PATCHNewsBody, POSTNewsBody } from '@/types/news';

import { patchRequest, postRequest } from '.';
import { patchRequest, postRequest } from './common/client';

const newsPath = '/news';

Expand Down
2 changes: 1 addition & 1 deletion apis/notice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { POSTNoticeBody, PatchNoticeBody } from '@/types/notice';

import { patchRequest, postRequest } from '.';
import { patchRequest, postRequest } from './common/client';

const noticePath = '/notice';

Expand Down
2 changes: 1 addition & 1 deletion apis/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NewsSearchResult, NoticeSearchResult } from '@/types/search';

import { getRequest } from '.';
import { getRequest } from './common/client';

export const getNoticeSearch = (params: {
keyword: string;
Expand Down
2 changes: 1 addition & 1 deletion apis/seminar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PATCHSeminarBody, POSTSeminarBody } from '@/types/seminar';

import { patchRequest, postRequest } from '.';
import { patchRequest, postRequest } from './common/client';

const seminarPath = '/seminar';

Expand Down
20 changes: 16 additions & 4 deletions app/.internal/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import RootLayout from '../[locale]/layout';

export default function Layout({ children }: { children: React.ReactNode }) {
return <RootLayout params={{ locale: 'ko' }}>{children}</RootLayout>;
// TODO: 디자인 적용
export default async function RootLayout({
children,
params,
}: {
children: React.ReactNode;
params: { locale: string };
}) {
return (
<html
lang={params.locale}
className="bg-neutral-900 font-normal text-neutral-800 sm:min-w-[1000px]"
>
<body>{children}</body>
</html>
);
}
29 changes: 29 additions & 0 deletions app/[locale]/MarginedMain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import { ReactNode } from 'react';

import {
NAVBAR_CLOSED_WIDTH_REM,
NAVBAR_EXPANDED_WIDTH_REM,
} from '@/components/layout/navbar/NavbarRoot';

import useCurrentSegmentNode from '@/utils/hooks/useCurrentSegmentNode';
import useResponsive from '@/utils/hooks/useResponsive';
import { main as mainNode } from '@/utils/segmentNode';

export default function MarginedMain({ children }: { children: ReactNode }) {
const node = useCurrentSegmentNode();
const { screenType } = useResponsive();

let marginLeft = '';
if (screenType === 'desktop') {
marginLeft =
node === mainNode ? `${NAVBAR_EXPANDED_WIDTH_REM}rem` : `${NAVBAR_CLOSED_WIDTH_REM}rem`;
}

return (
<main className="flex h-full flex-col overflow-scroll" style={{ marginLeft }}>
{children}
</main>
);
}
4 changes: 1 addition & 3 deletions app/[locale]/about/facilities/FacilitiesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ function FacilitiesRow({ name, description, location, imageURL, border }: Facili
}`}
>
<div className="flex w-[35.5rem] flex-col">
<h3 className="font-noto mb-[.69rem] text-base font-bold leading-5 text-neutral-800">
{name}
</h3>
<h3 className=" mb-[.69rem] text-base font-bold leading-5 text-neutral-800">{name}</h3>
<HTMLViewer htmlContent={description} />
<div className="flex items-center gap-[0.12rem]">
<Distance />
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/about/future-careers/CareerStat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function CareerStat({ stat }: { stat: FutureCareers['stat'] }) {
return (
<div className="flex flex-col gap-3">
<div className="mb-[0.8rem] flex items-center gap-2">
<h3 className="font-noto text-base font-bold leading-[1.625rem]">졸업생 진로 현황</h3>
<h3 className=" text-base font-bold leading-[1.625rem]">졸업생 진로 현황</h3>
<Dropdown
contents={Object.keys(stat).reverse()}
selectedIndex={selectedCareerStatIndex}
Expand Down
4 changes: 1 addition & 3 deletions app/[locale]/about/future-careers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export default async function GreetingsPage() {
function CareerCompanies({ companies }: { companies: FutureCareers['companies'] }) {
return (
<div>
<h3 className="font-noto mb-[0.8rem] text-base font-bold leading-[1.625rem]">
졸업생 창업 기업
</h3>
<h3 className=" mb-[0.8rem] text-base font-bold leading-[1.625rem]">졸업생 창업 기업</h3>
<div className="inline-block border-y-[1px] border-neutral-200 text-sm font-normal">
<CompanyTableHeader />
<ol>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/academics/graduate/scholarship/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function GraduateScholarshipListPage() {
return (
<PageLayout titleType="big">
<HTMLViewer htmlContent={description} className="mt-7" />
<div className="font-noto mt-10 flex flex-col">
<div className=" mt-10 flex flex-col">
<h3 className="border-b-[1px] border-b-neutral-200 pb-2 text-[20px] font-bold leading-10">
장학금 종류
</h3>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/academics/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MajorCategoryPageLayout from '@/components/layout/pageLayout/MajorCategoryPageLayout';

export default async function AcademicsPage() {
return <MajorCategoryPageLayout subtitle="Learning CSE" twoDimensional />;
return <MajorCategoryPageLayout subtitle="Learning CSE" />;
}
2 changes: 0 additions & 2 deletions app/[locale]/academics/undergraduate/course-changes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const TIME_SPOTS: { year: number; margin?: string; isLast?: boolean }[] = [
];

const getSelectedChanges = (selectedYear: number, data: CourseChange[]) => {
console.log('선택 연도', selectedYear);
console.log(data);
if (selectedYear <= YEAR_LIMIT) return data.filter((d) => d.year <= YEAR_LIMIT);

const change = data.find((d) => d.year === selectedYear);
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/academics/undergraduate/curriculum/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function UndergradutecurriculumPage({
href={`/${params.locale}/academics/undergraduate/courses`}
className={`peer absolute flex h-10 flex-row items-center p-4 text-center text-sm text-main-orange duration-300 hover:text-[#141212]`}
>
<span className="font-yoon mr-2 font-medium tracking-[-0.019em]">
<span className="mr-2 font-medium tracking-[-0.019em]">
교과목 정보, 선수 교과목 로드맵
</span>
<span className="material-symbols-outlined text-[20px] font-light">navigate_next</span>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/academics/undergraduate/scholarship/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function UndergraduateScholarshipListPage() {
return (
<PageLayout titleType="big">
<HTMLViewer htmlContent={description} className="mt-7" />
<div className="font-noto mt-10 flex flex-col">
<div className=" mt-10 flex flex-col">
<h3 className="border-b-[1px] border-b-neutral-200 pb-2 text-[20px] font-bold leading-10">
장학금 종류
</h3>
Expand Down
6 changes: 3 additions & 3 deletions app/[locale]/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getImportants, getSlides } from '@/apis/admin';

import ImportantManagement from '@/components/admin/important/ImportantManagement';
import SlideManagement from '@/components/admin/slide/SlideManagement';
import LoginStaffVisible from '@/components/common/auth/LoginStaffVisible';
import LoginVisible from '@/components/common/LoginVisible';
import SelectionList from '@/components/common/selection/SelectionList';
import PageLayout from '@/components/layout/pageLayout/PageLayout';

Expand Down Expand Up @@ -72,15 +72,15 @@ interface AdminPageLayoutProps {
function AdminPageLayout({ selectedMenu, children }: AdminPageLayoutProps) {
return (
<PageLayout title="관리자 메뉴" titleType="big" titleMargin="mb-9">
<LoginStaffVisible fallback={<p>관리자만 사용할 수 있는 페이지입니다.</p>}>
<LoginVisible staff fallback={<p>관리자만 사용할 수 있는 페이지입니다.</p>}>
<SelectionList
names={Object.values(ADMIN_MENU)}
selectedItemName={selectedMenu}
path={adminPath}
listGridColumnClass="grid-cols-[200px_220px]"
/>
{children}
</LoginStaffVisible>
</LoginVisible>
</PageLayout>
);
}
2 changes: 1 addition & 1 deletion app/[locale]/admissions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MajorCategoryPageLayout from '@/components/layout/pageLayout/MajorCategoryPageLayout';

export default async function AdmissionsPage() {
return <MajorCategoryPageLayout subtitle="Enroll CSE" twoDimensional />;
return <MajorCategoryPageLayout subtitle="Enroll CSE" />;
}
2 changes: 1 addition & 1 deletion app/[locale]/community/faculty-recruitment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function LatestRecruitmentBanner({
}: GETFacultyRecruitmentResponse) {
return (
<a
className="font-yoon relative block h-[4.5rem] w-[25rem] cursor-pointer"
className="relative block h-[4.5rem] w-[25rem] cursor-pointer"
href={latestRecruitmentPostHref}
>
<p className="absolute left-6 top-5 text-base font-bold tracking-[.025rem]">
Expand Down
Loading

0 comments on commit e6abe3b

Please sign in to comment.