Skip to content

Commit

Permalink
Merge pull request #470 from New-Barams/feat/#467/business-logic
Browse files Browse the repository at this point in the history
[혜수] - 비즈니스 로직 분리
  • Loading branch information
suehdn authored Feb 5, 2024
2 parents 0ca4763 + 74e9689 commit 86de908
Show file tree
Hide file tree
Showing 38 changed files with 433 additions and 381 deletions.
22 changes: 0 additions & 22 deletions src/app/(header)/_components/Content.tsx

This file was deleted.

42 changes: 0 additions & 42 deletions src/app/(header)/_components/Header/Header.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/app/(header)/_components/Header/index.scss

This file was deleted.

53 changes: 0 additions & 53 deletions src/app/(header)/_components/LinkIconText/LinkIconText.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions src/app/(header)/_components/LinkIconText/index.scss

This file was deleted.

16 changes: 0 additions & 16 deletions src/app/(header)/_components/index.scss

This file was deleted.

24 changes: 8 additions & 16 deletions src/app/(header)/explore/_components/ExplorePlans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@

import { ToTopFloatingButton } from '@/components';
import { COLOR } from '@/constants';
import { useAllPlansQuery } from '@/hooks/apis/useAllPlansQuery';
import { SortType } from '@/types/apis/plan/GetAllPlans';
import classNames from 'classnames';
import { useMemo, useState } from 'react';
import InfiniteScroll from 'react-infinite-scroller';
import { FadeLoader } from 'react-spinners';
import Plans from './Plans/Plans';
import Tab from './Tab/Tab';
import { useExplorePlans } from './hooks';
import './index.scss';

