Skip to content

Commit

Permalink
feature: setup stackflow
Browse files Browse the repository at this point in the history
  • Loading branch information
toothlessdev committed Nov 23, 2024
1 parent bc24a23 commit 4248e9d
Show file tree
Hide file tree
Showing 16 changed files with 417 additions and 143 deletions.
83 changes: 74 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,82 @@
Form Control Convention
admin -> backend -> client (문항 커스텀으로 만들때)

1. data-testid
```ts
export const QuestionTypes = {
checkbox: "checkbox",
selector: "selector",
slider: "slider",
doubleSlider: "doubleSlider",
} as const;

interface FormProps {
title: string;
description: string;
questions: {
questionText: string;
questionType: keyof typeof QuestionTypes;
dataType: string;
options: { label?: string; value: any }[];
}[];
}
```
data-testid: <UI>_{option.label}

ex.
<CheckBoxWithLabelForm/>
data-testid: checkbox\_{option.label}
```js
const formProps: FormProps = {
title: "test",
description: "test",
questions: [
{
questionId
questionText: "test-question-slider",
questionType: "slider",
dataType: "number",
options: [
{ label: "label1", value: 1 },
{ label: "label2", value: 2 },
{ label: "label3", value: 3 },
],
},
{
questionText: "test-question-checkbox",
questionType: "checkbox",
dataType: "number",
options: [
{ label: "label1", value: "value1" },
{ label: "label2", value: "value2" },
{ label: "label3", value: "value3" },
],
},
{
questionText: "test-question-selector",
questionType: "selector",
dataType: "number",
options: [
{ label: "label1", value: "value1" },
{ label: "label2", value: "value2" },
{ label: "label3", value: "value3" },
],
},
{
questionText: "test-question-doubleSlider",
questionType: "doubleSlider",
dataType: "number",
options: [
{ label: "label1", value: 1 },
{ label: "label2", value: 2 },
{ label: "label3", value: 3 },
{ label: "label4", value: 4 },
{ label: "label5", value: 5 },
],
},
],
};
```

2. htmlFor, id
client (문항 응답자가 응답완료해서 백엔드로 보낼때) -> backend

