mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : BBS 화면을 PC통신(DOS 텍스트 모드) 스타일 전체화면으로 개편
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
- 상태줄 / 이중선 창 / 명령줄 / 기능키(F1~F5) 레이아웃, PC·모바일 반응형 - 메인에 새 글 창 추가, 게시판을 번호·글쓴이·날짜·조회·제목 표로 변경 - 팔레트 버튼을 F4 색상 순환으로 대체 (PaletteSwitch 삭제) - 나눔고딕코딩 글꼴 적용 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
97321b8bef
commit
d0aced1026
10 files changed
+290
-186
No files matched your search
@@ -6,7 +6,6 @@ import { execute, initialState } from "../lib/command";
|
||||
import type { Nav, Palette } from "../types";
|
||||
import LoginForm from "./LoginForm";
|
||||
import MainMenu from "./MainMenu";
|
||||
import PaletteSwitch from "./PaletteSwitch";
|
||||
import PostDetail from "./PostDetail";
|
||||
import PostList from "./PostList";
|
||||
import styles from "./bbs.module.css";
|
||||
@@ -17,12 +16,19 @@ const DEFAULT_PALETTE: Palette = "blue";
|
||||
const subscribe = (onChange: () => void) => {
|
||||
const handler = () => {
|
||||
document.documentElement.dataset.palette = readPalette(); // 색은 CSS가 <html> 속성으로 적용
|
||||
onChange(); // 버튼 활성 표시는 React가 갱신
|
||||
onChange(); // F4가 다음 색을 고를 수 있게 React state도 갱신
|
||||
};
|
||||
window.addEventListener("storage", handler);
|
||||
return () => window.removeEventListener("storage", handler);
|
||||
};
|
||||
|
||||
// 상태줄 시계: 1초마다 다시 읽음 (서버 렌더링 땐 자리표시 문자열)
|
||||
const subscribeClock = (onChange: () => void) => {
|
||||
const t = setInterval(onChange, 1000);
|
||||
return () => clearInterval(t);
|
||||
};
|
||||
const readClock = () => new Date().toTimeString().slice(0, 8);
|
||||
|
||||
const readPalette = (): Palette => {
|
||||
try {
|
||||
const saved = localStorage.getItem(PALETTE_KEY);
|
||||
@@ -35,6 +41,7 @@ const readPalette = (): Palette => {
|
||||
export default function BbsTerminal() {
|
||||
const [state, dispatch] = useReducer(execute, initialState);
|
||||
const palette = useSyncExternalStore(subscribe, readPalette, () => DEFAULT_PALETTE);
|
||||
const clock = useSyncExternalStore(subscribeClock, readClock, () => "--:--:--");
|
||||
const [input, setInput] = useState("");
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const mounted = useRef(false);
|
||||
@@ -58,13 +65,28 @@ export default function BbsTerminal() {
|
||||
return () => removeEventListener("popstate", onPop);
|
||||
}, []);
|
||||
|
||||
const changePalette = (p: Palette) => {
|
||||
// F4: 블루 → 그린 → 앰버 순서로 돌아가며 변경
|
||||
const cyclePalette = () => {
|
||||
const next = PALETTES[(PALETTES.findIndex((p) => p.key === palette) + 1) % PALETTES.length].key;
|
||||
try {
|
||||
localStorage.setItem(PALETTE_KEY, p);
|
||||
localStorage.setItem(PALETTE_KEY, next);
|
||||
} catch {}
|
||||
window.dispatchEvent(new StorageEvent("storage")); // 같은 탭은 storage 이벤트가 안 오므로 직접 알림
|
||||
};
|
||||
|
||||
// 하단 기능키 (PC는 키보드 F1~F5도 동작)
|
||||
const fkeys = [
|
||||
{ key: "F1", label: "메인", run: () => dispatch({ screen: "main" }) },
|
||||
{ key: "F2", label: "게시판", run: () => dispatch({ screen: "list", list: "board" }) },
|
||||
{ key: "F3", label: "이전", run: () => history.back(), disabled: state.screen === "main" },
|
||||
{ key: "F4", label: "색상", run: cyclePalette },
|
||||
{
|
||||
key: "F5",
|
||||
label: state.user ? "로그아웃" : "로그인",
|
||||
run: () => dispatch(state.user ? { user: null } : { screen: "login" }),
|
||||
},
|
||||
];
|
||||
|
||||
// 클릭 = 명령어 대리 입력: 입력창에 채운 뒤 엔터와 같은 경로로 실행
|
||||
const submitFromClick = (cmd: string) => {
|
||||
setInput(cmd);
|
||||
@@ -77,44 +99,72 @@ export default function BbsTerminal() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.shell}>
|
||||
<PaletteSwitch value={palette} onChange={changePalette} />
|
||||
<div
|
||||
className={styles.frame}
|
||||
onKeyDown={(e) => {
|
||||
const f = fkeys.find((k) => k.key === e.key);
|
||||
if (!f || f.disabled) return;
|
||||
e.preventDefault(); // F5 새로고침 등 브라우저 기본 동작 막기
|
||||
f.run();
|
||||
}}
|
||||
>
|
||||
<div className={styles.status}>
|
||||
<span>SPECIALSOURCE-BBS</span>
|
||||
{/*<span className={styles.opt}></span>*/}
|
||||
<span>{state.user ? `${state.user} 접속중` : "손님 (비로그인)"}</span>
|
||||
<span className={styles.opt}>{clock}</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.frame}>
|
||||
<div className={styles.titlebar}>
|
||||
<span>SPECIALSOURCE-BBS</span>
|
||||
<span>{state.user ? `ONLINE: 7 · ${state.user} 접속중` : "ONLINE: 6 · 비로그인"}</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.screen}>
|
||||
<div className={styles.screen}>
|
||||
<div className={styles.grid}>
|
||||
{state.screen === "main" && (
|
||||
<MainMenu readIds={state.readIds} loggedIn={!!state.user} onSelect={submitFromClick} />
|
||||
<MainMenu
|
||||
readIds={state.readIds}
|
||||
loggedIn={!!state.user}
|
||||
onSelect={submitFromClick}
|
||||
onOpenPost={(id) => {
|
||||
// 메인에서 숫자는 메뉴 번호라서, 게시판으로 옮긴 뒤 글 번호를 실행
|
||||
dispatch({ screen: "list", list: "board" });
|
||||
dispatch(String(id));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{state.screen === "login" && <LoginForm onSuccess={(user) => dispatch({ screen: "main", user })} />}
|
||||
{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
|
||||
/>
|
||||
{state.error && <div className={`${styles.full} ${styles.error}`}>{state.error}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.cmdline}>
|
||||
<label htmlFor="bbs-cmd" className={styles.prompt}>
|
||||
선택 >
|
||||
</label>
|
||||
<input
|
||||
id="bbs-cmd"
|
||||
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="번호 또는 메뉴명 (M 메인 · L 목록)"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<nav className={styles.fkeys} aria-label="기능키">
|
||||
{fkeys.map((f) => (
|
||||
<button key={f.key} type="button" onClick={f.run} disabled={f.disabled}>
|
||||
<span>{f.key}</span>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user