mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : BBS 게시판을 백엔드 스크랩 게시물 API로 교체 (JWT 인증, 읽음 처리)
SpecialSource Frontend (React) CD / deploy (push) Successful in 13s
SpecialSource Frontend (React) CD / deploy (push) Successful in 13s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc814a484b
commit
4b10d4d3b2
11 files changed
+197
-85
No files matched your search
@@ -2,8 +2,9 @@
|
||||
|
||||
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 { fetchFeed } from "../api";
|
||||
import { apiError, execute, initialState, LOGOUT } from "../lib/command";
|
||||
import type { ListKind, Nav, Palette } from "../types";
|
||||
import LoginForm from "./LoginForm";
|
||||
import MainMenu from "./MainMenu";
|
||||
import PostDetail from "./PostDetail";
|
||||
@@ -57,6 +58,19 @@ export default function BbsTerminal() {
|
||||
}
|
||||
}, [state.screen, state.list, state.postId]);
|
||||
|
||||
// 메인(새 글)·목록 화면에 들어오거나 "L"을 누르면 서버에서 목록을 다시 불러옴
|
||||
const feedKind: ListKind | null = state.screen === "main" ? "board" : state.screen === "list" ? state.list : null;
|
||||
useEffect(() => {
|
||||
if (!feedKind || !state.token) return;
|
||||
let stale = false; // 응답 전에 화면이 바뀌면 늦게 온 응답은 버림
|
||||
fetchFeed(state.token, feedKind)
|
||||
.then((feed) => !stale && dispatch({ feed }))
|
||||
.catch((e) => !stale && dispatch(apiError(e)));
|
||||
return () => {
|
||||
stale = true;
|
||||
};
|
||||
}, [feedKind, state.token, state.rev]);
|
||||
|
||||
useEffect(() => {
|
||||
const onPop = (e: PopStateEvent) => {
|
||||
if (e.state?.bbs) dispatch(e.state.bbs);
|
||||
@@ -83,7 +97,7 @@ export default function BbsTerminal() {
|
||||
{
|
||||
key: "F5",
|
||||
label: state.user ? "로그아웃" : "로그인",
|
||||
run: () => dispatch(state.user ? { user: null } : { screen: "login" }),
|
||||
run: () => dispatch(state.user ? LOGOUT : { screen: "login" }),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -119,19 +133,25 @@ export default function BbsTerminal() {
|
||||
<div className={styles.grid}>
|
||||
{state.screen === "main" && (
|
||||
<MainMenu
|
||||
readIds={state.readIds}
|
||||
feed={state.feed}
|
||||
loggedIn={!!state.user}
|
||||
onSelect={submitFromClick}
|
||||
onOpenPost={(id) => {
|
||||
onOpenPost={(num) => {
|
||||
// 메인에서 숫자는 메뉴 번호라서, 게시판으로 옮긴 뒤 글 번호를 실행
|
||||
dispatch({ screen: "list", list: "board" });
|
||||
dispatch(String(id));
|
||||
dispatch(String(num));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{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.screen === "login" && (
|
||||
<LoginForm onSuccess={(user, token) => dispatch({ screen: "main", user, token })} />
|
||||
)}
|
||||
{state.screen === "list" && (
|
||||
<PostList kind={state.list} feed={state.feed} loggedIn={!!state.user} onSelect={submitFromClick} />
|
||||
)}
|
||||
{state.screen === "post" && state.token && (
|
||||
<PostDetail post={state.feed?.posts.find((p) => p.id === state.postId)} token={state.token} />
|
||||
)}
|
||||
{state.error && <div className={`${styles.full} ${styles.error}`}>{state.error}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user