generated from yandex-praktikum/client-server-template-with-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* добавил ssr в дев и прод режимы * сборка клиента для корректного линтинга проекта * добавил команду build:ssr * обработка стора на SSR * добавил доступ к стору в лоадерах роутов * сервер порт 3001 -> 5000 для совместимости с oauth * добавил комплицию типов пакета client * client-only перевод в jsx * мелкие правки * добавил rimraf для кроссплатформенности * замена `querySelector` * подготовка к мерджу * экспорт тип leaderboard стейта, исправление в условии SSR
- Loading branch information
Showing
45 changed files
with
920 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_API_BASE_URL=http://localhost:5000/api/v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,29 @@ | ||
import { AuthLayout, getCurrentUser } from 'components/auth-layout'; | ||
import { | ||
Route, | ||
defer, | ||
createBrowserRouter, | ||
createRoutesFromElements, | ||
RouterProvider, | ||
} from 'react-router-dom'; | ||
import { ProtectedRoutes } from 'utils/protected-routes'; | ||
import { Profile } from 'pages/profile'; | ||
import { MainPage } from 'pages/main'; | ||
import { GamePage } from 'pages/game'; | ||
import { RouterPaths } from './app.types'; | ||
import { LoginPage, RegisterPage } from 'pages/auth'; | ||
import { MainLayout } from 'components/main-layout'; | ||
import { Error404, Error500 } from 'pages/error'; | ||
import { Leaderboard } from 'pages/leaderboard'; | ||
import { ForumThread } from 'pages/forum-thread'; | ||
import { NewThreadModal } from 'components/modal-new-thread'; | ||
import { Forum } from 'pages/forum'; | ||
import { ThemeProvider, Theme } from 'components/hooks/use-theme'; | ||
import React from 'react'; | ||
import { Provider as StoreProvider } from 'react-redux'; | ||
import type { AppStore, InitialState } from './store'; | ||
import './styles/index.pcss'; | ||
|
||
const router = createBrowserRouter( | ||
createRoutesFromElements( | ||
<Route | ||
element={<AuthLayout />} | ||
loader={() => defer({ userPromise: getCurrentUser() })} | ||
> | ||
<Route path={RouterPaths.REGISTER} element={<RegisterPage />} /> | ||
<Route path={RouterPaths.LOGIN} element={<LoginPage />} /> | ||
<Route | ||
element={<MainLayout />} | ||
loader={({ request }) => { | ||
const url = new URL(request.url); | ||
return url.searchParams.get('modal'); | ||
}} | ||
> | ||
<Route path={RouterPaths.MAIN} element={<MainPage />} /> | ||
<Route path={RouterPaths.LEADERBOARD} element={<Leaderboard />} /> | ||
<Route path={RouterPaths.FORUM} element={<Forum />}> | ||
<Route path={RouterPaths.NEW_THREAD} element={<NewThreadModal />} /> | ||
</Route> | ||
<Route path={`${RouterPaths.FORUM}/:id`} element={<ForumThread />} /> | ||
<Route element={<ProtectedRoutes />}> | ||
<Route path={RouterPaths.PROFILE} element={<Profile />} /> | ||
<Route path={`${RouterPaths.GAME}/:id`} element={<GamePage />} /> | ||
</Route> | ||
</Route> | ||
<Route path={RouterPaths.ERROR_500} element={<Error500 />} /> | ||
<Route path={RouterPaths.ERROR_404} element={<Error404 />} /> | ||
<Route path="*" element={<Error404 />} /> | ||
</Route> | ||
) | ||
); | ||
|
||
function App() { | ||
return <RouterProvider router={router} />; | ||
function App({ | ||
children, | ||
theme = Theme.LIGHT, | ||
store, | ||
initialState, | ||
}: { | ||
children: React.ReactNode; | ||
theme?: string; | ||
store: AppStore; | ||
initialState?: InitialState; | ||
}) { | ||
return ( | ||
<React.StrictMode> | ||
<ThemeProvider initialValue={theme}> | ||
<StoreProvider store={store} serverState={initialState}> | ||
{children} | ||
</StoreProvider> | ||
</ThemeProvider> | ||
</React.StrictMode> | ||
); | ||
} | ||
|
||
export default App; | ||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
declare const __SERVER_PORT__: number; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
__INITIAL_STATE__?: string; | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/client/src/components/client-only/client-only.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
export const ClientOnly = ({ children }: { children: React.ReactNode }) => { | ||
const [hasMounted, setHasMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setHasMounted(true); | ||
}, []); | ||
|
||
if (!hasMounted) return null; | ||
|
||
return <>{children}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ClientOnly } from './client-only'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.