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

REV-399/활성화된 탭 페이지 이동 시에도 고정 #107

Merged
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: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { RouterProvider } from 'react-router-dom'
import { ThemeProvider, ToastProvider } from './components'
import { TabsProvider, ThemeProvider, ToastProvider } from './components'
import { router } from './routes'

const queryClient = new QueryClient({
Expand All @@ -31,7 +31,9 @@ function App() {
<ToastProvider>
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<RouterProvider router={router} />
<TabsProvider>
<RouterProvider router={router} />
</TabsProvider>
</ThemeProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
Expand Down
15 changes: 15 additions & 0 deletions src/components/TabsProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PropsWithChildren, useState } from 'react'
import { TabsContext } from '@/contexts'
import { Tabs } from '@/types'

const TabsProvider = ({ children }: PropsWithChildren) => {
const [activeTab, setActiveTab] = useState<Tabs>('invited')

return (
<TabsContext.Provider value={{ activeTab, setActiveTab }}>
{children}
</TabsContext.Provider>
)
}

export default TabsProvider
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { default as SearchBar } from './SearchBar'
export { default as Input } from './Input'
export { default as Header } from './Header'
export { default as ThemeProvider } from './ThemeProvider'
export { default as TabsProvider } from './TabsProvider'
export { default as Dropdown } from './Dropdown'
export { default as Modal } from './Modal'
export { default as ReviewInfo } from './ReviewInfo'
Expand Down
14 changes: 14 additions & 0 deletions src/contexts/TabsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Dispatch, SetStateAction, createContext } from 'react'
import { Tabs } from '@/types'

interface TabsContextType {
activeTab: Tabs
setActiveTab: Dispatch<SetStateAction<Tabs>>
}

const TabsContext = createContext<TabsContextType>({
activeTab: 'invited',
setActiveTab: () => {},
})

export default TabsContext
1 change: 1 addition & 0 deletions src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as ThemeContext } from './ThemeContext'
export { default as ToastContext } from './ToastContext'
export { default as TabsContext } from './TabsContext'
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as useToast } from './useToast'
export { default as useInfiniteScroll } from './useInfiniteScroll'
export { default as useRefine } from './useRefine'
export { default as useCheckHeaderRoute } from './useCheckHeaderRoute'
export { default as useTabs } from './useTabs'
8 changes: 8 additions & 0 deletions src/hooks/useTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useContext } from 'react'
import { TabsContext } from '@/contexts'

const useTabs = () => {
return useContext(TabsContext)
}

export default useTabs
8 changes: 3 additions & 5 deletions src/pages/MainPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Suspense, useState } from 'react'
import { Suspense } from 'react'
import { useNavigate } from 'react-router-dom'
import { useToast } from '@/hooks'
import { useTabs, useToast } from '@/hooks'
import { Header, TokenErrorBoundary } from '@/components'
import { useDeleteReview } from '@/apis/hooks'
import { rangerIdle } from '@/assets/images'
Expand All @@ -20,9 +20,7 @@ const MainPage = () => {

const navigate = useNavigate()

const [activeTab, setActiveTab] = useState<
'invited' | 'created' | 'received'
>('invited')
const { activeTab, setActiveTab } = useTabs()

const { addToast } = useToast()

Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './reviews'
export * from './reviewDetailed'
export * from './tabs'
1 change: 1 addition & 0 deletions src/types/tabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Tabs = 'invited' | 'created' | 'received'
Loading