```ts
interface ResponseSchema {
sruveyId:
}

```
const id = useId();
```
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
"prettier": "prettier --write .",
"test": "jest --config jest.config.ts"
"test": "jest --config jest.config.ts --ci --runInBand"
},
"dependencies": {
"@radix-ui/react-avatar": "^1.1.1",
Expand All @@ -23,6 +23,11 @@
"@radix-ui/react-toggle": "^1.1.0",
"@radix-ui/react-toggle-group": "^1.1.0",
"@reduxjs/toolkit": "^2.3.0",
"@stackflow/core": "^1.1.0",
"@stackflow/plugin-basic-ui": "^1.10.1",
"@stackflow/plugin-history-sync": "^1.7.0",
"@stackflow/plugin-renderer-basic": "^1.1.13",
"@stackflow/react": "^1.4.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"create-jest": "^29.7.0",
Expand All @@ -45,6 +50,7 @@
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
Expand Down
7 changes: 4 additions & 3 deletions src/apps/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Provider } from "react-redux";
import { createBrowserRouter, RouterProvider } from "react-router-dom";

import { router } from "./Router";
import { Stack } from "./stackflow";
import { store } from "./store/store";
import "./styles/tailwind.css";

export default function App() {
return (
<Provider store={store}>
<RouterProvider router={createBrowserRouter(router)} />
<main className="w-full max-w-[500px] mx-auto h-screen border-[1px]">
<Stack />
</main>
</Provider>
);
}
24 changes: 24 additions & 0 deletions src/apps/constants/nav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CirclePlus, HeartHandshake, MessagesSquare, User, UserSearch } from "lucide-react";

export const navBottom = [
{
path: "/match",
label: "룸메 찾기",
icon: HeartHandshake,
},
{
path: "/match/create",
label: "룸메 구하기",
icon: CirclePlus,
},
{
path: "/chat",
label: "채팅",
icon: MessagesSquare,
},
{
path: "/mypage",
label: "마이페이지",
icon: User,
},
];
48 changes: 48 additions & 0 deletions src/apps/stackflow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Fragment } from "react/jsx-runtime";

import { NavBottom } from "@/components/layouts/NavBottom";

import HomePage from "@/pages/home/HomePage";
import MatchDeatilPage from "@/pages/match/MatchDeatilPage";
import MatchListPage from "@/pages/match/MatchListPage";

import { AppScreen, AppScreenProps, basicUIPlugin } from "@stackflow/plugin-basic-ui";
import { historySyncPlugin } from "@stackflow/plugin-history-sync";
import { basicRendererPlugin } from "@stackflow/plugin-renderer-basic";
import { stackflow } from "@stackflow/react";

export const { Stack, useFlow } = stackflow({
transitionDuration: 250,
plugins: [
basicRendererPlugin(),
basicUIPlugin({
theme: "cupertino",
}),
historySyncPlugin({
routes: {
HomePage: "/",
MatchListPage: "/match",
MatchDeatilPage: "/match/detail",
},
fallbackActivity: () => "HomePage",
}),
],

activities: {
HomePage,
MatchListPage,
MatchDeatilPage,
},
initialActivity: () => "HomePage",
});

export const Screen = ({ children, ...appScreenProps }: AppScreenProps) => {
return (
<Fragment>
<AppScreen {...appScreenProps}>
<div className="screen">{children}</div>
</AppScreen>
<NavBottom />
</Fragment>
);
};
3 changes: 3 additions & 0 deletions src/apps/styles/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
@tailwind utilities;

@layer base {
.screen {
@apply relative mx-auto h-full w-full max-w-[500px];
}
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
Expand Down
20 changes: 20 additions & 0 deletions src/components/layouts/NavBottom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { navBottom } from "@/apps/constants/nav";

export const NavBottom = () => {
return (
<nav className="w-full max-w-[500px] h-[70px] fixed bottom-0 z-30 bg-white shadow-2xl shadow-black">
<ul className="flex justify-around w-full h-full gap-4 px-2 bg-white ">
{navBottom.map((item, index) => {
return (
<li className="flex items-center h-full">
<button className="flex flex-col items-center">
<item.icon size={25} />
<p className="text-sm">{item.label}</p>
</button>
</li>
);
})}
</ul>
</nav>
);
};
91 changes: 18 additions & 73 deletions src/domains/match/components/MatchListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Button } from "@/components/ui/button";

import { ParticipatingUserCardList } from "./ParticipatingUserCardList";

export interface MatchListItemProps extends React.ComponentProps<"li"> {
export interface MatchListItemProps extends React.ComponentProps<"div"> {
title: string;
dormitory: string;
description: string;
Expand All @@ -24,79 +24,24 @@ export const MatchListItem = ({
dormitory,
currentQuota,
maxQuota,
...props
}: MatchListItemProps) => {
const isParticipated = useSelector((state: RootState) => state.auth.isParticipated);

return (
<Drawer.Root>
<Drawer.Trigger className="list-none border-b-[1px] p-3 hover:cursor-pointer w-full">
<h1 className="text-lg font-bold text-left line-clamp-1">{title}</h1>
<p className="text-sm text-left text-gray-800 line-clamp-1">{description}</p>
<div className="flex justify-start gap-3 py-1 text-gray-500">
<p className="flex items-center gap-1 text-xs">
<House size={14} />
<span>{dormitory}</span>
</p>
<p className="flex items-center gap-1 text-xs">
<Users size={14} />
<span>
{currentQuota}/{maxQuota}
</span>
</p>
</div>
</Drawer.Trigger>

<Drawer.Portal>
<Drawer.Overlay className="fixed inset-0 z-40 bg-black/40" />
<Drawer.Content className="bg-gray-100 flex flex-col rounded-t-[10px] mt-24 h-fit fixed bottom-0 left-0 right-0 outline-none z-50">
<div className="p-3 bg-white rounded-t-[10px] flex-1">
<div
aria-hidden
className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-gray-300 mb-2"
/>
<div className="max-w-[600px] mx-auto px-4 py-2">
<Drawer.Title className="mb-4 text-gray-900">
<div className="text-lg font-bold">{title}</div>
<div className="flex gap-2">
<p className="flex items-center">
<Users size={14} className="mr-1" />
<span className="text-sm">
{currentQuota}/{maxQuota}
</span>
</p>
<p className="flex items-center">
<House size={14} className="mr-1" />
<span className="text-sm">{dormitory}</span>
</p>
</div>
</Drawer.Title>
<p className="mb-4 text-gray-600">{description}</p>

<div className="my-2">
<ParticipatingUserCardList
users={[
{ id: 1, index: 1, nickname: "김철수", status: "ACCEPTED" },
{ id: 2, index: 2, nickname: "홍길동", status: "PENDING" },
{ id: 3, index: 3, nickname: "이영희", status: "PENDING" },
]}
/>
</div>

<div className="flex flex-col gap-1">
<Button
variant="default"
className="w-full"
disabled={isParticipated}
>
{!isParticipated
? "채팅하기"
: "이미 참여중인 채팅방이 있습니다"}
</Button>
</div>
</div>
</div>
</Drawer.Content>
</Drawer.Portal>
</Drawer.Root>
<div className="list-none border-b-[1px] p-3 hover:cursor-pointer w-full" {...props}>
<h1 className="text-lg font-bold text-left line-clamp-1">{title}</h1>
<p className="text-sm text-left text-gray-800 line-clamp-1">{description}</p>
<div className="flex justify-start gap-3 py-1 text-gray-500">
<p className="flex items-center gap-1 text-xs">
<House size={14} />
<span>{dormitory}</span>
</p>
<p className="flex items-center gap-1 text-xs">
<Users size={14} />
<span>
{currentQuota}/{maxQuota}
</span>
</p>
</div>
</div>
);
};
2 changes: 2 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { createRoot } from "react-dom/client";

import App from "@/apps/App.tsx";

import "@stackflow/plugin-basic-ui/index.css";

createRoot(document.getElementById("root")!).render(<App />);
3 changes: 3 additions & 0 deletions src/pages/auth/SignUpPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function SignUpPage() {
return <div className=""></div>;
}
Loading

0 comments on commit 4248e9d

Please sign in to comment.