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]audio url을 클릭 시에만 생성하도록 변경 #121

Merged
merged 6 commits into from
Feb 11, 2025
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ next-env.d.ts
.env.production.local
.env.local

# workbox 캐싱 파일 무시
/public/workbox-*

# 서비스 워커 소스맵 무시
/public/sw.js.map

3 changes: 0 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# push하기 전에 빌드 실행
npm run build
if [ $? -eq 0 ]; then
Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const withPWA = nextPWA({

const nextConfig = {
reactStrictMode: true,
productionBrowserSourceMaps: false,
output: 'standalone',
images: {
remotePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion public/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/sw.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions public/workbox-e43f5367.js → public/workbox-bd7e3b9b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions src/components/common/TTSPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import useDeviceType from '@/hooks/useDeviceType';
import clsx from 'clsx';
import SpeakerSvg from '../svg-component/SpeakerSvg';
import useAudioPlayer from '@/hooks/useAudioPlayer';
import useGetTTSUrl from '@/hooks/query/useGetTTSUrl';
import { getTTSUrl } from '@/fetcher';
import { useQueryClient } from '@tanstack/react-query';
import QUERY_KEYS from '@/constants/queryKey';

type Props = {
id: string;
Expand All @@ -13,14 +15,27 @@ type Props = {

export default function TTSPlayer({ diacritic, id }: Props) {
const deviceType = useDeviceType();
const { data: audioUrl } = useGetTTSUrl(id);
const queryClient = useQueryClient();
const { audioRef, startAudio, isPlaying } = useAudioPlayer(id);

const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
const handleClick = async (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();

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

Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/quiz/QuizResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function QuizResult({
const router = useRouter();
const { data } = useAuthQuery();
const [isOpenModal, setIsOpenModal] = useState(false);
const isLoggedIn = !data?.error ?? false;
const isLoggedIn = data?.error ?? false;
const isGuest = quizResultId === 'guest';
const isScrolled = useScroll();
const [isOpen, setIsOpen] = useState(
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/quiz/QuizResultDetailWord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function QuizResultDetailWord({ data, correctWords }: Props) {

const { data: authData } = useAuthQuery();
const [isOpenModal, setIsOpenModal] = useState(false);
const isLoggedIn = !authData?.error ?? false;
const isLoggedIn = authData?.error ?? false;
const { optimisticLikeState, handleSubLike, handleAddLike } =
useOptimisticLike({
wordId: data.wordId,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/query/useGetTTSUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const useGetTTSUrl = (id: string) => {
return useQuery({
queryKey: [QUERY_KEYS.TTS_KEY, id],
queryFn: () => getTTSUrl(id),
gcTime: Infinity,
staleTime: Infinity,
});
};

Expand Down
Loading