Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
refactor: providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ko22009 committed Dec 7, 2023
1 parent 5913a27 commit 7080196
Show file tree
Hide file tree
Showing 60 changed files with 186 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

export FORCE_COLOR=1

yarn concurrently "yarn eslint" "yarn tslint" "lint-staged" --raw
yarn concurrently "yarn eslint --fix" "yarn tslint" "lint-staged" --raw
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ru from 'date-fns/locale/ru';
import { useIsMobile } from '~/shared/hooks';

import { ApiProvider } from './providers/api';
import { Routing } from './providers/router';
import { RouterProvider } from './providers/router';
import { desktopTheme, mobileTheme } from './providers/theme';

const queryClient = new QueryClient();
Expand All @@ -31,7 +31,7 @@ function App() {
>
<ApiProvider>
<QueryClientProvider client={queryClient}>
<Routing />
<RouterProvider />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</ApiProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/app/providers/api/ApiProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiContext, api } from '~/shared/contexts';
import { api } from '~/shared/api';
import { ApiContext } from '~/shared/contexts';

export function ApiProvider({ children }: { children: React.ReactNode }) {
return <ApiContext.Provider value={api}>{children}</ApiContext.Provider>;
Expand Down
1 change: 1 addition & 0 deletions src/app/providers/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AuthProvider';
17 changes: 0 additions & 17 deletions src/app/providers/layout/Routes.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { Box, Container, Flex, Stack } from '@chakra-ui/react';
import { useEffect, useRef } from 'react';
import { ScrollRestoration, useLocation } from 'react-router-dom';
import {
ScrollRestoration,
useLocation,
Routes as ReactRoutes,
Route,
} from 'react-router-dom';

import { MenuBase, MenuDesktop } from '~/widgets/menu';

import { LayoutContext } from '~/shared/contexts';
import { useIsMobile, useWindowSizes } from '~/shared/hooks';
import { PATHS } from '~/shared/lib/router';

import { AuthProvider } from './AuthProvider';
import { Routes } from './Routes';
import { AuthProvider } from '../auth';

import { OnboardingMiddleware } from './middlewares/onboarding';
import { routerPaths } from './router.paths';

const routes = (
<ReactRoutes>
{routerPaths.map(({ Component, path }) =>
OnboardingMiddleware(
path,
<Route key={path} path={path} element={<Component />} />,
),
)}
</ReactRoutes>
);

export const Layout = () => {
const isMobile = useIsMobile();
Expand All @@ -34,9 +52,7 @@ export const Layout = () => {
<AuthProvider>
{isMobile ? (
<Stack gap={0} minH="full">
<Flex flex="1">
<Routes />
</Flex>
<Flex flex="1">{routes}</Flex>
<Box position="sticky" bottom="0" bg="bg">
<Box ref={footerRef}></Box>
{!isDialogPage && !isOnboardingPage && <MenuBase />}
Expand All @@ -55,7 +71,7 @@ export const Layout = () => {
display="flex"
flexDirection="column"
>
<Routes />
{routes}
</Container>
</Flex>
)}
Expand Down
39 changes: 39 additions & 0 deletions src/app/providers/router/Router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
RouterProvider as ReactRouterProvider,
createBrowserRouter,
} from 'react-router-dom';

import { BlankPage } from '~/pages/blank';

import { api } from '~/shared/api';

import { Layout } from './Layout';

const closedRouter = createBrowserRouter([
{
path: '*',
element: <BlankPage />,
},
]);

const normalRouter = createBrowserRouter([
{
path: '*',
element: <Layout />,
loader: async () => {
try {
return api.userApi.isAuth();
} catch (e) {
return null;
}
},
},
]);

export const RouterProvider = () => {
return (
<ReactRouterProvider
router={import.meta.env.VITE_CLOSED ? closedRouter : normalRouter}
/>
);
};
2 changes: 1 addition & 1 deletion src/app/providers/router/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Routing } from './router';
export * from './Router';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {

import { PATHS } from '~/shared/lib/router';

export const normalRoutes = [
export const routerPaths = [
{
path: '*',
Component: Navigate.bind(null, {
Expand Down
17 changes: 10 additions & 7 deletions src/app/providers/router/router.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import {
RouterProvider as ReactRouterProvider,
createBrowserRouter,
} from 'react-router-dom';

import { BlankPage } from '~/pages/blank';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

import { Layout } from '../layout/Layout';
import { Layout } from './Layout';

const closedRouter = createBrowserRouter([
{
Expand All @@ -27,10 +30,10 @@ const normalRouter = createBrowserRouter([
},
]);

const Routing = () => {
export const RouterProvider = () => {
return (
<RouterProvider router={import.meta.env.VITE_CLOSED ? closedRouter : normalRouter} />
<ReactRouterProvider
router={import.meta.env.VITE_CLOSED ? closedRouter : normalRouter}
/>
);
};

export { Routing };
2 changes: 1 addition & 1 deletion src/entities/notification/api/useGetNotification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetNotification = (notificationId: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetAllProjects.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryFunctionContext, QueryKey, useInfiniteQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetAllProjects = (userId: string) =>
useInfiniteQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetParticipants.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { GetAllParticipantsRequest } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useGetParticipants = (data: GetAllParticipantsRequest) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetPositions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetPositions = (projectId: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetPositionsSkills.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQueries } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { GetProjectPositionsDataResponse } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useGetPositionsSkills = (
projectId: string,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetProject.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetProject = (projectId: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetProjectAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetProjectAvatar = (projectId: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project/api/useGetUser.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetUser = (userID: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/storage/api/useGetAllSkills.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetAllSkills = () =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/storage/api/useGetSkills.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQueries } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetSkills = (projectPositions?: string[][]) =>
useQueries({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/storage/api/useGetSkillsbyIds.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetSkillsByIds = (skills?: string[]) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/storage/api/useGetSpecs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetSpecs = () =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/api/useGetAvatar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetAvatar = (id: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/api/useGetProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetProfile = (id: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/api/useGetSkills.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useUserSkills = (id: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/api/useGetStatistic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useUserStatistic = (id: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/api/useIsAvatarExist.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useIsAvatarExist = (id: string) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/features/notifications/api/useReadNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useReadNotification = (notificationId: string) => {
const queryClient = useQueryClient();
Expand Down
2 changes: 1 addition & 1 deletion src/features/notifications/api/useUnreadNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';
import { api } from '~/shared/api';

export const useGetUnreadNotification = (isAuth: boolean) =>
useQuery({
Expand Down
2 changes: 1 addition & 1 deletion src/features/project/add/api/useAddAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { UpdateProjectAvatarRequest } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useAddAvatar = () =>
useMutation({
Expand Down
2 changes: 1 addition & 1 deletion src/features/project/add/api/useAddPosition.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { CreatePositionRequest } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useAddPosition = () =>
useMutation({
Expand Down
2 changes: 1 addition & 1 deletion src/features/project/add/api/useAddProject.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { NewProjectRequest } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useAddProject = () =>
useMutation({
Expand Down
2 changes: 1 addition & 1 deletion src/features/project/add/api/useAddSkills.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { AddSkillsRequest, UpdateSkillsParams } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useAddSkills = () =>
useMutation({
Expand Down
2 changes: 1 addition & 1 deletion src/features/project/add/api/useCreateParticipant.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from '@tanstack/react-query';

import { api } from '~/shared/api';
import { CreateParticipantRequest } from '~/shared/api/model';
import { api } from '~/shared/contexts';

export const useCreateParticipant = () =>
useMutation({
Expand Down
Loading

0 comments on commit 7080196

Please sign in to comment.