Skip to content
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

Feature/router #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
5,640 changes: 490 additions & 5,150 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
"preview": "vite preview"
},
"dependencies": {
"localforage": "^1.10.0",
"match-sorter": "^6.3.3",
"firebase": "^10.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.3",
"sort-by": "^0.0.2"
},
"devDependencies": {
"@types/react": "^18.2.37",
Expand Down
42 changes: 0 additions & 42 deletions src/App.css

This file was deleted.

35 changes: 0 additions & 35 deletions src/App.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions src/error-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useRouteError } from "react-router-dom";

export default function ErrorPage() {
const error = useRouteError();
console.error(error);

return (
<div id="error-page" style={{ padding: 40 }}>
<h1>Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
</div>
);
}
9 changes: 9 additions & 0 deletions src/interfaces/Common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type ValidationResult =
| {
isError: false;
errorMsg?: undefined;
}
| {
isError: true;
errorMsg: string;
};
35 changes: 27 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import CreateMeet from "./routes/CreateMeet/CreateMeet.tsx";
import ErrorPage from "./error-page";
import Meet from "./routes/Meet/Meet.tsx";
import { meetLoader } from "./routes/Meet/meetLoader.ts";

ReactDOM.createRoot(document.getElementById('root')!).render(
const router = createBrowserRouter([
{
path: "/",
element: <CreateMeet />,
errorElement: <ErrorPage />,
children: [
{
path: "meet/:meetId",
element: <Meet />,
loader: meetLoader,
},
],
},
]);

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
<RouterProvider router={router} />
</React.StrictMode>
);
24 changes: 24 additions & 0 deletions src/routes/CreateMeet/CreateMeet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Link } from "react-router-dom";

// TODO(세현): 모임 생성 추가
const CreateMeet = () => {
// example
const id = 2;

return (
<Link
style={{
padding: 20,
backgroundColor: "navy",
borderRadius: 20,
margin: 20,
color: "white",
}}
to={`meet/${id}`}
>
생성 후 이동
</Link>
);
};

export default CreateMeet;
13 changes: 13 additions & 0 deletions src/routes/Meet/Meet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { parseNum } from "@/utils/jsUtils";
import { useParams } from "react-router-dom";

const Meet = () => {
const { meetId: _meetId } = useParams<"meetId">();
const meetId = _meetId ? parseNum(_meetId) : null;
if (!meetId) return <></>;

// TODO: meetId 사용해서 미팅 정보 가져오고 시간 선택
return <></>;
};

export default Meet;
14 changes: 14 additions & 0 deletions src/utils/jsUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* string 으로 쓰여진 숫자를 Number로 변환하는 함수.
* 빈 스트링인 경우, 숫자형식이 아니거나 NaN인 경우 null 반환
*/

export const parseNum = (str: string) => {
if (str === "") return null;

const parsed = Number(str.replace(/[^0-9+.]/g, ""));

if (typeof parsed !== "number" || Number.isNaN(parsed)) return null;

return parsed;
};
27 changes: 27 additions & 0 deletions src/utils/validateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ValidationResult } from "@/interfaces/Common";

export const validateMeetName = (name: string): ValidationResult => {
if (name.trim().length < 3 || name.trim().length > 15) {
return {
isError: true,
errorMsg: "모임 이름은 3자 이상 15자 이내여야 합니다.",
};
}

return {
isError: false,
};
};

export const validateUserName = (name: string): ValidationResult => {
if (name.trim().length < 1 || name.trim().length > 15) {
return {
isError: true,
errorMsg: "이름은 1자 이상 15자 이내여야 합니다.",
};
}

return {
isError: false,
};
};