[OnSalePanel] OnSalePanel, CategoryNav 수정
Detail Notes : 1. OnSalePanel, targetId 관련 로직 수정 2. CategoryNav, CategoryNavItem 최적화
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
import React from 'react';
|
import React, { useCallback } from "react";
|
||||||
|
|
||||||
import VirtualGridList from '@enact/sandstone/VirtualList';
|
import { VirtualGridList } from "@enact/sandstone/VirtualList";
|
||||||
import SpotlightContainerDecorator
|
import SpotlightContainerDecorator from "@enact/spotlight/SpotlightContainerDecorator";
|
||||||
from '@enact/spotlight/SpotlightContainerDecorator';
|
import ri from "@enact/ui/resolution";
|
||||||
import ri from '@enact/ui/resolution';
|
|
||||||
|
|
||||||
import CategoryNavItem from '../CategoryNavItem/CategoryNavItem';
|
import CategoryNavItem from "../CategoryNavItem/CategoryNavItem";
|
||||||
import css from './CategoryNav.module.less';
|
import css from "./CategoryNav.module.less";
|
||||||
|
|
||||||
|
const LIST_ITEM_CONF = {
|
||||||
|
ITEM_WIDTH: 210 * 2,
|
||||||
|
ITEM_HEIGHT: 236 * 2,
|
||||||
|
SAPCING: 30 * 2,
|
||||||
|
};
|
||||||
|
|
||||||
const Container = SpotlightContainerDecorator(
|
const Container = SpotlightContainerDecorator(
|
||||||
{ leaveFor: { right: "" }, enterTo: "last-focused" },
|
{ leaveFor: { right: "" }, enterTo: "last-focused" },
|
||||||
@@ -15,21 +20,24 @@ const Container = SpotlightContainerDecorator(
|
|||||||
|
|
||||||
export default function CategoryNav({
|
export default function CategoryNav({
|
||||||
categoryInfos,
|
categoryInfos,
|
||||||
currentLgCatCd,
|
currentCategoryCode,
|
||||||
onCategoryNavClick,
|
onCategoryNavClick,
|
||||||
...rest
|
...rest
|
||||||
}) {
|
}) {
|
||||||
const renderItem = ({ index, ...rest }) => {
|
const renderItem = useCallback(
|
||||||
return (
|
({ index, ...rest }) => {
|
||||||
<CategoryNavItem
|
return (
|
||||||
categoryInfos={categoryInfos}
|
<CategoryNavItem
|
||||||
currentLgCatCd={currentLgCatCd}
|
categoryInfos={categoryInfos}
|
||||||
onCategoryNavClick={onCategoryNavClick}
|
currentCategoryCode={currentCategoryCode}
|
||||||
index={index}
|
onCategoryNavClick={onCategoryNavClick}
|
||||||
{...rest}
|
index={index}
|
||||||
/>
|
{...rest}
|
||||||
);
|
/>
|
||||||
};
|
);
|
||||||
|
},
|
||||||
|
[categoryInfos, currentCategoryCode, onCategoryNavClick]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container className={css.container} {...rest}>
|
<Container className={css.container} {...rest}>
|
||||||
@@ -41,12 +49,12 @@ export default function CategoryNav({
|
|||||||
horizontalScrollbar="hidden"
|
horizontalScrollbar="hidden"
|
||||||
itemRenderer={renderItem}
|
itemRenderer={renderItem}
|
||||||
itemSize={{
|
itemSize={{
|
||||||
minWidth: ri.scale(210 * 2),
|
minWidth: ri.scale(LIST_ITEM_CONF.ITEM_WIDTH),
|
||||||
minHeight: ri.scale(236 * 2),
|
minHeight: ri.scale(LIST_ITEM_CONF.ITEM_HEIGHT),
|
||||||
}}
|
}}
|
||||||
noScrollByWheel
|
noScrollByWheel
|
||||||
scrollMode="translate"
|
scrollMode="translate"
|
||||||
spacing={ri.scale(30 * 2)}
|
spacing={ri.scale(LIST_ITEM_CONF.SAPCING)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -1,36 +1,46 @@
|
|||||||
import React from 'react';
|
import React, { memo, useCallback } from "react";
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from "classnames";
|
||||||
|
|
||||||
import Spottable from '@enact/spotlight/Spottable';
|
import Spottable from "@enact/spotlight/Spottable";
|
||||||
|
|
||||||
import css from './CategoryNavItem.module.less';
|
import css from "./CategoryNavItem.module.less";
|
||||||
|
|
||||||
const SpottableComponent = Spottable("div");
|
const SpottableComponent = Spottable("div");
|
||||||
|
|
||||||
export default function CategoryNavItem({
|
export default memo(function CategoryNavItem({
|
||||||
categoryInfos,
|
categoryInfos,
|
||||||
currentLgCatCd,
|
currentCategoryCode,
|
||||||
onCategoryNavClick,
|
onCategoryNavClick,
|
||||||
index,
|
index,
|
||||||
...rest
|
...rest
|
||||||
}) {
|
}) {
|
||||||
|
const {
|
||||||
|
lgCatCd: categoryCode,
|
||||||
|
lgCatNm: categoryName, //
|
||||||
|
} = categoryInfos[index];
|
||||||
|
|
||||||
|
const handleClick = useCallback(
|
||||||
|
(categoryCode) => {
|
||||||
|
onCategoryNavClick && onCategoryNavClick(categoryCode);
|
||||||
|
},
|
||||||
|
[categoryCode, currentCategoryCode]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SpottableComponent
|
<SpottableComponent
|
||||||
className={classNames(
|
className={classNames(
|
||||||
css.category,
|
css.category,
|
||||||
categoryInfos[index].lgCatCd === currentLgCatCd && css.selected
|
categoryCode === currentCategoryCode && css.selected
|
||||||
)}
|
)}
|
||||||
key={categoryInfos[index].lgCatCd}
|
key={categoryCode}
|
||||||
onClick={() => onCategoryNavClick(categoryInfos[index].lgCatCd)}
|
onClick={() => handleClick(categoryCode)}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<span
|
<span className={css[`category-icon-${categoryCode}`]} />
|
||||||
className={css[`category-icon-${categoryInfos[index].lgCatCd}`]}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<strong>{categoryInfos[index].lgCatNm}</strong>
|
<strong>{categoryName}</strong>
|
||||||
</SpottableComponent>
|
</SpottableComponent>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|||||||
@@ -91,8 +91,7 @@
|
|||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
.position(@position: absolute, @bottom: 0);
|
||||||
bottom: 0;
|
|
||||||
display: block;
|
display: block;
|
||||||
.size(@w: 100%, @h:6px);
|
.size(@w: 100%, @h:6px);
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
import React, {
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
|
|
||||||
import {
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
useDispatch,
|
|
||||||
useSelector,
|
|
||||||
} from 'react-redux';
|
|
||||||
|
|
||||||
import { getOnSaleInfo } from '../../actions/onSaleActions';
|
import { getOnSaleInfo } from "../../actions/onSaleActions";
|
||||||
import TBody from '../../components/TBody/TBody';
|
import TBody from "../../components/TBody/TBody";
|
||||||
import TItemCard from '../../components/TItemCard/TItemCard';
|
import TItemCard from "../../components/TItemCard/TItemCard";
|
||||||
import TopButton from '../../components/TopButton/TopButton';
|
import TopButton from "../../components/TopButton/TopButton";
|
||||||
import TPanel from '../../components/TPanel/TPanel';
|
import TPanel from "../../components/TPanel/TPanel";
|
||||||
import { SpotlightIds } from '../../utils/SpotlightIds';
|
import { SpotlightIds } from "../../utils/SpotlightIds";
|
||||||
import CategoryNav from '../OnSalePanel/CategoryNav/CategoryNav';
|
import CategoryNav from "../OnSalePanel/CategoryNav/CategoryNav";
|
||||||
import OnSaleProductsGrid
|
import OnSaleProductsGrid from "../OnSalePanel/OnSaleProductsGrid/OnSaleProductsGrid";
|
||||||
from '../OnSalePanel/OnSaleProductsGrid/OnSaleProductsGrid';
|
import css from "./OnSalePanel.module.less";
|
||||||
import css from './OnSalePanel.module.less';
|
|
||||||
|
|
||||||
export default function OnSalePanel() {
|
export default function OnSalePanel() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -27,38 +20,47 @@ export default function OnSalePanel() {
|
|||||||
);
|
);
|
||||||
const saleInfos = useSelector((state) => state.onSale.onSaleData.saleInfos);
|
const saleInfos = useSelector((state) => state.onSale.onSaleData.saleInfos);
|
||||||
|
|
||||||
const [currentLgCatCd, setCurrentLgCatCd] = useState();
|
const [currentCategoryCode, setCurrentCategoryCode] = useState();
|
||||||
|
const [targetId, setTargetId] = useState();
|
||||||
|
|
||||||
const targetId = saleInfos[0].saleProductInfos[0].prdtId;
|
const handleCategoryNavClick = useCallback(
|
||||||
|
(categoryCode) => {
|
||||||
|
if (currentCategoryCode === categoryCode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const handleCategoryNavClick = (lgCatCd) => {
|
setCurrentCategoryCode(categoryCode);
|
||||||
if (currentLgCatCd === lgCatCd) {
|
},
|
||||||
return;
|
[currentCategoryCode]
|
||||||
}
|
);
|
||||||
|
|
||||||
setCurrentLgCatCd(lgCatCd);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (categoryInfos && !currentLgCatCd) {
|
if (categoryInfos && !currentCategoryCode) {
|
||||||
const initialLgCatCd = categoryInfos[0].lgCatCd;
|
const initialLgCatCd = categoryInfos[0].lgCatCd;
|
||||||
setCurrentLgCatCd(initialLgCatCd);
|
setCurrentCategoryCode(initialLgCatCd);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentLgCatCd) {
|
if (currentCategoryCode) {
|
||||||
dispatch(
|
dispatch(
|
||||||
getOnSaleInfo({ categoryIncFlag: "Y", lgCatCd: currentLgCatCd })
|
getOnSaleInfo({ categoryIncFlag: "Y", lgCatCd: currentCategoryCode })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [currentLgCatCd]);
|
}, [currentCategoryCode, dispatch]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (saleInfos) {
|
||||||
|
const id = saleInfos[0].saleProductInfos[0].prdtId;
|
||||||
|
setTargetId(id);
|
||||||
|
}
|
||||||
|
}, [dispatch, saleInfos]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TPanel className={css.container}>
|
<TPanel className={css.container}>
|
||||||
<CategoryNav
|
<CategoryNav
|
||||||
categoryInfos={categoryInfos}
|
categoryInfos={categoryInfos}
|
||||||
currentLgCatCd={currentLgCatCd}
|
currentCategoryCode={currentCategoryCode}
|
||||||
onCategoryNavClick={handleCategoryNavClick}
|
onCategoryNavClick={handleCategoryNavClick}
|
||||||
/>
|
/>
|
||||||
<TBody className={css.tBody}>
|
<TBody className={css.tBody}>
|
||||||
|
|||||||
Reference in New Issue
Block a user