Skip to content

Commit

Permalink
[feat/#467] ✨ feat: 페이지 별로 브금 다르게 세팅, 브금 반복
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbae94 committed May 16, 2024
1 parent fe37b95 commit 80ec0c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions chatty-fe/src/app/(game)/create-room/page.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const contentsContainer = style({
gap: 10,
backgroundColor: globals.color.blue_6,
borderRadius: 20,
boxShadow: '0 0 10px rgba(0, 0, 0, 0.2)',
});

export const contentsWrapper = style({
Expand Down
8 changes: 7 additions & 1 deletion chatty-fe/src/app/_components/BgmComponent/BgmComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use client';
import useBgm from '@/app/_hooks/useBgm';
import useBgmStore from '@/app/_store/useBgmStore';
import React, { useEffect, useRef } from 'react';

export default function BgmComponent() {
const { bgm, isPlaying } = useBgmStore();
const { checkUrlAndChangeBgm, url } = useBgm();
const audioElement = useRef<HTMLAudioElement>(null);

useEffect(() => {
Expand All @@ -14,5 +16,9 @@ export default function BgmComponent() {
}
}, [isPlaying]);

return <audio src={bgm} autoPlay ref={audioElement} />;
useEffect(() => {
checkUrlAndChangeBgm();
}, [url]);

return <audio src={bgm} autoPlay loop ref={audioElement} />;
}
20 changes: 20 additions & 0 deletions chatty-fe/src/app/_hooks/useBgm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { usePathname } from 'next/navigation';
import useBgmStore from '../_store/useBgmStore';

const useBgm = () => {
const { setBgm } = useBgmStore();
const url = usePathname();
const quizUrl = ['/quiz-room'];
const mainBgm = '/bgm/main.mp3';
const quizBgm = '/bgm/quiz.mp3';
const checkUrlAndChangeBgm = () => {
if (quizUrl.includes(url)) {
setBgm(quizBgm);
} else {
setBgm(mainBgm);
}
};
return { checkUrlAndChangeBgm, url };
};

export default useBgm;

0 comments on commit 80ec0c5

Please sign in to comment.