export default function ExplorePlans() {
const [sort, setSort] = useState<SortType>('latest');
const [current, setCurrent] = useState(true);
const { loadedPlans, fetchNextPage, hasNextPage } = useAllPlansQuery({
sort,
current,
});
const flatLoadedPlans = useMemo(() => loadedPlans.flat(), [loadedPlans]);
const handleSort = (condition: SortType) => {
setSort(condition);
};
const handleYear = (isNewYear: boolean) => {
setCurrent(isNewYear);
};
const {
fetchNextPage,
flatLoadedPlans,
handleSort,
handleYear,
hasNextPage,
} = useExplorePlans();
return (
<div className={classNames('explore-plans')}>
<div className={classNames('explore-plans__wrapper')}>
Expand Down
25 changes: 8 additions & 17 deletions src/app/(header)/explore/_components/Tab/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use client';

import { SortType } from '@/types/apis/plan/GetAllPlans';
import { TabProps } from '@/types';
import classNames from 'classnames';
import { useState } from 'react';
import React from 'react';
import { useTab } from '../hooks';
import './index.scss';

type TabProps = {
handleSort: (condition: SortType) => void;
handleYear: (isNewYear: boolean) => void;
};

export default function Tab({ handleSort, handleYear }: TabProps) {
const [currentYearTab, setCurrentYearTab] = useState(0);
const [currentSortTab, setCurrentSortTab] = useState(0);
const {
currentSortTab,
currentYearTab,
selectSortMenuHandler,
selectYearMenuHandler,
} = useTab({ handleSort, handleYear });

const yearMenu = [
{ name: '새해' },
Expand All @@ -23,14 +22,6 @@ export default function Tab({ handleSort, handleYear }: TabProps) {
];
const sortMenu = [{ name: '최신순' }, { name: '인기순' }];

const selectYearMenuHandler = (index: number) => {
setCurrentYearTab(index);
handleYear(index === 0 ? true : false);
};
const selectSortMenuHandler = (index: number) => {
setCurrentSortTab(index);
handleSort(index === 0 ? 'latest' : 'ajaja');
};
return (
<div className={classNames('tab__wrapper')}>
<div className={classNames('tab__wrapper-year')}>
Expand Down
2 changes: 2 additions & 0 deletions src/app/(header)/explore/_components/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as useTab } from './useTab';
export { default as useExplorePlans } from './useExplorePlans';
31 changes: 31 additions & 0 deletions src/app/(header)/explore/_components/hooks/useExplorePlans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useAllPlansQuery } from '@/hooks/apis/useAllPlansQuery';
import { SortType } from '@/types/apis/plan/GetAllPlans';
import { useMemo, useState } from 'react';

export default function useExplorePlans() {
const [sort, setSort] = useState<SortType>('latest');
const [current, setCurrent] = useState(true);
const { loadedPlans, fetchNextPage, hasNextPage } = useAllPlansQuery({
sort,
current,
});
const flatLoadedPlans = useMemo(() => loadedPlans.flat(), [loadedPlans]);
const handleSort = (condition: SortType) => {
setSort(condition);
};
const handleYear = (isNewYear: boolean) => {
setCurrent(isNewYear);
};
return {
sort,
setSort,
current,
setCurrent,
loadedPlans,
fetchNextPage,
hasNextPage,
flatLoadedPlans,
handleSort,
handleYear,
};
}
23 changes: 23 additions & 0 deletions src/app/(header)/explore/_components/hooks/useTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TabProps } from '@/types/Tab';
import { useState } from 'react';

export default function useTab({ handleSort, handleYear }: TabProps) {
const [currentYearTab, setCurrentYearTab] = useState(0);
const [currentSortTab, setCurrentSortTab] = useState(0);
const selectYearMenuHandler = (index: number) => {
setCurrentYearTab(index);
handleYear(index === 0 ? true : false);
};
const selectSortMenuHandler = (index: number) => {
setCurrentSortTab(index);
handleSort(index === 0 ? 'latest' : 'ajaja');
};
return {
currentYearTab,
setCurrentYearTab,
currentSortTab,
setCurrentSortTab,
selectYearMenuHandler,
selectSortMenuHandler,
};
}
30 changes: 4 additions & 26 deletions src/app/(header)/home/_components/MyPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,19 @@
import { Dropdown } from '@/components';
import { maxPlan } from '@/constants/plan';
import { planIcons } from '@/constants/planIcons';
import { canMakeNewPlanStore } from '@/stores/canMakeNewPlanStore';
import { GetMyPlansResponse } from '@/types/apis/plan/GetMyPlans';
import { checkThisYear } from '@/utils/checkThisYear';
import classNames from 'classnames';
import Image from 'next/image';
import { useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import NewPlan from './NewPlan/NewPlan';
import Plan from './Plan/Plan';
import ProgressBar from './ProgressBar/ProgressBar';
import { useMyPlan } from './hooks';

type MyPlanProps = {
myPlans: GetMyPlansResponse;
};

export default function MyPlan({ myPlans }: MyPlanProps) {
const { data: myPlansData } = myPlans;
const yearList = myPlansData.map((x) => x.year);
const setCanMakeNewPlan = useSetRecoilState(canMakeNewPlanStore);
const [year, setYear] = useState(yearList[0]);
const [yearData, setYearData] = useState(myPlansData[0]);
const [yearDataLength, setYearDataLength] = useState(
myPlansData[0].getPlanList.length,
export default function MyPlan({ myPlans }: { myPlans: GetMyPlansResponse }) {
const { PERIOD_OPTIONS, setYear, year, yearData, yearDataLength } = useMyPlan(
{ myPlans },
);

const PERIOD_OPTIONS = yearList.map((x) => {
return { value: x, name: `${x}년 계획` };
});

useEffect(() => {
const chosenYearData = myPlansData.find((x) => x.year === year)!;
setYearData(chosenYearData);
setYearDataLength(chosenYearData.getPlanList.length);
setCanMakeNewPlan(!!(maxPlan - chosenYearData.getPlanList.length));
}, [year, myPlansData, setYearDataLength, setCanMakeNewPlan]);
return (
<>
<div className={classNames('home__header')}>
Expand Down
6 changes: 2 additions & 4 deletions src/app/(header)/home/_components/NewPlan/NewPlan.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Icon } from '@/components';
import { canMakeNewPlanStore } from '@/stores/canMakeNewPlanStore';
import { checkIsSeason } from '@/utils/checkIsSeason';
import classNames from 'classnames';
import Link from 'next/link';
import { useRecoilState } from 'recoil';
import { useNewPlan } from '../hooks';
import './index.scss';

export default function NewPlan() {
const [canMakeNewPlan] = useRecoilState(canMakeNewPlanStore);

const { canMakeNewPlan } = useNewPlan();
return (
<>
<div className={classNames('new-plan__servey')}>
Expand Down
Loading

0 comments on commit 86de908

Please sign in to comment.