mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
- 목록을 30건씩 id 커서로 이어 불러옴 (MoreSentinel 재사용), 글 보기에서 돌아와도 불러온 글·스크롤 유지 - 받는 중 진행률 갱신은 첫 페이지만 다시 받아 합침 (아래쪽 불러온 글 유지) - 날짜 검색: 브라우저 기본 달력 대신 <dialog> 레이어 달력 (방향키·PageUp/Down·Enter·Esc, 오늘/지우기) - 글 수정 시 목록에도 바로 반영 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d359c35304
commit
60ab3e9ff6
9 files changed
+283
-34
No files matched your search
@@ -1,6 +1,11 @@
|
||||
import { AuthError } from "../api";
|
||||
import { MENU } from "../constants";
|
||||
import type { BbsState, Feed, MenuItem, Nav } from "../types";
|
||||
import type { BbsState, Feed, MediaPost, MenuItem, Nav } from "../types";
|
||||
|
||||
/** 자료실 페이지 도착: more = 다음 페이지 (after = 요청 당시 목록), poll = 받는 중 글 진행률 갱신용 첫 페이지 */
|
||||
export type MediaPage =
|
||||
| { mediaMore: MediaPost[]; last: boolean; after: MediaPost[] }
|
||||
| { mediaPoll: MediaPost[]; total: number; last: boolean };
|
||||
|
||||
export const initialState: BbsState = {
|
||||
screen: "main",
|
||||
@@ -12,6 +17,8 @@ export const initialState: BbsState = {
|
||||
token: null,
|
||||
feed: null,
|
||||
media: null,
|
||||
mediaTotal: 0,
|
||||
mediaLast: true,
|
||||
mediaQuery: { category: null, q: "", from: "", to: "" },
|
||||
mediaCategories: [],
|
||||
rev: 0,
|
||||
@@ -36,8 +43,21 @@ function findMenu(raw: string): MenuItem | undefined {
|
||||
/** 클릭/키보드 입력이 모두 거치는 단일 명령 처리기 (순수 함수 → useReducer reducer로 사용) */
|
||||
export function execute(
|
||||
prev: BbsState,
|
||||
input: string | Nav | Partial<BbsState> | { more: Feed; after: Feed },
|
||||
input: string | Nav | Partial<BbsState> | { more: Feed; after: Feed } | MediaPage,
|
||||
): BbsState {
|
||||
if (typeof input !== "string" && "mediaMore" in input) {
|
||||
// 요청할 때의 목록이 지금도 그대로일 때만 이어 붙임 (그 사이 탭·검색을 바꿨으면 버림)
|
||||
if (prev.media !== input.after) return prev;
|
||||
return { ...prev, media: [...prev.media, ...input.mediaMore], mediaLast: input.last };
|
||||
}
|
||||
if (typeof input !== "string" && "mediaPoll" in input) {
|
||||
// 진행률 갱신: 첫 페이지는 새로 받은 것으로, 무한 스크롤로 더 불러온 아래쪽 글은 그대로 유지
|
||||
// (받는 중인 글은 방금 등록한 최신 글이라 항상 첫 페이지 안에 있음)
|
||||
const fresh = input.mediaPoll;
|
||||
const oldest = fresh.at(-1)?.id ?? 0;
|
||||
const rest = (prev.media ?? []).filter((p) => p.id < oldest);
|
||||
return { ...prev, media: [...fresh, ...rest], mediaTotal: input.total, mediaLast: rest.length ? prev.mediaLast : input.last };
|
||||
}
|
||||
if (typeof input !== "string" && "more" in input) {
|
||||
// 무한 스크롤 다음 페이지: 요청할 때의 목록이 지금도 그대로일 때만 이어 붙임 (그 사이 탭을 바꿨거나 새로고침했으면 버림)
|
||||
const { more, after } = input;
|
||||
|
||||
Reference in new issue
Block a user