260702_01_ENH: 리스트 작업 도중 공용 ui를 적용하기 위한 중간 커밋

This commit is contained in:
2026-07-02 17:02:17 +09:00
parent 6944064377
commit a8ce35f5bf
111 changed files with 2833 additions and 2557 deletions

View File

@@ -1,22 +1,6 @@
"use client";
import { createLocalStorageAtom } from "@/store/jotai/utils";
import { StorageKeys } from "@/store/storage/storage-keys";
import type { LoginUser } from "@/types/auth";
export type AuthState = {
user: LoginUser | null;
seatNumber: string | null;
};
const initialAuthState: AuthState = {
user: null,
seatNumber: null,
};
/**
* AES 암호화된 localStorage 기반 로그인 상태 Atom
*/
export const authStateAtom = createLocalStorageAtom<AuthState>(
StorageKeys.AuthState,
initialAuthState,
);
export {
authStateAtom,
type AuthState,
} from "@/hooks/useAuth";

View File

@@ -1,22 +1,15 @@
import { atom } from 'jotai'
// 사용할 수 있는 DialogId를 타입으로 고정
// Dialog추가 할 때만다 추가하기
export type DialogId =
| 'userUpsertDialog'
| 'userUploadDialog'
| 'listUploadDialog'
| 'listBatchEditDialog'
| 'listFilterDialog'
| 'projectCreateDialog'
| 'resultCodeDialog'
| 'resultCodeCopyDialog'
| 'listResetDialog'
| 'listExcelUploadDialog'
| 'listHeaderManageDialog'
| 'listDownloadDialog'
| 'messageSendDialog'
| 'messageHistoryDialog'
// 현재 열려 있는 다이얼로그 ID 리스트
export const openDialogIdsAtom = atom<DialogId[]>([])
| "userUpsertDialog"
| "userUploadDialog"
| "listUploadDialog"
| "listBatchEditDialog"
| "listFilterDialog"
| "projectCreateDialog"
| "resultCodeDialog"
| "resultCodeCopyDialog"
| "listResetDialog"
| "listExcelUploadDialog"
| "listHeaderManageDialog"
| "listDownloadDialog"
| "messageSendDialog"
| "messageHistoryDialog";

View File

@@ -1,9 +1,20 @@
"use client";
import { atom } from "jotai";
import {
isLoadingAtom,
} from "@/hooks/useLoading";
export const manualLoadingAtom = atom(false);
export const queryLoadingAtom = atom(false);
export const manualLoadingAtom =
isLoadingAtom;
// 기존 LoadingOverlay가 보는 값: manual || query
export const loadingAtom = atom((get) => get(manualLoadingAtom) || get(queryLoadingAtom));
export const queryLoadingAtom =
atom(false);
export const loadingAtom =
atom((get) => {
return (
get(isLoadingAtom)
|| get(queryLoadingAtom)
);
});

View File

@@ -1,7 +1,8 @@
"use client";
import { StorageKeys } from "@/store/storage/storage-keys";
import {createSessionStorageAtom} from "@/store/jotai/utils";
import { createPersistentAtom } from "@kri/common/jotai";
import { sessionJsonStorage } from "@/store/storage/secure-storage";
import {SurveyType} from "@/types/project";
export type SelectedProject = {
@@ -22,7 +23,13 @@ export type SelectedProject = {
* - 탭/브라우저 닫으면: 삭제
*/
export const selectedProjectAtom =
createSessionStorageAtom<SelectedProject | null>(
createPersistentAtom<SelectedProject | null>(
StorageKeys.SelectedProject,
null,
);
{
storage: sessionJsonStorage,
debugLabel: "selectedProjectAtom",
},
);
export const selectedProjectHydratedAtom = selectedProjectAtom.hydratedAtom;

View File

@@ -1,108 +0,0 @@
"use client";
import { atom, type PrimitiveAtom } from "jotai";
import {
setLocalStorage,
getLocalStorage,
removeLocalStorage,
setSessionStorage,
getSessionStorage,
removeSessionStorage
} from "@/store/storage/secure-storage";
import {StorageKey} from "@/store/storage/storage-keys";
const loadInitialState = <T>(storageType: "local"|"session", key: StorageKey, initialValue: T): T => {
if (typeof window === "undefined") {
// SSR 시에는 그냥 기본값 사용
return initialValue;
}
const stored = storageType == "local" ? getLocalStorage(key) : getSessionStorage(key);
if (stored && typeof stored === "object") {
return stored as T;
}
return initialValue;
}
/**
* localStorage(AES 암호화) + Jotai 연동용 Atom 생성기
* - initialValue: SSR 시/최초 렌더 시 기본값
* - 마운트 후 localStorage에서 실제 값 읽어와서 덮어씀
*/
export const createLocalStorageAtom = <T>(
key: StorageKey,
initialValue: T,
) => {
const realInitialValue = loadInitialState("local", key, initialValue);
const baseAtom: PrimitiveAtom<T> = atom<T>(realInitialValue);
// 하이드레이션(저장소 주입)과 사용자 set 경합 방지용 플래그
let wasOverridden = false; // 마운트 이후 사용자가 값을 쓴 적이 있는지
const persistentAtom = atom(
(get) => get(baseAtom),
(get, set, update: T | ((prev: T) => T)) => {
const prev = get(baseAtom);
const next =
typeof update === "function"
? (update as (prev: T) => T)(prev)
: update;
// 메모리 상태 갱신
set(baseAtom, next);
// 사용자 쓰기 발생 표시 (하이드레이션이 도착해도 무시하도록)
wasOverridden = true;
if (next === null || (next as unknown) === undefined) {
// 암호화 localStorage 및 캐시 제거
removeLocalStorage(key);
} else {
// 동기 API로 캐시를 먼저 기록하고 암호화 저장은 백그라운드 처리
setLocalStorage(key, next);
}
},
);
return persistentAtom;
}
/**
* sessionStorage + Jotai 연동용 Atom 생성기
* - 탭 단위로 유지, 탭/브라우저 닫히면 삭제
* - 새로고침 시 유지
*/
export const createSessionStorageAtom = <T>(
key: StorageKey,
initialValue: T,
) => {
const realInitialValue = loadInitialState("session", key, initialValue);
const baseAtom: PrimitiveAtom<T> = atom<T>(realInitialValue);
const persistentAtom = atom(
(get) => get(baseAtom),
(get, set, update: T | ((prev: T) => T)) => {
const prev = get(baseAtom);
const next =
typeof update === "function"
? (update as (prev: T) => T)(prev)
: update;
set(baseAtom, next);
if (typeof window === "undefined") return;
try {
if (next === null || (next as unknown) === undefined) {
removeSessionStorage(key)
} else {
setSessionStorage(key, next);
}
} catch {
// sessionStorage 에러는 조용히 무시
}
},
);
return persistentAtom;
}