Skip to content

Commit

Permalink
Refactor: home
Browse files Browse the repository at this point in the history
  • Loading branch information
hookor authored and cuconveniencestore committed Jun 3, 2024
1 parent eb8b679 commit 8750d24
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 108 deletions.
16 changes: 12 additions & 4 deletions src/components/home/CaffeineFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { lazy, Suspense } from 'react';
import Button from '@/components/common/Button';
import CaffeineInfo from '@/components/home/CaffeineInfo';
import CoffeeSelection from '@/components/home/CoffeeSelection';
import { BUTTON_TEXTS } from '@/constants/common';
import { useNavigateTo } from '@/hooks/useNavigateTo';
import { styled } from 'styled-system/jsx';
import { RegistBtn } from '@/styles/styles';
import { css, cx } from 'styled-system/css';
import { useGetSignedIn } from '@/hooks/useGetSignedIn';

const CaffeineInfo = lazy(() => import('@/components/home/CaffeineInfo'));
const CoffeeSelection = lazy(() => import('@/components/home/CoffeeSelection'));

const CaffeineFilter = () => {
const registPage = useNavigateTo('/post/register');
const { signedIn } = useGetSignedIn();

return (
<Container>
<CoffeeSelection />
<CaffeineInfo />
<Suspense>
<CoffeeSelection />
</Suspense>

<Suspense>
<CaffeineInfo />
</Suspense>

{signedIn && (
<Button
text={BUTTON_TEXTS.regist}
Expand Down
29 changes: 16 additions & 13 deletions src/components/home/CoffeeMenuSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lazy, Suspense } from 'react';
import { useParams } from 'react-router-dom';
import { useRecoilState, useSetRecoilState } from 'recoil';

import SelectBox from '@/components/common/SelectBox';
import RegisterLabel from '@/components/post/RegisterLabel';
import { CAFFEINE_FILTER_TEXTS } from '@/constants/home';
import useGetCoffeeList from '@/hooks/useGetCoffeeList';
Expand All @@ -14,6 +14,7 @@ import { SmStyle } from '@/styles/styles';
import { Column, Grid } from '@/styles/layout';

const { coffeeMenu } = CAFFEINE_FILTER_TEXTS;
const SelectBox = lazy(() => import('@/components/common/SelectBox'));

const CoffeeMenuSelection = () => {
const { postid } = useParams();
Expand Down Expand Up @@ -95,18 +96,20 @@ const CoffeeMenuSelection = () => {
essential
/>
)}
<SelectBox
value={registInfo.brand}
defaultValue={registInfo.brand || coffeeMenu.brand}
data={brandList}
onClick={selectBrand}
/>
<SelectBox
value={registInfo.menu}
defaultValue={coffeeMenu.menu}
data={menuList}
onClick={selectMenu}
/>
<Suspense>
<SelectBox
value={registInfo.brand}
defaultValue={registInfo.brand || coffeeMenu.brand}
data={brandList}
onClick={selectBrand}
/>
<SelectBox
value={registInfo.menu}
defaultValue={coffeeMenu.menu}
data={menuList}
onClick={selectMenu}
/>
</Suspense>
</CoffeeSelectContainer>
</div>
);
Expand Down
16 changes: 12 additions & 4 deletions src/components/home/TodayCaffeineInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import TodayCaffeineText from '@/components/home/TodayCaffeineText';
import WaterPerCoffee from '@/components/home/WaterPerCoffee';
import { lazy, Suspense } from 'react';
import { styled } from 'styled-system/jsx';

const TodayCaffeineText = lazy(
() => import('@/components/home/TodayCaffeineText')
);
const WaterPerCoffee = lazy(() => import('@/components/home/WaterPerCoffee'));

const TodayCaffeineInfo = () => {
return (
<Container>
<TodayCaffeineText />
<WaterPerCoffee />
<Suspense>
<TodayCaffeineText />
</Suspense>
<Suspense>
<WaterPerCoffee />
</Suspense>
</Container>
);
};
Expand Down
66 changes: 32 additions & 34 deletions src/components/home/TodayCaffeineText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,49 @@ const TodayCaffeineText = () => {
const allCount = todayCoffeeData?.allCount;
const waterPerCoffeeCount = allCount && allCount * 2 - takedWater;

const anonymousText = !user?.nickname && (
<div className={Column}>
<span>{anonymous.first}</span>
<span>{anonymous.second}</span>
<span>{anonymous.third}</span>
</div>
);

const signedInText = (
<div className={Column}>
<span>
{user ? user?.nickname : userInfo.nickname}
{signedIn.first}
</span>
<div>
<CaffeineInfo>{user?.sum || 0}mg</CaffeineInfo>
{signedIn.second}
</div>
<span>{signedIn.third}</span>
</div>
);

const signedInMessage = (
<div>
{signedIn.messageText.first}
{waterPerCoffeeCount ? ` ${waterPerCoffeeCount}` : null}
{waterPerCoffeeCount
? signedIn.messageText.second
: signedIn.messageText.third}
</div>
);

return (
<div className={HomeHeaderContent}>
<div className={cx(Align, Between)}>
{user?.nickname ? signedInText : anonymousText}
{user?.nickname ? (
<div className={Column}>
<span>
{user ? user?.nickname : userInfo.nickname}
{signedIn.first}
</span>
<div>
<CaffeineInfo>{user?.sum || 0}mg</CaffeineInfo>
{signedIn.second}
</div>
<span>{signedIn.third}</span>
</div>
) : (
<div className={Column}>
<span>{anonymous.first}</span>
<span>{anonymous.second}</span>
<span>{anonymous.third}</span>
</div>
)}
<CoffeeImage
src="/png/coffee_mainimg.png"
alt="coffee"
srcset="/png/coffee_mainimg.png 120w"

Check failure on line 47 in src/components/home/TodayCaffeineText.tsx

View workflow job for this annotation

GitHub Actions / Build and Delpoy React (18.15.0)

Type '{ src: string; alt: string; srcset: string; sizes: string; }' is not assignable to type 'IntrinsicAttributes & Omit<Omit<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref">, "ref"> & { ...; }'.
sizes="(min-width: 360px) 120px, (max-width: 500px) 120px"
/>
</div>
<AlertBubble
type={allCount && allCount >= 1 ? '' : null}
message={
allCount && allCount >= 1 ? signedInMessage : anonymous.messageText
allCount && allCount >= 1 ? (
<div>
{signedIn.messageText.first}
{waterPerCoffeeCount ? ` ${waterPerCoffeeCount}` : null}
{waterPerCoffeeCount
? signedIn.messageText.second
: signedIn.messageText.third}
</div>
) : (
anonymous.messageText
)
}
/>
</div>
Expand Down
91 changes: 46 additions & 45 deletions src/components/home/WaterPerCoffee.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazy } from 'react';
import { lazy, Suspense } from 'react';
import { useRecoilValue } from 'recoil';

import { BUTTON_TEXTS } from '@/constants/common';
Expand Down Expand Up @@ -31,46 +31,6 @@ const WaterPerCoffee = () => {
const user = useRecoilValue(userInfoState);
const { coffeeInfo: todayCoffeeData } = useGetTodayCoffeeData();

const anonymousCard = (
<div className={cx(Column, Center, MarginAuto)}>
<CTA
text={anonymous.card}
actionText={BUTTON_TEXTS.signIn1}
btn={true}
fn={useNavigateTo('/start/1')}
/>
</div>
);

const notConsumedCoffee = (
<div className={cx(Column, Center, MarginAuto)}>
<span className={AlertMessage}>{signedIn.card.notConsumed}</span>
<Button
text={signedIn.btn}
onClick={useNavigateTo('/post/register')}
className={RegistCoffeeBtn}
/>
</div>
);

const consumedCoffee = (
<ConsumedCoffeeContainer className={Column}>
<div className={cx(Flex, Between)}>
<CoffeeIntake data={todayCoffeeData} />
<WaterIntake coffeeCount={todayCoffeeData?.allCount} />
</div>
<TodayMenuList className={Flex}>
{todayCoffeeData?.allCount !== null &&
todayCoffeeData?.item.map((item, idx) => (
<TodayMenuItem
data={item}
key={idx}
/>
))}
</TodayMenuList>
</ConsumedCoffeeContainer>
);

return (
<Container
className={cx(
Expand All @@ -80,12 +40,53 @@ const WaterPerCoffee = () => {
Align,
Between
)}>
{!user.nickname && anonymousCard}
{user.nickname && !todayCoffeeData?.allCount && notConsumedCoffee}
{!user.nickname && (
<div className={cx(Column, Center, MarginAuto)}>
<Suspense>
<CTA
text={anonymous.card}
actionText={BUTTON_TEXTS.signIn1}
btn={true}
fn={useNavigateTo('/start/1')}
/>
</Suspense>
</div>
)}
{user.nickname && !todayCoffeeData?.allCount && (
<div className={cx(Column, Center, MarginAuto)}>
<span className={AlertMessage}>{signedIn.card.notConsumed}</span>
<Suspense>
<Button
text={signedIn.btn}
onClick={useNavigateTo('/post/register')}
className={RegistCoffeeBtn}
/>
</Suspense>
</div>
)}
{user.nickname &&
todayCoffeeData?.allCount &&
todayCoffeeData?.allCount >= 1 &&
consumedCoffee}
todayCoffeeData?.allCount >= 1 && (
<ConsumedCoffeeContainer className={Column}>
<div className={cx(Flex, Between)}>
<Suspense>
<CoffeeIntake data={todayCoffeeData} />
</Suspense>
<Suspense>
<WaterIntake coffeeCount={todayCoffeeData?.allCount} />
</Suspense>
</div>
<TodayMenuList className={Flex}>
{todayCoffeeData?.allCount !== null &&
todayCoffeeData?.item.map((item, idx) => (
<TodayMenuItem
data={item}
key={idx}
/>
))}
</TodayMenuList>
</ConsumedCoffeeContainer>
)}
</Container>
);
};
Expand Down
29 changes: 21 additions & 8 deletions src/pages/Page-Home.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import CaffeineFilter from '@/components/home/CaffeineFilter';
import HomeFooter from '@/components/home/HomeFooter';
import TodayCaffeineInfo from '@/components/home/TodayCaffeineInfo';
import WeeklyPopular from '@/components/home/WeeklyPopular';
import { lazy, Suspense } from 'react';

import SEOMeta from '@/components/common/SEOMeta';
import SEO_DATA from '@/constants/SEOData';
import { useComposeHeader } from '@/hooks/useComposeHeader';
import useGetUserInfo from '@/hooks/useGetUserInfo';
import { styled } from 'styled-system/jsx';

const CaffeineFilter = lazy(() => import('../components/home/CaffeineFilter'));
const TodayCaffeineInfo = lazy(
() => import('../components/home/TodayCaffeineInfo')
);
const HomeFooter = lazy(() => import('../components/home/HomeFooter'));
const WeeklyPopular = lazy(() => import('../components/home/WeeklyPopular'));

const Home = () => {
useComposeHeader(true, '', 'icons');
useGetUserInfo();
Expand All @@ -16,11 +21,19 @@ const Home = () => {
<>
<SEOMeta pageData={SEO_DATA.home} />
<Container>
<TodayCaffeineInfo />
<CaffeineFilter />
<WeeklyPopular />
<Suspense>
<TodayCaffeineInfo />
</Suspense>
<Suspense>
<CaffeineFilter />
</Suspense>
<Suspense>
<WeeklyPopular />
</Suspense>
</Container>
<HomeFooter />
<Suspense>
<HomeFooter />
</Suspense>
</>
);
};
Expand Down

0 comments on commit 8750d24

Please sign in to comment.