즐겨찾기 추가/삭제 로직 개선 및 스크롤 위치 수정

- 즐겨찾기 삭제 시 최소 1개 유지 검증 추가 (favorite-wrapper.tsx)
- 즐겨찾기 추가/삭제 로직 분리 및 개선 (menu-category.tsx)
  - 추가 시: 최대 10개만 체크
  - 삭제 시: 최소 1개 유지 체크
  - 각 조건에서 early return으로 명확한 흐름 구성
- 메뉴 오픈 시 즐겨찾기 목록 스크롤을 맨 앞으로 초기화
  - prevMenuOn 상태로 메뉴 오픈 감지
  - 추가/삭제 시에만 마지막 아이템으로 스크롤
- 로컬라이제이션 키 추가
  - cannotDeleteLastItem: 최소 1개 유지 메시지
  - cannotAddMoreThan10: 최대 10개 제한 메시지
- snackBar import 추가 및 showAlert에서 snackBar로 변경

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jay Sheen
2025-11-13 17:24:29 +09:00
parent b20c625426
commit 8fbc7d2f74
4 changed files with 71 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';
import { MenuItems } from '@/entities/common/model/constant';
import { showAlert } from '@/widgets/show-alert';
import { checkGrant } from '@/shared/lib/check-grant';
import { snackBar } from '@/shared/lib';
export interface MenuCategoryProps {
menuId?: number;
@@ -60,34 +61,41 @@ export const MenuCategory = ({
programPath?: string,
) => {
let userFavorite = useStore.getState().UserStore.userFavorite;
if(userFavorite.length >= 10){
showAlert('즐겨찾기는 10개까지만 추가 할수 있습니다.');
// 추가 시: 최대 10개 체크
if(checked && userFavorite.length >= 10){
snackBar(t('favorite.cannotAddMoreThan10'));
return;
}
else if(userFavorite.length <= 1){
showAlert('바로가기는 1개이상 설정 필요 합니다.');
// 삭제 시: 최소 1개 체크
if(!checked && userFavorite.length <= 1){
snackBar(t('favorite.cannotDeleteLastItem'));
return;
}
// 추가 또는 삭제 실행
if(checked){
userFavorite = [
...userFavorite,
{
menuId: menuId,
menuName: menuName,
menuNameEng: menuNameEng,
iconFilePath: iconFilePath,
programPath: programPath
}
];
}
else{
if(checked){
userFavorite = [
...userFavorite,
{
menuId: menuId,
menuName: menuName,
menuNameEng: menuNameEng,
iconFilePath: iconFilePath,
programPath: programPath
}
];
}
else{
userFavorite = userFavorite.filter((value, _) => {
return value.menuId !== menuId
});
}
useStore.getState().UserStore.setUserFavorite(userFavorite);
setChangeMenuId(`${menuId}-${checked}`);
callFavoiteItems();
userFavorite = userFavorite.filter((value, _) => {
return value.menuId !== menuId
});
}
useStore.getState().UserStore.setUserFavorite(userFavorite);
setChangeMenuId(`${menuId}-${checked}`);
callFavoiteItems();
};
const callFavoiteItems = () => {