mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
This commit is contained in:
1 parent
cfda95c1ba
commit
a49df04adf
28 files changed
+734
-304
No files matched your search
@@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
.next
|
||||
out
|
||||
.git
|
||||
.idea
|
||||
*.tsbuildinfo
|
||||
study-notes.md
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# 1단계: Next.js 정적 빌드 → /app/out
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# 2단계: nginx로 정적 파일 서비스 (기존 Vue 배포와 같은 방식)
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/out /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
@@ -1,36 +1,32 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
# ss-front-react
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
PC통신 스타일 BBS UI — Next.js 16 (App Router) + React 19 + TypeScript
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
npm install
|
||||
npm run dev # http://localhost:3000
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
## 디렉토리 구조
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
```
|
||||
src/
|
||||
├─ app/ # 라우팅 전용 (page / layout)
|
||||
│ ├─ layout.tsx
|
||||
│ ├─ page.tsx
|
||||
│ ├─ globals.css # 전역 토큰·리셋
|
||||
│ └─ _components/ # 이 라우트에서만 쓰는 컴포넌트 (private folder, 라우팅 제외)
|
||||
└─ features/ # 도메인(기능) 단위 모듈
|
||||
└─ bbs/
|
||||
├─ index.ts # 외부 공개 API (여기서만 import)
|
||||
├─ types.ts
|
||||
├─ constants/ # 메뉴·팔레트 정의
|
||||
├─ mocks/ # 목업 데이터 → API 연동 시 api/ 로 교체
|
||||
├─ lib/command.ts # 명령 처리 순수 함수 (useReducer reducer)
|
||||
└─ components/ # BbsTerminal(client) + 화면별 컴포넌트 + CSS Module
|
||||
```
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
규칙
|
||||
- `app/`에는 라우팅 파일만, 로직은 `features/<도메인>/`에.
|
||||
- 다른 곳에서는 `@/features/bbs` (index.ts)로만 import.
|
||||
- 여러 feature가 공유하는 코드가 생기면 그때 `src/components`, `src/lib`, `src/hooks` 추가.
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/types/routes.d.ts";
|
||||
import "./.next/types/root-params.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
cacheComponents: true,
|
||||
partialPrefetching: true,
|
||||
output: "export", // 정적 HTML/JS로 빌드 → nginx로 서비스
|
||||
// localhost 외 주소로 개발 서버 접속 허용 (Tailscale 등). 호스트명만, 포트/스킴 없이
|
||||
allowedDevOrigins: ["100.102.165.37"],
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
@@ -1 +0,0 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
Before Width: | Height: | Size: 391 B |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
Before Width: | Height: | Size: 128 B |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
Before Width: | Height: | Size: 385 B |
@@ -0,0 +1,18 @@
|
||||
import styles from "./home.module.css";
|
||||
|
||||
export default function Intro() {
|
||||
return (
|
||||
<section className={styles.intro}>
|
||||
<p className={styles.eyebrow}>Concept preview — 클릭 · 명령어 둘 다 됩니다</p>
|
||||
<h1>PC통신 스타일 TUI — 넘버 메뉴</h1>
|
||||
<p>
|
||||
BOARD 화면을 <b>번호와 메뉴명을 직접 쳐서 이동하던 예전 PC통신 방식</b>으로 바꾼 화면입니다. 마우스
|
||||
클릭도 되지만, 클릭은 아래 명령어창에 같은 숫자를 입력하고 엔터 치는 것과 동일한 경로를 탑니다.
|
||||
</p>
|
||||
<div className={styles.hint}>
|
||||
👉 입력창에 <kbd>2</kbd> 또는 <kbd>board</kbd> → 글 <kbd>번호</kbd> 입력해서 읽기 → <kbd>L</kbd> 목록,{" "}
|
||||
<kbd>M</kbd> 메인
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import styles from "./home.module.css";
|
||||
|
||||
const NOTES = [
|
||||
["클릭 = 명령어 대리 입력.", "메뉴/게시글 줄을 클릭하면 입력창에 번호가 채워졌다가 자동으로 엔터가 눌립니다. 마우스든 키보드든 같은 명령 처리 함수(features/bbs/lib/command.ts) 하나로 들어갑니다."],
|
||||
["\"읽음\" 기능이 그대로 이어집니다.", "글을 읽으면 \"2. 자유게시판\"에서 빠지고 \"3. 내가 읽은 글\"로 넘어갑니다 — viewed_at 플래그 기능을 재현."],
|
||||
["팔레트는 실제 테마 시스템과 바로 연결 가능.", "블루/그린/앰버 버튼은 기존 테마 셀렉터와 같은 구조(data-palette 속성 + CSS 변수)입니다."],
|
||||
];
|
||||
|
||||
export default function Notes() {
|
||||
return (
|
||||
<section className={styles.notes}>
|
||||
{NOTES.map(([title, desc]) => (
|
||||
<div key={title} className={styles.note}>
|
||||
<span className={styles.mark}>▲</span>
|
||||
<p>
|
||||
<b>{title}</b> {desc}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
.intro { max-width: 740px; width: 100%; }
|
||||
.eyebrow { font-size: 11px; letter-spacing: 0.16em; color: #5a6b5a; text-transform: uppercase; margin: 0 0 10px; }
|
||||
.intro h1 { margin: 0 0 14px; font-size: clamp(19px, 3vw, 25px); color: var(--ink); font-weight: 700; text-wrap: balance; }
|
||||
.intro p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.75; color: var(--ink-3); max-width: 66ch; }
|
||||
.intro b, .note b { color: var(--ink); font-weight: 600; }
|
||||
|
||||
.hint {
|
||||
margin-top: 14px; font-size: 12px; color: var(--ink-4); border: 1px dashed var(--line);
|
||||
padding: 9px 12px; display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap;
|
||||
}
|
||||
.hint kbd {
|
||||
background: #151515; border: 1px solid #333; border-radius: 3px; padding: 1px 6px;
|
||||
font-size: 11px; color: var(--ink);
|
||||
}
|
||||
|
||||
.notes { max-width: 740px; width: 100%; display: flex; flex-direction: column; gap: 14px; }
|
||||
.note { display: flex; gap: 12px; padding: 13px 15px; border: 1px solid var(--line); background: var(--panel-soft); }
|
||||
.mark { color: #4dff4d; font-size: 12px; flex-shrink: 0; padding-top: 1px; }
|
||||
.note p { margin: 0; font-size: 12.5px; line-height: 1.7; color: var(--ink-3); }
|
||||
+24
-39
@@ -1,49 +1,34 @@
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
--void: #050505;
|
||||
--ink: #eafff0;
|
||||
--ink-2: #c9d6c9;
|
||||
--ink-3: #a9bdae;
|
||||
--ink-4: #8fae93;
|
||||
--line: #2c3a2c;
|
||||
--panel-soft: rgba(255, 255, 255, 0.03);
|
||||
--mono: ui-monospace, "D2Coding", "Cascadia Mono", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
max-width: 100vw;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
min-height: 100%;
|
||||
margin: 0;
|
||||
background: var(--void);
|
||||
color: var(--ink-2);
|
||||
font-family: var(--mono);
|
||||
}
|
||||
|
||||
button, input { font-family: inherit; }
|
||||
|
||||
.page {
|
||||
padding: clamp(20px, 4vw, 56px) clamp(14px, 4vw, 40px) 80px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: var(--foreground);
|
||||
background: var(--background);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
align-items: center;
|
||||
gap: 32px;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html {
|
||||
color-scheme: dark;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
* { transition: none !important; }
|
||||
}
|
||||
+12
-14
@@ -1,25 +1,23 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import { PALETTE_KEY } from "@/features/bbs";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
title: "SPECIALSOURCE-BBS",
|
||||
description: "PC통신 스타일 TUI — 넘버 메뉴",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: LayoutProps<"/">) {
|
||||
return (
|
||||
<html lang="en" className={`${geistSans.variable} ${geistMono.variable}`}>
|
||||
// 아래 스크립트가 hydration 전에 data-palette를 붙이므로 경고 억제
|
||||
<html lang="ko" suppressHydrationWarning>
|
||||
<head>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `try{document.documentElement.dataset.palette=localStorage.getItem(${JSON.stringify(PALETTE_KEY)})||""}catch(e){}`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
.page {
|
||||
--background: #fafafa;
|
||||
--foreground: #fff;
|
||||
|
||||
--text-primary: #000;
|
||||
--text-secondary: #666;
|
||||
|
||||
--button-primary-hover: #383838;
|
||||
--button-secondary-hover: #f2f2f2;
|
||||
--button-secondary-border: #ebebeb;
|
||||
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-family: var(--font-geist-sans);
|
||||
background-color: var(--background);
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
background-color: var(--foreground);
|
||||
padding: 120px 60px;
|
||||
}
|
||||
|
||||
.intro {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
text-align: left;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.intro h1 {
|
||||
max-width: 320px;
|
||||
font-size: 40px;
|
||||
font-weight: 600;
|
||||
line-height: 48px;
|
||||
letter-spacing: -2.4px;
|
||||
text-wrap: balance;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.intro p {
|
||||
max-width: 440px;
|
||||
font-size: 18px;
|
||||
line-height: 32px;
|
||||
text-wrap: balance;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.intro a {
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.ctas {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
max-width: 440px;
|
||||
gap: 16px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.ctas a {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 40px;
|
||||
padding: 0 16px;
|
||||
border-radius: 128px;
|
||||
border: 1px solid transparent;
|
||||
transition: 0.2s;
|
||||
cursor: pointer;
|
||||
width: fit-content;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
a.primary {
|
||||
background: var(--text-primary);
|
||||
color: var(--background);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
a.secondary {
|
||||
border-color: var(--button-secondary-border);
|
||||
}
|
||||
|
||||
/* Enable hover only on non-touch devices */
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
a.primary:hover {
|
||||
background: var(--button-primary-hover);
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
a.secondary:hover {
|
||||
background: var(--button-secondary-hover);
|
||||
border-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.main {
|
||||
padding: 48px 24px;
|
||||
}
|
||||
|
||||
.intro {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.intro h1 {
|
||||
font-size: 32px;
|
||||
line-height: 40px;
|
||||
letter-spacing: -1.92px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.logo {
|
||||
filter: invert();
|
||||
}
|
||||
|
||||
.page {
|
||||
--background: #000;
|
||||
--foreground: #000;
|
||||
|
||||
--text-primary: #ededed;
|
||||
--text-secondary: #999;
|
||||
|
||||
--button-primary-hover: #ccc;
|
||||
--button-secondary-hover: #1a1a1a;
|
||||
--button-secondary-border: #1a1a1a;
|
||||
}
|
||||
}
|
||||
|
||||
.code {
|
||||
font-family: var(--font-geist-mono);
|
||||
font-size: 0.9em;
|
||||
background: color-mix(in srgb, currentColor 8%, transparent);
|
||||
padding: 0.1em 0.4em;
|
||||
border-radius: 6px;
|
||||
}
|
||||
+8
-64
@@ -1,69 +1,13 @@
|
||||
import Image from "next/image";
|
||||
import styles from "./page.module.css";
|
||||
import { BbsTerminal } from "@/features/bbs";
|
||||
import Intro from "./_components/Intro";
|
||||
import Notes from "./_components/Notes";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<main className={styles.main}>
|
||||
<Image
|
||||
className={styles.logo}
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className={styles.intro}>
|
||||
<h1>
|
||||
To get started, edit the{" "}
|
||||
<code className={styles.code}>page.tsx</code> file.
|
||||
</h1>
|
||||
<p>
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className={styles.ctas}>
|
||||
<a
|
||||
className={styles.primary}
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className={styles.logo}
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={14}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className={styles.secondary}
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<main className="page">
|
||||
<Intro />
|
||||
<BbsTerminal />
|
||||
<Notes />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
||||
import { PALETTE_KEY, PALETTES } from "../constants";
|
||||
import { execute, initialState } from "../lib/command";
|
||||
import type { Nav, Palette } from "../types";
|
||||
import MainMenu from "./MainMenu";
|
||||
import PaletteSwitch from "./PaletteSwitch";
|
||||
import PostDetail from "./PostDetail";
|
||||
import PostList from "./PostList";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
const DEFAULT_PALETTE: Palette = "blue";
|
||||
|
||||
// localStorage를 외부 저장소로 보고 React가 구독 (다른 탭에서 바꿔도 동기화됨)
|
||||
const subscribe = (onChange: () => void) => {
|
||||
const handler = () => {
|
||||
document.documentElement.dataset.palette = readPalette(); // 색은 CSS가 <html> 속성으로 적용
|
||||
onChange(); // 버튼 활성 표시는 React가 갱신
|
||||
};
|
||||
window.addEventListener("storage", handler);
|
||||
return () => window.removeEventListener("storage", handler);
|
||||
};
|
||||
|
||||
const readPalette = (): Palette => {
|
||||
try {
|
||||
const saved = localStorage.getItem(PALETTE_KEY);
|
||||
return PALETTES.find((p) => p.key === saved)?.key ?? DEFAULT_PALETTE;
|
||||
} catch {
|
||||
return DEFAULT_PALETTE;
|
||||
}
|
||||
};
|
||||
|
||||
export default function BbsTerminal() {
|
||||
const [state, dispatch] = useReducer(execute, initialState);
|
||||
const palette = useSyncExternalStore(subscribe, readPalette, () => DEFAULT_PALETTE);
|
||||
const [input, setInput] = useState("");
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const mounted = useRef(false);
|
||||
|
||||
// 화면 이동을 브라우저 history에 기록 → 스와이프/뒤로가기 버튼/Alt+←가 그대로 앞뒤 이동이 됨
|
||||
useEffect(() => {
|
||||
const nav: Nav = { screen: state.screen, list: state.list, postId: state.postId };
|
||||
if (!mounted.current) {
|
||||
mounted.current = true;
|
||||
history.replaceState({ bbs: nav }, ""); // 새로고침 시 이전 기록 대신 현재 화면으로 시작
|
||||
} else if (JSON.stringify(history.state?.bbs) !== JSON.stringify(nav)) {
|
||||
history.pushState({ bbs: nav }, "");
|
||||
}
|
||||
}, [state.screen, state.list, state.postId]);
|
||||
|
||||
useEffect(() => {
|
||||
const onPop = (e: PopStateEvent) => {
|
||||
if (e.state?.bbs) dispatch(e.state.bbs);
|
||||
};
|
||||
addEventListener("popstate", onPop);
|
||||
return () => removeEventListener("popstate", onPop);
|
||||
}, []);
|
||||
|
||||
const changePalette = (p: Palette) => {
|
||||
try {
|
||||
localStorage.setItem(PALETTE_KEY, p);
|
||||
} catch {}
|
||||
window.dispatchEvent(new StorageEvent("storage")); // 같은 탭은 storage 이벤트가 안 오므로 직접 알림
|
||||
};
|
||||
|
||||
// 클릭 = 명령어 대리 입력: 입력창에 채운 뒤 엔터와 같은 경로로 실행
|
||||
const submitFromClick = (cmd: string) => {
|
||||
setInput(cmd);
|
||||
// 터치 기기에서 포커스하면 가상 키보드가 튀어나와 화면을 가림 → 마우스 환경에서만
|
||||
if (matchMedia("(pointer: fine)").matches) inputRef.current?.focus();
|
||||
setTimeout(() => {
|
||||
dispatch(cmd);
|
||||
setInput("");
|
||||
}, 160);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.shell}>
|
||||
<PaletteSwitch value={palette} onChange={changePalette} />
|
||||
|
||||
<div className={styles.frame}>
|
||||
<div className={styles.titlebar}>
|
||||
<span>SPECIALSOURCE-BBS v3.2</span>
|
||||
<span>{state.loggedIn ? "ONLINE: 7 · admin 접속중" : "ONLINE: 6 · 비로그인"}</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.screen}>
|
||||
{state.screen === "main" && <MainMenu readIds={state.readIds} onSelect={submitFromClick} />}
|
||||
{state.screen === "list" && <PostList kind={state.list} readIds={state.readIds} onSelect={submitFromClick} />}
|
||||
{state.screen === "post" && state.postId !== null && <PostDetail postId={state.postId} />}
|
||||
{state.error && <div className={`${styles.sub} ${styles.error}`}>{state.error}</div>}
|
||||
</div>
|
||||
|
||||
<div className={styles.cmdline}>
|
||||
<span className={styles.prompt}>></span>
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key !== "Enter" || e.nativeEvent.isComposing) return;
|
||||
dispatch(input);
|
||||
setInput("");
|
||||
}}
|
||||
placeholder="번호 또는 메뉴명을 입력하세요"
|
||||
aria-label="BBS 명령어 입력"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { MENU } from "../constants";
|
||||
import { POSTS } from "../mocks/posts";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
interface Props {
|
||||
readIds: number[];
|
||||
onSelect: (cmd: string) => void;
|
||||
}
|
||||
|
||||
export default function MainMenu({ readIds, onSelect }: Props) {
|
||||
const unread = POSTS.length - readIds.length;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.title}>SPECIALSOURCE.SYSTEM 메인 메뉴</div>
|
||||
<div className={styles.sub}>번호나 메뉴명을 입력하거나, 줄을 클릭하세요.</div>
|
||||
<hr className={styles.rule} />
|
||||
{MENU.map((m) => (
|
||||
<div key={m.num} className={styles.row} onClick={() => onSelect(String(m.num))}>
|
||||
<span className={styles.num}>{m.num}.</span>
|
||||
<span>{m.label}</span>
|
||||
<span className={styles.dim}>{m.en}</span>
|
||||
{m.key === "board" && <span className={styles.accent}>(안읽음 {unread})</span>}
|
||||
{m.key === "viewed" && <span className={styles.accent}>({readIds.length}건)</span>}
|
||||
</div>
|
||||
))}
|
||||
<hr className={styles.rule} />
|
||||
<div className={styles.footer}>
|
||||
예) <b>2</b> 또는 <b>board</b> 입력 → 자유게시판 이동
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { PALETTES } from "../constants";
|
||||
import type { Palette } from "../types";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
interface Props {
|
||||
value: Palette;
|
||||
onChange: (p: Palette) => void;
|
||||
}
|
||||
|
||||
export default function PaletteSwitch({ value, onChange }: Props) {
|
||||
return (
|
||||
<div className={styles.paletteSwitch}>
|
||||
{PALETTES.map((p) => (
|
||||
<button
|
||||
key={p.key}
|
||||
type="button"
|
||||
className={`${styles.paletteBtn} ${value === p.key ? styles.active : ""}`}
|
||||
aria-pressed={value === p.key}
|
||||
onClick={() => onChange(p.key)}
|
||||
>
|
||||
{p.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { POSTS } from "../mocks/posts";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
export default function PostDetail({ postId }: { postId: number }) {
|
||||
const post = POSTS.find((p) => p.id === postId);
|
||||
if (!post) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.title}>{post.title}</div>
|
||||
<div className={styles.sub}>
|
||||
글쓴이 {post.author} · 조회 {post.views} · {post.date}
|
||||
</div>
|
||||
<hr className={styles.rule} />
|
||||
<div className={styles.body}>{post.body}</div>
|
||||
<hr className={styles.rule} />
|
||||
<div className={styles.footer}>
|
||||
<b>L</b>=목록으로 · <b>M</b>=메인메뉴
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { POSTS } from "../mocks/posts";
|
||||
import type { ListKind } from "../types";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
interface Props {
|
||||
kind: ListKind;
|
||||
readIds: number[];
|
||||
onSelect: (cmd: string) => void;
|
||||
}
|
||||
|
||||
export default function PostList({ kind, readIds, onSelect }: Props) {
|
||||
const viewed = kind === "viewed";
|
||||
const posts = POSTS.filter((p) => readIds.includes(p.id) === viewed);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.title}>
|
||||
[{viewed ? 3 : 2}] {viewed ? "내가 읽은 글" : "자유게시판"}
|
||||
</div>
|
||||
<div className={styles.sub}>글 번호를 입력하면 읽습니다 · 총 {posts.length}건</div>
|
||||
<hr className={styles.rule} />
|
||||
{posts.length === 0 && <div className={styles.sub}>표시할 글이 없습니다.</div>}
|
||||
{posts.map((p) => (
|
||||
<div key={p.id} className={`${styles.row} ${styles.postRow}`} onClick={() => onSelect(String(p.id))}>
|
||||
<span className={styles.postIdx}>{p.id}</span>
|
||||
<span className={`${styles.postTitle} ${viewed ? styles.dim : ""}`}>{p.title}</span>
|
||||
<span className={styles.postMeta}>
|
||||
{p.author} · 조회 {p.views} · {p.date}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
<hr className={styles.rule} />
|
||||
<div className={styles.footer}>
|
||||
<b>번호</b>=글읽기 · <b>M</b>=메인 · <b>L</b>=이 목록 새로고침
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/* --- BBS 팔레트 (시대별 PC통신 느낌) --- */
|
||||
/* <html data-palette>는 layout.tsx 인라인 스크립트가 첫 페인트 전에 설정 → 깜빡임 없음 */
|
||||
.frame, :global(html[data-palette="blue"]) .frame {
|
||||
--bbs-bg: #000033; --bbs-fg: #d9d9f5; --bbs-accent: #55ffff;
|
||||
--bbs-highlight: #ffff55; --bbs-dim: #7d7dc4; --bbs-border: #ffffff; --bbs-glow: rgba(85, 255, 255, 0.35);
|
||||
}
|
||||
:global(html[data-palette="green"]) .frame {
|
||||
--bbs-bg: #000d00; --bbs-fg: #cdf7cd; --bbs-accent: #4dff4d;
|
||||
--bbs-highlight: #ffff55; --bbs-dim: #3f8f3f; --bbs-border: #4dff4d; --bbs-glow: rgba(77, 255, 77, 0.35);
|
||||
}
|
||||
:global(html[data-palette="amber"]) .frame {
|
||||
--bbs-bg: #190f00; --bbs-fg: #ffe3ba; --bbs-accent: #ffb347;
|
||||
--bbs-highlight: #ffffff; --bbs-dim: #a06a2c; --bbs-border: #ffb347; --bbs-glow: rgba(255, 179, 71, 0.35);
|
||||
}
|
||||
|
||||
.shell { width: 100%; max-width: 760px; display: flex; flex-direction: column; align-items: center; }
|
||||
|
||||
.paletteSwitch { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
|
||||
.paletteBtn {
|
||||
background: none; border: 1px solid #333; color: #8fae93; font-size: 11px;
|
||||
padding: 6px 12px; cursor: pointer; letter-spacing: 0.02em;
|
||||
}
|
||||
.paletteBtn:hover, .active { border-color: #eafff0; color: #eafff0; }
|
||||
|
||||
.frame {
|
||||
width: 100%; background: var(--bbs-bg); color: var(--bbs-fg);
|
||||
border: 3px double var(--bbs-border);
|
||||
box-shadow: 0 0 24px var(--bbs-glow), 0 20px 60px rgba(0, 0, 0, 0.6);
|
||||
position: relative; overflow: hidden;
|
||||
}
|
||||
/* CRT 스캔라인 */
|
||||
.frame::after {
|
||||
content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
|
||||
background: linear-gradient(rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.12) 50%);
|
||||
background-size: 100% 3px; mix-blend-mode: overlay; opacity: 0.5;
|
||||
}
|
||||
.frame :focus-visible { outline: 2px solid var(--bbs-accent); outline-offset: 2px; }
|
||||
|
||||
.titlebar {
|
||||
display: flex; justify-content: space-between; align-items: center; gap: 8px;
|
||||
padding: 8px 16px; border-bottom: 1px solid var(--bbs-border);
|
||||
font-size: 12.5px; font-weight: 700; color: var(--bbs-accent); letter-spacing: 0.03em;
|
||||
}
|
||||
.screen { padding: 18px 20px; min-height: 360px; font-size: 13.5px; line-height: 1.9; }
|
||||
|
||||
.row { display: flex; gap: 10px; cursor: pointer; padding: 1px 4px; margin: 0 -4px; }
|
||||
.row:hover { background: rgba(255, 255, 255, 0.08); }
|
||||
.num { color: var(--bbs-highlight); font-weight: 700; width: 1.4em; flex-shrink: 0; text-align: right; }
|
||||
.dim { color: var(--bbs-dim); }
|
||||
.accent { color: var(--bbs-accent); }
|
||||
|
||||
.title { color: var(--bbs-accent); font-weight: 700; margin-bottom: 4px; }
|
||||
.sub { color: var(--bbs-dim); font-size: 12px; margin-bottom: 10px; }
|
||||
.error { color: #ff6b6b; }
|
||||
.rule { border: none; border-top: 1px solid var(--bbs-dim); opacity: 0.5; margin: 8px 0 12px; }
|
||||
|
||||
.postRow { font-size: 13px; }
|
||||
.postIdx { color: var(--bbs-highlight); width: 1.6em; flex-shrink: 0; text-align: right; }
|
||||
.postTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.postMeta { color: var(--bbs-dim); font-size: 11.5px; flex-shrink: 0; white-space: nowrap; }
|
||||
|
||||
.body { white-space: pre-wrap; margin-bottom: 14px; }
|
||||
|
||||
.footer { color: var(--bbs-dim); font-size: 11.5px; }
|
||||
.footer b { color: var(--bbs-highlight); }
|
||||
|
||||
.cmdline {
|
||||
display: flex; align-items: center; gap: 8px; padding: 10px 16px;
|
||||
border-top: 1px solid var(--bbs-border); background: rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.prompt { color: var(--bbs-highlight); font-size: 13px; font-weight: 700; flex-shrink: 0; }
|
||||
.cmdline input {
|
||||
flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--bbs-fg);
|
||||
font-size: 13.5px; caret-color: var(--bbs-highlight);
|
||||
}
|
||||
.cmdline input::placeholder { color: var(--bbs-dim); }
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.postMeta { display: none; }
|
||||
.screen { padding: 14px; }
|
||||
.titlebar { padding: 8px 12px; font-size: 11.5px; }
|
||||
}
|
||||
/* iOS는 16px 미만 input에 포커스하면 화면을 확대함 */
|
||||
@media (pointer: coarse) {
|
||||
.cmdline input { font-size: 16px; }
|
||||
.row { padding: 4px; } /* 손가락 터치 영역 확보 */
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { MenuItem, Palette } from "../types";
|
||||
|
||||
export const MENU: MenuItem[] = [
|
||||
{ num: 1, key: "notice", label: "공지사항", en: "NOTICE", aliases: ["공지", "notice"] },
|
||||
{ num: 2, key: "board", label: "자유게시판", en: "BOARD", aliases: ["게시판", "자유게시판", "board"] },
|
||||
{ num: 3, key: "viewed", label: "내가 읽은 글", en: "VIEWED", aliases: ["읽음", "내가읽은글", "viewed"] },
|
||||
{ num: 4, key: "youtube", label: "유튜브 자료실", en: "YOUTUBE", aliases: ["유튜브", "youtube"] },
|
||||
{ num: 5, key: "about", label: "회사 소개", en: "ABOUT", aliases: ["소개", "회사소개", "about"] },
|
||||
{ num: 6, key: "contact", label: "문의하기", en: "CONTACT", aliases: ["문의", "contact"] },
|
||||
{ num: 7, key: "login", label: "로그아웃", en: "LOGOUT", aliases: ["로그인", "로그아웃", "login", "logout"] },
|
||||
];
|
||||
|
||||
export const PALETTE_KEY = "bbs-palette";
|
||||
|
||||
export const PALETTES: { key: Palette; label: string }[] = [
|
||||
{ key: "blue", label: "블루" },
|
||||
{ key: "green", label: "그린" },
|
||||
{ key: "amber", label: "앰버" },
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
export { PALETTE_KEY } from "./constants";
|
||||
export { default as BbsTerminal } from "./components/BbsTerminal";
|
||||
@@ -0,0 +1,52 @@
|
||||
import { MENU } from "../constants";
|
||||
import { POSTS } from "../mocks/posts";
|
||||
import type { BbsState, MenuItem, Nav } from "../types";
|
||||
|
||||
export const initialState: BbsState = {
|
||||
screen: "main",
|
||||
list: "board",
|
||||
postId: null,
|
||||
readIds: [],
|
||||
loggedIn: true,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function findMenu(raw: string): MenuItem | undefined {
|
||||
const n = Number(raw);
|
||||
if (!Number.isNaN(n)) return MENU.find((m) => m.num === n);
|
||||
const lower = raw.toLowerCase();
|
||||
return MENU.find((m) => m.aliases.includes(lower));
|
||||
}
|
||||
|
||||
/** 클릭/키보드 입력이 모두 거치는 단일 명령 처리기 (순수 함수 → useReducer reducer로 사용) */
|
||||
export function execute(prev: BbsState, input: string | Nav): BbsState {
|
||||
if (typeof input !== "string") return { ...prev, ...input, error: null }; // 뒤로/앞으로 이동 복원
|
||||
const raw = input.trim();
|
||||
if (!raw) return prev;
|
||||
const state = { ...prev, error: null };
|
||||
const cmd = raw.toLowerCase();
|
||||
const isMain = cmd === "m" || cmd === "메인";
|
||||
const isList = cmd === "l" || cmd === "목록";
|
||||
|
||||
if (state.screen === "main") {
|
||||
const m = findMenu(raw);
|
||||
if (!m) return { ...state, error: `※ 알 수 없는 메뉴입니다: "${raw}"` };
|
||||
if (m.key === "board" || m.key === "viewed") return { ...state, screen: "list", list: m.key };
|
||||
if (m.key === "login") return { ...state, loggedIn: !state.loggedIn };
|
||||
return { ...state, error: `※ "${m.label}"는 이 목업에서는 미리보기 대상이 아닙니다 (BOARD/VIEWED만 시연).` };
|
||||
}
|
||||
|
||||
if (isMain) return { ...state, screen: "main" };
|
||||
|
||||
if (state.screen === "list") {
|
||||
if (isList) return state;
|
||||
const post = POSTS.find((p) => p.id === Number(raw));
|
||||
if (!post) return { ...state, error: `※ 목록에 없는 번호입니다: "${raw}"` };
|
||||
const readIds = state.readIds.includes(post.id) ? state.readIds : [...state.readIds, post.id];
|
||||
return { ...state, screen: "post", postId: post.id, readIds };
|
||||
}
|
||||
|
||||
// screen === "post"
|
||||
if (isList) return { ...state, screen: "list" };
|
||||
return { ...state, error: '※ "L"(목록) 또는 "M"(메인)만 입력해 보세요.' };
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
export type MenuKey = "notice" | "board" | "viewed" | "youtube" | "about" | "contact" | "login";
|
||||
|
||||
export interface MenuItem {
|
||||
num: number;
|
||||
key: MenuKey;
|
||||
label: string;
|
||||
en: string;
|
||||
aliases: string[];
|
||||
}
|
||||
|
||||
export interface Post {
|
||||
id: number;
|
||||
title: string;
|
||||
author: string;
|
||||
date: string;
|
||||
views: number;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export type Palette = "blue" | "green" | "amber";
|
||||
export type Screen = "main" | "list" | "post";
|
||||
export type ListKind = "board" | "viewed";
|
||||
|
||||
export interface BbsState {
|
||||
screen: Screen;
|
||||
list: ListKind;
|
||||
postId: number | null;
|
||||
readIds: number[];
|
||||
loggedIn: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
/** 브라우저 history에 저장하는 화면 위치 (뒤로/앞으로 제스처로 복원) */
|
||||
export type Nav = Pick<BbsState, "screen" | "list" | "postId">;
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
# React / Next.js 공부 노트
|
||||
|
||||
---
|
||||
|
||||
## 1. 디렉토리 네이밍 규칙 (src/app, src/features)
|
||||
|
||||
**질문:** src/app, features 디렉토리 네이밍룰이 실무에서도 이래?
|
||||
|
||||
**요약:** 대체로 실무 표준에 가깝다. 핵심은 "어떤 규칙이든 팀 안에서 일관되게".
|
||||
|
||||
### 실무에서 흔한 패턴
|
||||
- `src/app/` : Next.js App Router 폴더. **폴더 구조 = URL 경로**.
|
||||
- `page.tsx` → 그 경로의 화면, `layout.tsx` → 공통 껍데기
|
||||
- `_폴더명` (예: `_components`) : **언더스코어로 시작하면 라우팅에서 제외** (Next.js 공식 규칙).
|
||||
페이지 전용 컴포넌트를 근처에 두고 싶을 때 사용.
|
||||
- `src/features/기능명/` : **기능 단위 폴더 구조** (bulletproof-react 스타일).
|
||||
- `components/` 화면 조각, `lib/` 로직, `constants` 상수, `types.ts` 타입
|
||||
- `index.ts` = 이 기능의 "공개 창구". 밖에서는 `@/features/bbs` 로만 import.
|
||||
- 파일명 규칙
|
||||
- 컴포넌트: PascalCase (`PostList.tsx`)
|
||||
- 그 외: camelCase / 소문자 (`command.ts`)
|
||||
- 모두 kebab-case(`post-list.tsx`)로 쓰는 팀도 많음 → 정답은 없고 통일이 중요.
|
||||
|
||||
### 개선 포인트
|
||||
1. 파일 하나뿐이면 폴더 대신 파일로: `constants/index.ts` → `constants.ts` (`types.ts`와 맞춤). 커지면 그때 폴더로.
|
||||
2. CSS Module은 보통 컴포넌트당 하나: `PostList.module.css`. 하나를 여럿이 공유하면 커질수록 추적이 어려움.
|
||||
3. `mocks/`(가짜 데이터)는 feature 안에 있어도 OK. MSW 같은 도구를 쓰면 보통 최상위로 이동.
|
||||
|
||||
### 키워드
|
||||
App Router, Private Folder(`_`), Feature-based 구조, Barrel 파일(`index.ts`), CSS Modules
|
||||
|
||||
---
|
||||
|
||||
## 2. localStorage에 값 기억하기 (useSyncExternalStore)
|
||||
|
||||
**질문:** 팔레트 선택을 기억하게 해줘. localStorage에 넣을 거야?
|
||||
|
||||
**요약:** 네. 단, Next.js에서는 서버에 localStorage가 없으므로 "서버는 기본값 → 브라우저에서 저장값"으로 읽어야 한다.
|
||||
React 19에서는 `useSyncExternalStore`가 정석.
|
||||
|
||||
### 핵심 내용
|
||||
- **localStorage**: 브라우저에 문자열을 영구 저장 (`setItem` / `getItem`). 새로고침해도 유지, 서버에서는 없음.
|
||||
- **Hydration**: 서버가 만든 HTML과 브라우저 첫 렌더 결과가 같아야 함. 처음부터 localStorage 값으로 그리면 불일치 에러.
|
||||
- 흔한 방법 `useEffect(() => setState(저장값), [])` → React 19 ESLint가 막음 (`set-state-in-effect`, 렌더가 두 번 일어남).
|
||||
- **useSyncExternalStore(subscribe, 브라우저값, 서버값)**
|
||||
- `subscribe`: 값이 바뀔 때 React에 알려줄 방법 (여기선 `storage` 이벤트)
|
||||
- 두 번째 인자: 브라우저에서 현재 값 읽기
|
||||
- 세 번째 인자: 서버 렌더용 기본값 → hydration 문제 자동 해결
|
||||
- `storage` 이벤트는 **다른 탭**에서만 발생 → 같은 탭에선 직접 `dispatchEvent`로 알림. 덤으로 탭 간 동기화.
|
||||
- localStorage 값은 사용자가 조작 가능 → 읽을 때 허용된 값인지 검사 (`PALETTES.find`)
|
||||
- `try/catch`: 시크릿 모드 등에서 localStorage 접근이 실패할 수 있음.
|
||||
|
||||
### 키워드
|
||||
localStorage, Hydration, useSyncExternalStore, storage 이벤트, You Might Not Need an Effect
|
||||
|
||||
---
|
||||
|
||||
## 3. IP로 접속하면 버튼이 안 눌리는 이유 (allowedDevOrigins)
|
||||
|
||||
**증상:** `http://100.102.165.37:3000`으로 접속 → 화면은 보이는데 클릭 반응 없음.
|
||||
콘솔: `WebSocket connection to 'ws://.../_next/hmr' failed`
|
||||
|
||||
**요약:** Next.js 개발 서버는 보안상 `localhost`가 아닌 주소에서 오는 개발용 요청(JS, HMR)을 막는다.
|
||||
→ `next.config.ts`의 `allowedDevOrigins`에 그 주소를 등록하면 해결.
|
||||
|
||||
### 핵심 내용
|
||||
- **SSR vs Hydration**: 서버가 HTML을 먼저 보내서 화면은 보임. 클릭 같은 동작은 브라우저에서 JS가 붙어야(hydration) 작동.
|
||||
JS가 막히면 "보이지만 죽은 화면"이 된다.
|
||||
- **HMR**(Hot Module Replacement): 코드 저장 시 새로고침 없이 반영하는 개발용 기능. WebSocket(`/_next/hmr`)으로 연결.
|
||||
- 설정:
|
||||
```ts
|
||||
allowedDevOrigins: ["100.102.165.37"], // 호스트명만, http:// 와 포트 제외
|
||||
```
|
||||
- `next.config.ts`를 바꾸면 **개발 서버 재시작** 필요.
|
||||
- 개발 모드 전용 설정. 배포(`next build` / `next start`)와는 무관.
|
||||
|
||||
### 키워드
|
||||
allowedDevOrigins, Hydration, HMR, WebSocket, Cross-origin
|
||||
|
||||
---
|
||||
|
||||
## 4. 새로고침 시 색 깜빡임 없애기 (FOUC 방지)
|
||||
|
||||
**문제:** 저장된 색이 앰버여도 새로고침하면 잠깐 블루가 보였다가 바뀜.
|
||||
|
||||
**요약:** 서버는 localStorage를 모르니 기본색으로 HTML을 보내고, React가 나중에 바꾸기 때문.
|
||||
→ `<head>`의 짧은 인라인 스크립트가 **화면을 그리기 전에** `<html data-palette="amber">`를 붙이고, 색은 CSS가 담당.
|
||||
|
||||
### 핵심 내용
|
||||
- **FOUC** (Flash of Unstyled/Incorrect Content): 잘못된 스타일이 잠깐 보이는 현상. 다크모드 깜빡임과 같은 문제.
|
||||
- 브라우저는 `<head>`의 `<script>`를 만나면 **실행이 끝날 때까지 화면을 그리지 않음** → 첫 화면부터 올바른 색.
|
||||
- 역할 분리
|
||||
- 색 적용: CSS (`html[data-palette="green"] .frame { ... }`)
|
||||
- 버튼 활성 표시: React (`useSyncExternalStore`)
|
||||
- CSS Module에서 전역 선택자 쓰기: `:global(html[data-palette="green"]) .frame`
|
||||
- `<html suppressHydrationWarning>`: 스크립트가 React보다 먼저 속성을 바꾸므로 "서버 HTML과 다르다" 경고를 끔 (그 태그 한 단계만 적용).
|
||||
- 대안: 쿠키에 저장해 서버가 처음부터 맞는 색으로 렌더 → 페이지가 매 요청마다 동적 렌더링됨. 이 경우엔 스크립트 방식이 더 가벼움.
|
||||
|
||||
### 키워드
|
||||
FOUC, 인라인 스크립트, render-blocking script, suppressHydrationWarning, :global, next-themes(같은 원리의 라이브러리)
|
||||
|
||||
---
|
||||
|
||||
## 5. 반응형 + 제스처로 앞뒤 이동 (History API)
|
||||
|
||||
**질문:** 모바일/PC 반응형으로 하고, 키보드 입력과 별개로 제스처로 앞뒤 이동되게 하고 싶어.
|
||||
|
||||
**요약:** 제스처를 직접 구현하지 말고 **브라우저 history에 화면 이동을 기록**하면 된다.
|
||||
그러면 각 기기의 기본 동작(스와이프, 뒤로가기 버튼)이 그대로 앞뒤 이동이 된다.
|
||||
|
||||
### 핵심 내용
|
||||
- `history.pushState(state, "")` : 주소는 그대로, 방문 기록만 한 칸 추가.
|
||||
- `popstate` 이벤트 : 뒤로/앞으로 갈 때 발생 → `e.state`에서 화면 위치를 꺼내 복원.
|
||||
- 이걸로 공짜로 되는 것: iOS 가장자리 스와이프, Android 뒤로 제스처, 맥 트랙패드 스와이프, 마우스 앞/뒤 버튼, Alt+←/→
|
||||
- 기록하는 것은 **화면 위치만** (`screen`, `list`, `postId`). "읽은 글" 목록은 넣지 않음 → 뒤로 가도 읽음 표시는 유지.
|
||||
- 같은 화면이면 push 안 함 (중복 기록 방지). 첫 렌더는 `replaceState` (새로고침 시 옛 기록과 꼬이지 않게).
|
||||
- Next.js는 `pushState`를 감싸서 자기 내부 상태(`__NA`)를 자동으로 함께 저장 → 직접 써도 라우터와 충돌 없음.
|
||||
|
||||
### 모바일 대응 (CSS)
|
||||
- `@media (max-width: 560px)` : 화면 **너비** 기준 (작은 화면 레이아웃)
|
||||
- `@media (pointer: coarse)` : **입력 장치** 기준 (손가락 터치). 너비와 별개로 구분하는 게 정확.
|
||||
- iOS는 글자 크기 16px 미만 input에 포커스하면 자동 확대 → 터치 기기에선 16px.
|
||||
- 터치 기기에서 `input.focus()` 하면 가상 키보드가 화면을 가림 → `matchMedia("(pointer: fine)")`(마우스)일 때만 포커스.
|
||||
|
||||
### 키워드
|
||||
History API, pushState, popstate, media query, pointer: coarse/fine, matchMedia
|
||||
|
||||
---
|
||||
|
||||
## 6. Next.js 정적 배포 (Gitea Actions + Docker + nginx)
|
||||
|
||||
**질문:** Gitea로 배포할 deploy.yml 만들어줘 (기존 Vue는 nginx 컨테이너로 서비스 중).
|
||||
|
||||
**요약:** 서버 기능을 안 쓰는 앱은 `output: "export"`로 **정적 HTML/JS**로 빌드 → Vue처럼 nginx로 서비스.
|
||||
|
||||
### 핵심 내용
|
||||
- `next.config.ts`에 `output: "export"` → `npm run build` 시 `out/` 폴더 생성 (Vue의 `dist/`와 같은 역할).
|
||||
- 정적 export에서 못 쓰는 것: 쿠키, Server Actions, API(Route Handler), redirects/rewrites, ISR 등 **서버가 필요한 기능**.
|
||||
나중에 필요해지면 `output: "standalone"` + Node 서버 컨테이너로 전환.
|
||||
- `cacheComponents`, `partialPrefetching`(PPR)은 서버 렌더링용 기능 → export 모드와 함께 쓰면 빌드 에러.
|
||||
- **멀티 스테이지 Dockerfile**: 1단계 node로 빌드 → 2단계 nginx에 결과물만 복사. 최종 이미지에 node_modules 없음 → 가볍다.
|
||||
- `.dockerignore`: 빌드에 필요 없는 파일(node_modules 등)을 Docker로 안 보냄 → 빌드 빠름.
|
||||
- Gitea Actions 워크플로 위치: `.gitea/workflows/*.yml` (GitHub의 `.github/workflows`와 같은 문법).
|
||||
- `--restart unless-stopped`: NAS 재부팅 시 컨테이너 자동 시작.
|
||||
- `docker image prune -f`: 배포마다 생기는 이름 없는 옛 이미지 정리 (NAS 디스크 보호).
|
||||
|
||||
### 키워드
|
||||
Static Export, output: "export", Multi-stage build, nginx, Gitea Actions, docker run -p / -v
|
||||
Reference in new issue
Block a user