Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Issue 해결 #52

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@suspensive/react": "^1.13.0",
"@suspensive/react-query": "^1.13.0",
"@tanstack/react-query": "^4.32.6",
"@tanstack/react-query-devtools": "^4.35.0",
"@types/node": "20.4.5",
"@types/react": "18.2.17",
"@types/react-dom": "18.2.7",
Expand Down
14 changes: 5 additions & 9 deletions src/apis/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ export const usePoseFeedQuery = (
) =>
useSuspenseInfiniteQuery<PoseFeedResponse>(
['poseFeed', peopleCount, frameCount, tags],
({ pageParam = '' }) => getPoseFeed(peopleCount, frameCount, tags.join(','), pageParam),
({ pageParam = 0 }) => getPoseFeed(peopleCount, frameCount, tags.join(','), pageParam),
{
getNextPageParam: (lastPage) => {
let target = lastPage.filteredContents;
if (lastPage.recommendation) {
target = lastPage.recommendedContents;
} else {
target = lastPage.filteredContents;
}
if (target.last) return false;
return target.number + 1;
const target = lastPage.recommendation
? lastPage.recommendedContents
: lastPage.filteredContents;
return target.last ? undefined : target.number + 1;
Comment on lines +42 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔하네유 ㅎㅎ 감삼다

},
...options,
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(Main)/feed/components/Photo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Image from 'next/image';
import Link from 'next/link';

import { Modal, PreparingModal } from '@/components/Modal';
import { PreparingModal } from '@/components/Modal';
import { useOverlay } from '@/components/Overlay/useOverlay';
import { ICON } from '@/constants/icon';

Expand Down
21 changes: 9 additions & 12 deletions src/app/(Main)/feed/components/PhotoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ interface PhotoList {
}

export default function PhotoList({ data }: PhotoList) {
if (!data) return <Photo />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터 없을때 스켈레톤 ? 이미지 나오게 하면 좋을 것 같네요 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그것도 좋을 것 같네요 -!

return (
<>
{data ? (
data.map((item) => (
<Photo
key={item.poseInfo.poseId}
imageKey={item.poseInfo.imageKey}
source={item.poseInfo.source}
id={item.poseInfo.poseId}
/>
))
) : (
<Photo />
)}
{data.map((item) => (
<Photo
key={item.poseInfo.poseId}
imageKey={item.poseInfo.imageKey}
source={item.poseInfo.source}
id={item.poseInfo.poseId}
/>
))}
</>
);
}
23 changes: 18 additions & 5 deletions src/app/(Main)/talk/components/TalkSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
import Lottie from 'react-lottie-player';

import lottieTalkAfterClick from '#/lotties/talk_after_click.json';
Expand All @@ -11,26 +12,38 @@ import { Spacing } from '@/components/Spacing';
import useLoading from '@/hooks/useLoading';

export default function TalkSection() {
const [talkWord, setTalkWord] = useState<string>(`제시어에 맞춰 포즈를 취해요!`);
const { isLoading: isFirstLoading, stopLoading: stopFirstLoading } = useLoading({
loadingDelay: 1000,
isFirstLoadingInfinite: true,
});

const { refetch, data } = usePoseTalkQuery();
const { refetch, data } = usePoseTalkQuery({
onSuccess: (data) => {
setTimeout(() => {
setTalkWord(data.poseWord.content);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드가 아닌 기획관련 의견이긴 한데 , 1초동안 로딩하고나서 키워드 보여주고 이미지 재생하는 대신 키워드 보여주고 나서 1초동안 이미지 재생하는건 어떨까요 ?.? 키워드가 빨리 나오는게 좋을 것 같아서용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요 이 부분 저도 무언가 어색하다랄까 .. 아쉽다는 느낌받긴했어요

회의 때 이 부분 이야기해봐도 좋을 것 같아요 ~

}, 1000);
},
});

const { isLoading, startLoading } = useLoading({
loadingDelay: 1000,
onStopLoading: () => data && setTalkWord(data.poseWord.content),
initialState: false,
});
const [talkWord, setTalkWord] = useState<string>(`제시어에 맞춰 포즈를 취해요!`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 다른페이지 갔다왔을때 기본 키워드로 돌아가는거 고쳐진건가요?! 제가 코드만 보고 원리를 모르겠어서 여쭤봅니답ㅠㅜ

Copy link
Collaborator Author

@guesung guesung Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 useEffect(() => {
    return () => {
      queryClient.resetQueries(['poseTalk']);
    };
  }, [queryClient]);

이 부분에서 useEffect의 return문에 캐싱된 쿼리를 초기화 하도록 설정하였습니다.
useEffect의 함수는 컴포넌트가 마운트되었을 때인데, return문 안의 함수이므로 unmount되었을 때 실행이됩니다.
기존에는 페이지 이동시 쿼리된 데이터가 inActive상태가 되었지만, 이제는 페이지 이동 시 캐싱된 데이터를 버리게 됩니다.

우선 임시로 이 방식으로 구현은 했는데, 무언가 더 효율적인 코드가 있을 거라는 생각이 들어요 ..
추후 좀 더 알아보고 다른 좋은 방법이 있으면 교체해도 될 것 같아요 !


const handleTalkClick = () => {
if (isFirstLoading) stopFirstLoading();
startLoading();
refetch();
};

const queryClient = useQueryClient();

useEffect(() => {
return () => {
queryClient.resetQueries(['poseTalk']);
};
}, [queryClient]);

return (
<section className="flex flex-col items-center">
<h1 className="max-w-310 break-keep text-center">{talkWord}</h1>
Expand Down
5 changes: 3 additions & 2 deletions src/app/(Main)/talk/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Metadata } from 'next';

import TalkSection from './components/TalkSection';
import TitleSection from './components/TitleSection';
import { PageAnimation } from '@/components/PageAnimation';
import { Spacing } from '@/components/Spacing';

export const metadata: Metadata = {
Expand All @@ -11,10 +12,10 @@ export const metadata: Metadata = {
export default function Talk() {
return (
<>
<div className="flex flex-1 flex-col items-center justify-center">
<PageAnimation className="flex flex-1 flex-col items-center justify-center">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageanimation은 어떤 애니메이션인가요?.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pageanimation은 framer-motion을 활용하여 애니메이션을 구현한 컴포넌트로, 컴포넌트가 마운트됬을 때 opacity 0부터 1까지 자연스럽게 변화합니다.

<TitleSection />
<TalkSection />
</div>
</PageAnimation>
<Spacing size={80} />
</>
);
Expand Down
1 change: 0 additions & 1 deletion src/app/(Sub)/menu/components/MakerSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';
import Image from 'next/image';
import Link from 'next/link';

import BottomFixedDiv from '@/components/BottomFixedDiv';
import { Spacing } from '@/components/Spacing';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Header({
...props
}: HeaderProps) {
return (
<div className="z-10 fixed inset-x-0 top-0 mx-auto max-w-440 bg-white pt-8">
<div className="fixed inset-x-0 top-0 z-10 mx-auto max-w-440 bg-white pt-8">
<header
className={`flex h-48 items-center justify-between ${className ? className : ''}`}
{...props}
Expand Down
3 changes: 2 additions & 1 deletion src/components/PageAnimation/PageAnimation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client';
import cn from '@/utils/cn';
import { type AnimationProps, motion } from 'framer-motion';

import cn from '@/utils/cn';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cn도 궁금해요-!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cn은 기존 tailwindcss를 사용했을 때의 단점을 극복한 util함수입니다.

기존 tailwindcss를 사용하면 clssName = text-a text-b

로 작성할 경우, 두 속성 중 한 속성이 사라지지 않고 스타일에 그대로 나타나는 이슈가 있었습니다. (중복으로 적용되지는 않지만 어떤 것이 적용될 지는 미지수)

그래서 twMerge 라이브러리를 도입하였지만, 이 라이브러리에서는 커스텀 css속성을 사용할 경우 적용이 정상적으로 동작하지 않는 이슈가 있습니다.

저희 프로젝트에서는 커스텀 css속성이 아니라, h1/h2 등 태그로 typography를 적용하기에 cn까지는 필요 없고, twMerge를 사용해도 될 것 같긴 하네용


import type { StrictPropsWithChildren } from '@/types';

interface PageAnimationProps extends AnimationProps {
Expand Down
7 changes: 1 addition & 6 deletions src/hooks/useLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@ import useIsMounted from './useIsMounted';
interface UseLoadingProps {
initialState?: boolean;
loadingDelay?: number;
onStopLoading?: () => void;
isFirstLoadingInfinite?: boolean;
}
export default function useLoading({
initialState = true,
loadingDelay,
onStopLoading,
isFirstLoadingInfinite = false,
}: UseLoadingProps = {}) {
const [isLoading, setIsLoading] = useState(initialState);
const isMounted = useIsMounted();

const stopLoading = useCallback(() => {
setIsLoading(false);
if (onStopLoading) {
onStopLoading();
}
}, [onStopLoading]);
}, []);

const startLoading = useCallback(() => {
setIsLoading(true);
Expand Down
8 changes: 7 additions & 1 deletion src/provider/QueryProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { useState } from 'react';

import type { StrictPropsWithChildren } from '@/types';
Expand All @@ -16,5 +17,10 @@ export default function QueryProvider({ children }: StrictPropsWithChildren) {
},
});

return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
return (
<QueryClientProvider client={queryClient}>
{children}
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
}
40 changes: 40 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1365,11 +1365,27 @@
dependencies:
tslib "^2.4.0"

"@tanstack/match-sorter-utils@^8.7.0":
version "8.8.4"
resolved "https://registry.yarnpkg.com/@tanstack/match-sorter-utils/-/match-sorter-utils-8.8.4.tgz#0b2864d8b7bac06a9f84cb903d405852cc40a457"
integrity sha512-rKH8LjZiszWEvmi01NR72QWZ8m4xmXre0OOwlRGnjU01Eqz/QnN+cqpty2PJ0efHblq09+KilvyR7lsbzmXVEw==
dependencies:
remove-accents "0.4.2"

"@tanstack/query-core@4.32.6":
version "4.32.6"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-4.32.6.tgz#cf7df91ab1542e67a82624fefb12a55f580b4c01"
integrity sha512-YVB+mVWENQwPyv+40qO7flMgKZ0uI41Ph7qXC2Zf1ft5AIGfnXnMZyifB2ghhZ27u+5wm5mlzO4Y6lwwadzxCA==

"@tanstack/react-query-devtools@^4.35.0":
version "4.35.0"
resolved "https://registry.yarnpkg.com/@tanstack/react-query-devtools/-/react-query-devtools-4.35.0.tgz#5c28920f238c01033cb374e4664cd5f0fbccb113"
integrity sha512-tzN0K70idRsqnfLdUcQC3eCrv28kLIAB6/H1zsGdIw7Wmj5VgTxPmpEVc3rHQjKt0LZsvZTLmaLnI6FCI3VUZw==
dependencies:
"@tanstack/match-sorter-utils" "^8.7.0"
superjson "^1.10.0"
use-sync-external-store "^1.2.0"

"@tanstack/react-query@^4.32.6":
version "4.32.6"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-4.32.6.tgz#f88c2d57f423d4cd295c501df2edeb3285a301bd"
Expand Down Expand Up @@ -2090,6 +2106,13 @@ convert-source-map@^1.5.0, convert-source-map@^1.7.0:
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.9.0.tgz#7faae62353fb4213366d0ca98358d22e8368b05f"
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==

copy-anything@^3.0.2:
version "3.0.5"
resolved "https://registry.yarnpkg.com/copy-anything/-/copy-anything-3.0.5.tgz#2d92dce8c498f790fa7ad16b01a1ae5a45b020a0"
integrity sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==
dependencies:
is-what "^4.1.8"

core-js-compat@^3.31.0:
version "3.32.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.32.1.tgz#55f9a7d297c0761a8eb1d31b593e0f5b6ffae964"
Expand Down Expand Up @@ -3275,6 +3298,11 @@ is-weakref@^1.0.2:
dependencies:
call-bind "^1.0.2"

is-what@^4.1.8:
version "4.1.15"
resolved "https://registry.yarnpkg.com/is-what/-/is-what-4.1.15.tgz#de43a81090417a425942d67b1ae86e7fae2eee0e"
integrity sha512-uKua1wfy3Yt+YqsD6mTUEa2zSi3G1oPlqTflgaPJ7z63vUGN5pxFpnQfeSLMFnJDEsdvOtkp1rUWkYjB4YfhgA==

is-wsl@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
Expand Down Expand Up @@ -4171,6 +4199,11 @@ regjsparser@^0.9.1:
dependencies:
jsesc "~0.5.0"

remove-accents@0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/remove-accents/-/remove-accents-0.4.2.tgz#0a43d3aaae1e80db919e07ae254b285d9e1c7bb5"
integrity sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==

require-from-string@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
Expand Down Expand Up @@ -4540,6 +4573,13 @@ sucrase@^3.32.0:
pirates "^4.0.1"
ts-interface-checker "^0.1.9"

superjson@^1.10.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/superjson/-/superjson-1.13.1.tgz#a0b6ab5d22876f6207fcb9d08b0cb2acad8ee5cd"
integrity sha512-AVH2eknm9DEd3qvxM4Sq+LTCkSXE2ssfh1t11MHMXyYXFQyQ1HLgVvV+guLTsaQnJU3gnaVo34TohHPulY/wLg==
dependencies:
copy-anything "^3.0.2"

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down