Skip to content

Commit cd6d6d1

Browse files
committed
feat: 후원사 컨텍스트 추가 및 App 컴포넌트에 통합
1 parent 2865231 commit cd6d6d1

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

apps/pyconkr/src/App.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import * as Common from "@frontend/common";
22
import React from "react";
33
import { BrowserRouter, Route, Routes } from "react-router-dom";
4+
import { SponsorProvider } from "./contexts/SponsorContext";
45

56
import MainLayout from "./components/layout";
67
import { Test } from "./components/pages/test";
78
import { IS_DEBUG_ENV } from "./consts/index.ts";
89

910
export const App: React.FC = () => {
1011
return (
11-
<BrowserRouter>
12-
<Routes>
13-
<Route element={<MainLayout />}>
14-
{IS_DEBUG_ENV && <Route path="/debug" element={<Test />} />}
15-
<Route path="/pages/:id" element={<Common.Components.PageIdParamRenderer />} />
16-
<Route path="*" element={<Common.Components.RouteRenderer />} />
17-
</Route>
18-
</Routes>
19-
</BrowserRouter>
12+
<SponsorProvider>
13+
<BrowserRouter>
14+
<Routes>
15+
<Route element={<MainLayout />}>
16+
{IS_DEBUG_ENV && <Route path="/debug" element={<Test />} />}
17+
<Route
18+
path="/pages/:id"
19+
element={<Common.Components.PageIdParamRenderer />}
20+
/>
21+
<Route path="*" element={<Common.Components.RouteRenderer />} />
22+
</Route>
23+
</Routes>
24+
</BrowserRouter>
25+
</SponsorProvider>
2026
);
2127
};

apps/pyconkr/src/components/layout/Sponsor/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styled from "@emotion/styled";
22
import { useEffect, useState } from "react";
33
import SponsorExample from "../../../assets/sponsorExample.svg?react";
4+
import { useSponsor } from "../../../contexts/SponsorContext";
45

56
interface Sponsor {
67
id: number;
@@ -10,6 +11,7 @@ interface Sponsor {
1011

1112
export default function Sponsor() {
1213
const [sponsors, setSponsors] = useState<Sponsor[]>([]);
14+
const { isVisible } = useSponsor();
1315

1416
// 16개의 임시 스폰서 데이터 생성
1517
useEffect(() => {
@@ -28,6 +30,8 @@ export default function Sponsor() {
2830
fetchSponsors();
2931
}, []);
3032

33+
if (!isVisible) return null;
34+
3135
return (
3236
<SponsorContainer>
3337
<SponsorTitle>후원사 목록</SponsorTitle>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { createContext, useContext, useState, ReactNode } from "react";
2+
3+
interface SponsorContextType {
4+
isVisible: boolean;
5+
toggleVisibility: () => void;
6+
}
7+
8+
const SponsorContext = createContext<SponsorContextType | undefined>(undefined);
9+
10+
export function SponsorProvider({ children }: { children: ReactNode }) {
11+
const [isVisible, setIsVisible] = useState(true);
12+
13+
const toggleVisibility = () => {
14+
setIsVisible((prev) => !prev);
15+
};
16+
17+
return (
18+
<SponsorContext.Provider value={{ isVisible, toggleVisibility }}>
19+
{children}
20+
</SponsorContext.Provider>
21+
);
22+
}
23+
24+
export function useSponsor() {
25+
const context = useContext(SponsorContext);
26+
if (context === undefined) {
27+
throw new Error("useSponsor must be used within a SponsorProvider");
28+
}
29+
return context;
30+
}

0 commit comments

Comments
 (0)