Skip to content

Commit

Permalink
Merge pull request #149 from 2020-NAVER-CAMPUS-HACKDAY/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jominjimail authored Jun 10, 2020
2 parents 9f695e7 + 1227743 commit 477aa86
Show file tree
Hide file tree
Showing 58 changed files with 1,053 additions and 767 deletions.
111 changes: 111 additions & 0 deletions client/components/Category/ChildrenCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React, {
FC, useEffect, useState,
} from 'react';
import useStyles from 'components/Category/ChildrenCard/styles';
import { Category } from 'interfaces/category';
import Router from 'next/router';
import clsx from 'clsx';

interface ChildrenCardProps {
childrenData: Category[];
isLastLevel: boolean;
catId: string | string[];
}
const ChildrenCard: FC<ChildrenCardProps> = (props) => {
const { childrenData, isLastLevel, catId } = props;
const classes = useStyles();
const [transValue, setTransValue] = useState<number>(0);

// TODO(jominjimail): duplicated function
const setCategory = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
const categoryId: string = event.currentTarget.value;
Router.push(`/search/category?catId=${categoryId}`, undefined, { shallow: true });
};

const calculateX = (client2target, Begin2target, target2End, clientHalfWidth):
{canMove: boolean; translate: number} => {
let canMove = false;
let translate = 0;

if (client2target < 0) {
// <---
if (target2End - Math.abs(client2target) > 0) {
canMove = true;
translate = client2target;
if (target2End < clientHalfWidth) {
translate = client2target + (clientHalfWidth - target2End);
}
}
} else if (client2target >= 0) {
// --->
if (Begin2target - client2target > 0) {
canMove = true;
translate = client2target;
if (Begin2target < clientHalfWidth) {
translate = client2target - (clientHalfWidth - Begin2target);
}
}
}
return { canMove, translate };
};

const moveX = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
if (isLastLevel) {
const scrollWidth = document.getElementById('section_scroll').getBoundingClientRect().width;
const clientWidthCenter = document.body.clientWidth / 2;
const firstCardElement = document.getElementById('firstCard');
const firstCardX = firstCardElement.getBoundingClientRect().x;

const { x, width } = event.currentTarget.getBoundingClientRect();
const targetCenter = x + width / 2;

const scrollBegin2targetCenter = Math.abs(firstCardX) + targetCenter;
const targetCenter2scrollEnd = scrollWidth - scrollBegin2targetCenter;

const clientCenter2targetCenter = clientWidthCenter - targetCenter;

const { canMove, translate } = calculateX(
clientCenter2targetCenter,
scrollBegin2targetCenter,
targetCenter2scrollEnd,
clientWidthCenter,
);
if (canMove && translate !== 0) {
setTransValue(transValue + translate);
}
}
setCategory(event);
};

useEffect(() => {
const scrollElement = document.getElementById('section_scroll');
scrollElement.style.transitionTimingFunction = 'cubic-bezier(0.1, 0.57, 0.1, 1)';
scrollElement.style.transitionDuration = '450ms';
scrollElement.style.transform = `translate(${transValue}px, 0px)`;
}, [transValue]);

const cardRender = (child: Category, index: number): React.ReactElement => {
const isHighLight = child.categoryId === catId;
const isFirst = index === 0;
return (
<button
id={isFirst ? 'firstCard' : ''}
key={child.categoryId}
className={clsx(classes.button, classes.cardContent, isHighLight && classes.highLight)}
onClick={moveX}
value={child.categoryId}
>
{child.value.categoryName}
</button>);
};

return (
<section className={classes.container}>
<div id='section_scroll' className={clsx(classes.card, classes.scroll)}>
{childrenData.map((child, index) => cardRender(child, index))}
</div>
</section>
);
};

export default ChildrenCard;
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import { makeStyles } from '@material-ui/core/styles';
import { AppColor } from 'constant';

