일정 관리 상태 복원 로직 - fromScheduleForm 플래그 방식으로 변경
- 일정 추가/수정 버튼 클릭 시 플래그 설정 - 돌아올 때 플래그가 있으면 상태 복원 후 플래그 제거 - 플래그가 없으면 상태 초기화 (새로고침/직접 진입)
This commit is contained in:
parent
31f15fe20b
commit
2c766e8da6
1 changed files with 14 additions and 7 deletions
|
|
@ -21,16 +21,17 @@ function AdminSchedule() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// sessionStorage에서 저장된 상태 복원
|
// sessionStorage에서 저장된 상태 복원
|
||||||
// 뒤로가기로 돌아올 때만 복원, 새로고침이나 직접 진입 시에는 초기화
|
// 일정 폼에서 돌아올 때만 복원 (fromScheduleForm 플래그 확인)
|
||||||
const getStoredState = () => {
|
const getStoredState = () => {
|
||||||
try {
|
try {
|
||||||
const navType = performance.getEntriesByType('navigation')[0]?.type;
|
const fromForm = sessionStorage.getItem('fromScheduleForm');
|
||||||
// 뒤로가기/앞으로가기일 때만 상태 복원
|
if (fromForm) {
|
||||||
if (navType === 'back_forward') {
|
// 플래그 제거 후 상태 복원
|
||||||
|
sessionStorage.removeItem('fromScheduleForm');
|
||||||
const stored = sessionStorage.getItem('adminScheduleState');
|
const stored = sessionStorage.getItem('adminScheduleState');
|
||||||
return stored ? JSON.parse(stored) : null;
|
return stored ? JSON.parse(stored) : null;
|
||||||
}
|
}
|
||||||
// 그 외(reload, navigate)는 상태 초기화
|
// 폼에서 돌아온 게 아니면 상태 초기화
|
||||||
sessionStorage.removeItem('adminScheduleState');
|
sessionStorage.removeItem('adminScheduleState');
|
||||||
return null;
|
return null;
|
||||||
} catch { return null; }
|
} catch { return null; }
|
||||||
|
|
@ -523,7 +524,10 @@ function AdminSchedule() {
|
||||||
봇 관리
|
봇 관리
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => navigate('/admin/schedule/new')}
|
onClick={() => {
|
||||||
|
sessionStorage.setItem('fromScheduleForm', 'true');
|
||||||
|
navigate('/admin/schedule/new');
|
||||||
|
}}
|
||||||
className="flex items-center gap-2 px-5 py-3 bg-primary text-white rounded-xl hover:bg-primary-dark transition-colors font-medium shadow-sm"
|
className="flex items-center gap-2 px-5 py-3 bg-primary text-white rounded-xl hover:bg-primary-dark transition-colors font-medium shadow-sm"
|
||||||
>
|
>
|
||||||
<Plus size={20} />
|
<Plus size={20} />
|
||||||
|
|
@ -1070,7 +1074,10 @@ function AdminSchedule() {
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => navigate(`/admin/schedule/${schedule.id}/edit`)}
|
onClick={() => {
|
||||||
|
sessionStorage.setItem('fromScheduleForm', 'true');
|
||||||
|
navigate(`/admin/schedule/${schedule.id}/edit`);
|
||||||
|
}}
|
||||||
className="p-2 hover:bg-gray-200 rounded-lg transition-colors text-gray-500"
|
className="p-2 hover:bg-gray-200 rounded-lg transition-colors text-gray-500"
|
||||||
>
|
>
|
||||||
<Edit2 size={18} />
|
<Edit2 size={18} />
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue