Skip to content

Commit be422b3

Browse files
authored
[fix]audio url을 클릭 시에만 생성하도록 변경
[fix]audio url을 클릭 시에만 생성하도록 변경
2 parents cca0b82 + 59cef70 commit be422b3

12 files changed

+5139
-17
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ next-env.d.ts
4848
.env.production.local
4949
.env.local
5050

51+
# workbox 캐싱 파일 무시
52+
/public/workbox-*
53+
54+
# 서비스 워커 소스맵 무시
55+
/public/sw.js.map
56+

.husky/pre-push

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
# push하기 전에 빌드 실행
52
npm run build
63
if [ $? -eq 0 ]; then

next.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const withPWA = nextPWA({
77

88
const nextConfig = {
99
reactStrictMode: true,
10+
productionBrowserSourceMaps: false,
1011
output: 'standalone',
1112
images: {
1213
remotePatterns: [

public/sw.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sw.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/workbox-e43f5367.js public/workbox-bd7e3b9b.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/workbox-e43f5367.js.map public/workbox-bd7e3b9b.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/common/TTSPlayer.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import useDeviceType from '@/hooks/useDeviceType';
44
import clsx from 'clsx';
55
import SpeakerSvg from '../svg-component/SpeakerSvg';
66
import useAudioPlayer from '@/hooks/useAudioPlayer';
7-
import useGetTTSUrl from '@/hooks/query/useGetTTSUrl';
7+
import { getTTSUrl } from '@/fetcher';
8+
import { useQueryClient } from '@tanstack/react-query';
9+
import QUERY_KEYS from '@/constants/queryKey';
810

911
type Props = {
1012
id: string;
@@ -13,14 +15,27 @@ type Props = {
1315

1416
export default function TTSPlayer({ diacritic, id }: Props) {
1517
const deviceType = useDeviceType();
16-
const { data: audioUrl } = useGetTTSUrl(id);
18+
const queryClient = useQueryClient();
1719
const { audioRef, startAudio, isPlaying } = useAudioPlayer(id);
1820

19-
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
21+
const handleClick = async (e: React.MouseEvent<HTMLDivElement>) => {
2022
e.stopPropagation();
2123

22-
if (audioUrl) {
23-
startAudio(audioUrl);
24+
try {
25+
// Fixme: 타입 추론되도록 만들고 싶어요
26+
const audioUrl = await queryClient.fetchQuery({
27+
queryKey: [QUERY_KEYS.TTS_KEY, id],
28+
queryFn: () => getTTSUrl(id),
29+
gcTime: Infinity,
30+
staleTime: Infinity,
31+
});
32+
if (audioUrl) {
33+
startAudio(audioUrl);
34+
}
35+
} catch {
36+
// Note: 오디오 에러는 서비스에 큰 지장을 주지 않기 때문에 에러 전파 X
37+
// Todo: 추후 여러번 발생할 때 리포팅 할 수 있는 Sentry를 연동하면 좋겠다.
38+
console.error('오디오 url 생성 중 에러');
2439
}
2540
};
2641

src/components/pages/quiz/QuizResult.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function QuizResult({
3636
const router = useRouter();
3737
const { data } = useAuthQuery();
3838
const [isOpenModal, setIsOpenModal] = useState(false);
39-
const isLoggedIn = !data?.error ?? false;
39+
const isLoggedIn = data?.error ?? false;
4040
const isGuest = quizResultId === 'guest';
4141
const isScrolled = useScroll();
4242
const [isOpen, setIsOpen] = useState(

src/components/pages/quiz/QuizResultDetailWord.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function QuizResultDetailWord({ data, correctWords }: Props) {
1919

2020
const { data: authData } = useAuthQuery();
2121
const [isOpenModal, setIsOpenModal] = useState(false);
22-
const isLoggedIn = !authData?.error ?? false;
22+
const isLoggedIn = authData?.error ?? false;
2323
const { optimisticLikeState, handleSubLike, handleAddLike } =
2424
useOptimisticLike({
2525
wordId: data.wordId,

src/hooks/query/useGetTTSUrl.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const useGetTTSUrl = (id: string) => {
66
return useQuery({
77
queryKey: [QUERY_KEYS.TTS_KEY, id],
88
queryFn: () => getTTSUrl(id),
9+
gcTime: Infinity,
10+
staleTime: Infinity,
911
});
1012
};
1113

0 commit comments

Comments
 (0)