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,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">;
|
||||
Reference in new issue
Block a user