This commit is contained in:
focp212@naver.com
2025-11-13 16:51:35 +09:00
parent f343a8a438
commit b20c625426
2 changed files with 60 additions and 37 deletions

View File

@@ -25,7 +25,7 @@ export const FavoriteWrapper = ({
const { menuOn, setMenuOn } = useMenuOnStore();
const { favoriteEditOn, setFavoriteEditOn } = useFavoriteEditOnStore();
const { menuIds, setMenuIds, deleteMenuId} = useMenuIds();
const [isFirst, setIsFirst] = useState<boolean>(true);
const [favoriteItems, setFavoriteItems] = useState<Array<UserFavorite>>([]);
const itemAdd: UserFavorite = {
@@ -36,10 +36,18 @@ export const FavoriteWrapper = ({
programPath: '',
};
const goToLastSlide = () => {
const goToSlide = (key: number | 'first' | 'last') => {
if(swiperInstance){
if(key === 'first'){
swiperInstance.slideTo(0);
}
else if(key === 'last'){
swiperInstance.slideTo(swiperInstance.slides.length - 1);
}
else{
swiperInstance.slideTo(key);
}
}
};
const onClickToFavoriteEdit = () => {
@@ -65,19 +73,35 @@ export const FavoriteWrapper = ({
};
const onClickToRemoveItem = (item?: UserFavorite) => {
let idx = -1;
let newFavorite: Array<UserFavorite> = favoriteItems.filter((value, index) => {
if(value.menuId === item?.menuId){
idx = index;
}
return value.menuId !== item?.menuId;
});
useStore.getState().UserStore.setUserFavorite(newFavorite);
setFavoriteItems(newFavorite);
if(idx > -1){
goToSlide(idx);
}
if(menuIds.length <= 1){
showAlert('바로가기는 1개이상 설정 필요 합니다.') ;
}
else{
if(item?.menuId){
deleteMenuId(item?.menuId);
}
}
};
const makeFavoriteItems = () => {
let rs = [];
for(let i=0;i<favoriteItems.length;i++){
let cnt = favoriteItems.length;
if(usingType === 'home'){
cnt = (cnt > 4)? 4: cnt;
}
for(let i=0;i<cnt;i++){
const displayName = i18n.language === 'en' && favoriteItems[i]?.menuNameEng
? favoriteItems[i]?.menuNameEng
: favoriteItems[i]?.menuName;
@@ -137,14 +161,18 @@ export const FavoriteWrapper = ({
};
useEffect(() => {
goToLastSlide();
getFavoriteList();
if(usingType === 'home'){
goToSlide('first');
}
else if(usingType === 'menu' && !isFirst){
setTimeout(() => {
goToSlide('last');
}, 100);
}
setIsFirst(false);
}, [changeMenuId, favoriteEditOn]);
useEffect(() => {
goToLastSlide();
}, [menuIds]);
return (
<>
<Swiper

View File

@@ -49,7 +49,6 @@ export const MenuCategory = ({
else{
showAlert(t('common.nopermission'));
}
};
const favoriteSetting = (
@@ -61,12 +60,14 @@ export const MenuCategory = ({
programPath?: string,
) => {
let userFavorite = useStore.getState().UserStore.userFavorite;
if(checked){
// 즐겨찾기가 4개 이상일 경우 마지막 항목 제거
if(userFavorite.length >= 10){
showAlert('즐겨찾기는 10개까지만 추가 할수 있습니다.');
}
else if(userFavorite.length <= 1){
showAlert('바로가기는 1개이상 설정 필요 합니다.');
}
else{
if(checked){
userFavorite = [
...userFavorite,
{
@@ -78,13 +79,7 @@ export const MenuCategory = ({
}
];
}
}
else{
// 즐겨찾기가 1개 남았을 때는 해제하지 않음
if(userFavorite.length <= 1){
callFavoiteItems();
return;
}
userFavorite = userFavorite.filter((value, _) => {
return value.menuId !== menuId
});
@@ -92,7 +87,7 @@ export const MenuCategory = ({
useStore.getState().UserStore.setUserFavorite(userFavorite);
setChangeMenuId(`${menuId}-${checked}`);
callFavoiteItems();
}
};
const callFavoiteItems = () => {
@@ -104,10 +99,6 @@ export const MenuCategory = ({
setMenuIds(newArr);
};
useEffect(() => {
callFavoiteItems();
}, [changeMenuId]);
const getMenuItems = () => {
let rs = [];
if(subMenu){
@@ -165,6 +156,10 @@ export const MenuCategory = ({
? MenuItems.find(item => item.menuId === menuId)?.menuNameEng || menuName
: menuName;
useEffect(() => {
callFavoiteItems();
}, [changeMenuId]);
return (
<>
<div