const useStyles = makeStyles({
card: {
display: 'flex',
container: {
backgroundColor: AppColor.GREY,
minWidth: '100%',
overflowX: 'hidden',
height: '2.5rem',
overflowX: 'auto',
'&::-webkit-scrollbar': {
display: 'none',
},
},
card: {
display: 'inline-flex',
height: '100%',
},
scroll: {

},
cardContent: {
padding: '0 11px',
Expand All @@ -19,10 +25,14 @@ const useStyles = makeStyles({
button: {
background: 'none',
border: 'none',
font: 'inherit',
cursor: 'pointer',
font: 'inherit',
outline: 'inherit',
},
highLight: {
color: AppColor.LIGHT_BLUE,
fontWeight: 650,
},
});

export default useStyles;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react';
import { Category } from 'interfaces/category';
import Router from 'next/router';
import useStyles from 'components/CategoryHeader/styles';
import useStyles from 'components/Category/Header/styles';
import { PublicImageCategoryPath, ImageArray, ImageExtension } from 'constant';

interface CategoryHeaderProps {
Expand All @@ -14,13 +14,13 @@ const CategoryHeader: FC<CategoryHeaderProps> = (props) => {

const setCategory = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
const categoryId: string = event.currentTarget.value;
Router.push(`/tempCategoryDetail/${categoryId}`);
Router.push(`/search/category?catId=${categoryId}`, undefined, { shallow: true });
};

const categoryElements = categoryData.map((category, index) => {
const { categoryId } = category;
return (
<div className={classes.content} key={categoryId}>
<div className={classes.item} key={categoryId}>
<button
className={classes.button}
onClick={setCategory}
Expand All @@ -37,7 +37,12 @@ const CategoryHeader: FC<CategoryHeaderProps> = (props) => {

return (
<div className={classes.container}>
{categoryElements}
<h3 className={classes.title}>์นดํ…Œ๊ณ ๋ฆฌ</h3>
<div className={classes.content}>
<div className={classes.items}>
{categoryElements}
</div>
</div>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
container: {
padding: '0 0.5rem',
},
title: {
margin: '0.7rem 0',
},
content: {
display: 'flex',
height: '17rem',
justifyContent: 'center',
maxWidth: '375px',
width: '100%',
},
items: {
alignItems: 'center',
background: 'white',
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'flex-start',
maxWidth: '375',
padding: '0 0.5rem',
padding: '0.5rem 0',
},
content: {
item: {
display: 'flex',
flexDirection: 'column',
height: '5rem',
Expand Down
48 changes: 48 additions & 0 deletions client/components/Category/WholeName/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { FC } from 'react';
import useStyles from 'components/Category/WholeName/styles';
import Router from 'next/router';
import clsx from 'clsx';

interface CategoryBoxProps {
names: string;
ids: string;
}
const WholeName: FC<CategoryBoxProps> = (props) => {
const { names, ids } = props;
const classes = useStyles();
// TODO(jominjimail): remove this constant varialbe to constant.ts
const SEPARATOR = '>';
const nameArray = names.split(SEPARATOR);
const idArray = ids.split(SEPARATOR);
const lastIndex = nameArray.length - 1;

// TODO(jominjimail): duplicated function
const setCategory = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
const categoryId: string = event.currentTarget.value;
Router.push(`/search/category?catId=${categoryId}`, undefined, { shallow: true });
};

const makeElement = (name, index): React.ReactElement => {
const isLast = (index === lastIndex);
return (
<>
<button
key={index}
className={clsx(classes.button, isLast ? classes.active : classes.inactive)}
onClick={setCategory}
value={idArray[index]}>
{name}
</button>
{!isLast && <span className={classes.separator}>{SEPARATOR}</span>}
</>
);
};

return (
<section className={classes.container}>
{nameArray.map((name, index) => makeElement(name, index))}
</section>
);
};

export default WholeName;
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@ const useStyles = makeStyles({
container: {
background: AppColor.WHITE,
display: 'flex',
height: '2.5rem',
color: 'black',
height: '2.5rem',
minWidth: '100%',
overflowX: 'auto',
'&::-webkit-scrollbar': {
display: 'none',
},
},
button: {
background: 'none',
border: 'none',
cursor: 'pointer',
font: 'inherit',
outline: 'inherit',
whiteSpace: 'nowrap',
},
inactive: {
color: AppColor.BLACK50,
},
active: {
color: AppColor.BLACK,
fontWeight: 650,
},
button: {
background: 'none',
border: 'none',
font: 'inherit',
cursor: 'pointer',
outline: 'inherit',
separator: {
color: AppColor.BLACK50,
display: 'table',
margin: 'auto 0',
},
});

Expand Down
36 changes: 0 additions & 36 deletions client/components/CategoryHeader/ChildrenCard/index.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions client/components/CategoryHeader/WholeCategoryName/index.tsx

This file was deleted.

Loading

0 comments on commit 477aa86

Please sign in to comment.