Skip to content

Commit

Permalink
(#82) πŸš€ feat: useStadiumSelector ν›…κ³Ό λ©”μΈν™ˆ μ»΄ν¬λ„ŒνŠΈμ— μŠ€νƒ€λ””μ›€ μ „μ—­ μƒνƒœ 동기화 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
inaemon committed Nov 29, 2024
1 parent 2a0e47a commit 5ce60cc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/context/StadiumContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StadiumType } from "@/src/constants/ZoneData";

// 1. Context νƒ€μž… μ •μ˜
interface StadiumContextType {
selectedStadium: StadiumType | null;
selectedStadium: StadiumType;
setSelectedStadium: (stadium: StadiumType) => void;
}

Expand All @@ -12,8 +12,8 @@ const StadiumContext = createContext<StadiumContextType | undefined>(undefined);

// 3. Context Provider μ»΄ν¬λ„ŒνŠΈ
export const StadiumProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [selectedStadium, setSelectedStadium] = useState<StadiumType | null>(null);

const [selectedStadium, setSelectedStadium] = useState<StadiumType>(StadiumType.JAMSIL); // μ΄ˆκΈ°κ°’: μž μ‹€
return (
<StadiumContext.Provider value={{ selectedStadium, setSelectedStadium }}>
{children}
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useStadiumSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { StadiumType } from "@/src/constants/ZoneData";
import { ZoneGetParamsType, ZoneGetResponseType } from "@/src/api/StadiumApiType"; // νƒ€μž…λ“€ import
import { handleGetStadiumInfo } from "@/src/api/StadiumApiHandler"; // API 호좜 ν•¨μˆ˜

import { useStadiumContext } from "@/src/context/StadiumContext";

export const useStadiumSelector = () => {
const [selectedStadium, setSelectedStadium] = useState<StadiumType>(StadiumType.JAMSIL); // 첫 화면은 μž μ‹€λ‘œ μ΄ˆκΈ°ν™”
const { selectedStadium, setSelectedStadium } = useStadiumContext();
const [selectedSection, setSelectedSection] = useState<string>("");
const [selectedSectionColor, setSelectedSectionColor] = useState<string>("");

Expand Down
4 changes: 1 addition & 3 deletions src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const Main = () => {
const [isPopupOpen, setIsPopupOpen] = useState(false); // μ€€λΉ„ 쀑 νŒμ—… μƒνƒœ

// λ©”μΈν™ˆ μŠ€νƒ€λ””μ›€ 관리
const {
selectedStadium, setSelectedStadium
} = useStadiumSelector();
const { selectedStadium, setSelectedStadium } = useStadiumSelector();

const handleStadiumSelect = (stadium: StadiumType) => {
// 선택 κ°€λŠ₯ν•œ ꡬμž₯인지 확인
Expand Down
80 changes: 38 additions & 42 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import Script from 'next/script';
// μ „μ—­ μ†Œμ…œλ‘œκ·ΈμΈ μƒνƒœ 관리
import { SessionProvider } from "next-auth/react";

// Enum으둜 μΆ”μ²œ ꡬ역 Data 관리
import { StadiumType, SeatType, Keyword } from "../constants/ZoneData"
// μŠ€νƒ€λ””μ›€ κ°’ μ „μ—­ μƒνƒœ 관리
import { StadiumProvider } from "@/src/context/StadiumContext"; // μž‘μ„±ν•œ Context 경둜

import { ZoneGetResponseType } from "../api/ResultApiType";

Expand All @@ -57,12 +57,6 @@ export const metadata = {
};

const MyApp: React.FC<AppProps> = ({ Component, pageProps: { session, ...pageProps } }) => {
// λ©”μΈν™ˆ μŠ€νƒ€λ””μ›€ 관리
const {
selectedStadium: selectedMainStadium,
setSelectedStadium: setSelectedMainStadium
} = useStadiumSelector();

// λ°±μ—”λ“œμ— μΆ”μ²œ 질문 데이터 전솑 ν›„ λ°˜ν™˜λ°›μ€ resultId κ°’ μ €μž₯ν•˜λŠ” λ³€μˆ˜/ν•¨μˆ˜
const [resultId, setResultId] = useState<number | null>(null); //useState(0); // 0 λ˜λŠ” -1둜 μ΄ˆκΈ°ν™”'

Expand Down Expand Up @@ -94,9 +88,9 @@ const MyApp: React.FC<AppProps> = ({ Component, pageProps: { session, ...pagePro
case '/':
return <HomePage />;
case '/recommend/question':
return <Question /*stadium={selectedMainStadium}*/ setResultId={setResultId} recommendedZoneList={recommendedZoneList} setRecommendedZoneList={setRecommendedZoneList}/>;
return <Question setResultId={setResultId} recommendedZoneList={recommendedZoneList} setRecommendedZoneList={setRecommendedZoneList}/>;
case '/recommend/results':
return <Result /*stadium={selectedMainStadium}*/ resultId={resultId} setResultId={setResultId} />;
return <Result resultId={resultId} setResultId={setResultId} />;
case '/guide':
return <Guide/>
case '/guide/zone':
Expand All @@ -114,40 +108,42 @@ const MyApp: React.FC<AppProps> = ({ Component, pageProps: { session, ...pagePro

return (
<>
<Head>
<title>HitZone</title>
<meta name="description" content="νμ‹œμ¦˜ 30th λ°‹μ—… AνŒ€ 히트쑴" />
{/* κΈ°λ³Έ Favicon */}
<link rel="icon" href="/favicon.ico" />

{/* Web App Manifest */}
<link rel="manifest" href="/manifest.json" />

{/* iOS μ „μš© ν™ˆ ν™”λ©΄ μ•„μ΄μ½˜ */}
<link rel="apple-touch-icon" sizes="192x192" href="/android-icon-192x192.png" />

{/* 메타 데이터 */}
<meta name="theme-color" content="#ffffff" />
<meta name="description" content="A Progressive Web App" />

{/* Microsoft Clarity 슀크립트 */}
<Script
id="ms-clarity"
strategy="afterInteractive" // μŠ€ν¬λ¦½νŠΈκ°€ μ‚¬μš©μž μΈν„°λž™μ…˜ ν›„ λ‘œλ“œλ˜λ„λ‘ μ„€μ •
dangerouslySetInnerHTML={{
__html: `(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "p2zzif1xu0");`,
}}
/>
</Head>
<Head>
<title>HitZone</title>
<meta name="description" content="νμ‹œμ¦˜ 30th λ°‹μ—… AνŒ€ 히트쑴" />
{/* κΈ°λ³Έ Favicon */}
<link rel="icon" href="/favicon.ico" />

{/* Web App Manifest */}
<link rel="manifest" href="/manifest.json" />

{/* iOS μ „μš© ν™ˆ ν™”λ©΄ μ•„μ΄μ½˜ */}
<link rel="apple-touch-icon" sizes="192x192" href="/android-icon-192x192.png" />

{/* 메타 데이터 */}
<meta name="theme-color" content="#ffffff" />
<meta name="description" content="A Progressive Web App" />
{/* Microsoft Clarity 슀크립트 */}
<Script
id="ms-clarity"
strategy="afterInteractive" // μŠ€ν¬λ¦½νŠΈκ°€ μ‚¬μš©μž μΈν„°λž™μ…˜ ν›„ λ‘œλ“œλ˜λ„λ‘ μ„€μ •
dangerouslySetInnerHTML={{
__html: `(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "p2zzif1xu0");`,
}}
/>
</Head>

{/*<SessionProvider session={session}>*/}
<div className="flex flex-col h-screen max-w-[500px] mx-auto overflow-hidden">
{renderComponent()}
</div>
<StadiumProvider>
<div className="flex flex-col h-screen max-w-[500px] mx-auto overflow-hidden">
{renderComponent()}
</div>
</StadiumProvider>
{/*</SessionProvider> */}

<script src="https://developers.kakao.com/sdk/js/kakao.min.js" async></script>
Expand Down

0 comments on commit 5ce60cc

Please sign in to comment.