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

Commit

Permalink
fix: баг получения количества уведомлений + подключение десктопа (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaBorovskaya authored Mar 19, 2024
1 parent 44366fa commit f95cd9b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/app/providers/router/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const Layout = () => {
) : (
<Flex alignItems="start" h="full">
<BlankPage />
{/* ВОТ ТУТ ДЛЯ ДЕСКТОПА РАСКОММЕНТИРУЙ, А BlankPage ЗАКОММЕНТЬ */}
{/* {!isNotFoundPage && <MenuDesktop />}
<Container
maxW="6xl"
Expand Down
33 changes: 23 additions & 10 deletions src/app/providers/router/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { Routes as ReactRoutes, Route } from 'react-router-dom';

import { useIsMobile } from '~/shared/hooks';

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

export const Routes = () => (
<ReactRoutes>
{routerPaths.map(({ Component, path }) =>
OnboardingMiddleware(
path,
<Route key={path} path={path} element={<Component />} />,
),
)}
</ReactRoutes>
);
export function Routes() {
const isMobile = useIsMobile();

return (
<ReactRoutes>
{routerPaths.map((props) => {
let Component = props.view.base;
const desktop = props.view.desktop;

if (!isMobile && desktop) {
Component = desktop;
}

return OnboardingMiddleware(
props.path,
<Route key={props.path} path={props.path} element={<Component />} />,
);
})}
</ReactRoutes>
);
}
108 changes: 75 additions & 33 deletions src/app/providers/router/router.paths.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Navigate } from 'react-router-dom';

import { ChatsPage, ChatsPageDesktop } from '~/pages/chats';
import { DialogPage } from '~/pages/dialog';
import { MainPage } from '~/pages/main';
import { NotFoundPage } from '~/pages/not-found';
import { NotificationPage } from '~/pages/notification';
Expand Down Expand Up @@ -32,84 +30,128 @@ import { PATHS } from '~/shared/lib/router';
export const routerPaths = [
{
path: '*',
Component: Navigate.bind(null, {
to: PATHS.notFound,
replace: true,
}),
view: {
base: Navigate.bind(null, {
to: PATHS.notFound,
replace: true,
}),
},
},
{
path: PATHS.root,
Component: MainPage,
view: {
base: MainPage,
// для примера
desktop: MainPage,
},
},
{
path: PATHS.notFound,
Component: NotFoundPage,
view: {
base: NotFoundPage,
},
},
{
path: PATHS.profile,
Component: ProfileUserPage,
view: {
base: ProfileUserPage,
},
},
{
path: PATHS.profileMe,
Component: ProfileMePage,
view: {
base: ProfileMePage,
// desktop: ProfilePageDesktop,
},
},
{
path: PATHS.deletedProfile,
Component: DeletedProfile,
view: {
base: DeletedProfile,
},
},
{
path: PATHS.searchProject,
Component: ProjectPage,
view: {
base: ProjectPage,
},
},
{
path: PATHS.search,
Component: SearchPage,
view: {
base: SearchPage,
},
},
{
path: PATHS.onboarding,
Component: OnboardingPage,
view: {
base: OnboardingPage,
},
},
{
path: PATHS.projects,
Component: ProjectsPage,
view: {
base: ProjectsPage,
},
},
// {
// path: PATHS.chats,
// Component: ChatsPage,
// },
{
path: PATHS.chats,
Component: NotFoundPage,
view: {
base: NotFoundPage,
},
},
{
path: PATHS.project,
Component: ProjectPage,
view: {
base: ProjectPage,
},
},
{
path: PATHS.position,
Component: PositionPage,
view: {
base: PositionPage,
},
},
{
path: PATHS.addProject,
Component: AddProjectPage,
view: {
base: AddProjectPage,
},
},
// {
// path: PATHS.dialog,
// Component: DialogPage,
// },
{
path: PATHS.dialog,
Component: NotFoundPage,
view: {
base: NotFoundPage,
},
},
{
path: PATHS.notifications,
Component: NotificationsPage,
view: {
base: NotificationsPage,
},
},
{
path: PATHS.notification,
Component: NotificationPage,
view: {
base: NotificationPage,
},
},
{
path: PATHS.settings,
view: {
base: SettingsPage,
},
},
{
path: PATHS.profileSettings,
view: {
base: ProfileSettingsPage,
},
},
{
path: PATHS.notificationsSettings,
view: {
base: NotificationsSettingsPage,
},
},
{ path: PATHS.settings, Component: SettingsPage },
{ path: PATHS.profileSettings, Component: ProfileSettingsPage },
{ path: PATHS.notificationsSettings, Component: NotificationsSettingsPage },
];
2 changes: 1 addition & 1 deletion src/features/notifications/api/useUnreadNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const useGetUnreadNotification = (isAuth: boolean) =>
useQuery({
queryKey: ['unreadNotificatiions'],
queryFn: () => api.notificationsApi.getUnreadCount({ is_read: false }),
staleTime: 10000,
staleTime: 5000,
enabled: isAuth,
});
2 changes: 1 addition & 1 deletion src/features/user/update-user/UpdateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function UpdateUser({
id: user.id,
first_name: data.first_name,
last_name: data.last_name,
about: data.about,
about: data.about || '',
main_specialization_id: data.specs[0] ?? null,
secondary_specialization_id: data.specs[1] ?? null,
};
Expand Down
10 changes: 8 additions & 2 deletions src/widgets/menu/base/MenuBase.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container, Flex, Link, Text } from '@chakra-ui/react';
import { NavLink } from 'react-router-dom';
import { useEffect } from 'react';
import { NavLink, useLocation } from 'react-router-dom';

import { useGetUnreadNotification } from '~/features/notifications';

Expand All @@ -10,7 +11,12 @@ import { routes } from './routes';

export const MenuBase = () => {
const { isAuth } = useAuth();
const { data } = useGetUnreadNotification(isAuth);
const { data, refetch } = useGetUnreadNotification(isAuth);
const location = useLocation();

useEffect(() => {
refetch();
}, [location, isAuth]);

return (
<Flex shadow="base" borderTop="1px" borderColor="gray.200" bg="white">
Expand Down

0 comments on commit f95cd9b

Please sign in to comment.