mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(frontend): resolve notification subscription logic
This commit is contained in:
parent
2638e845e6
commit
76ecb900c5
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Hexastack. All rights reserved.
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
@ -7,17 +7,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
Dispatch,
|
||||||
PropsWithChildren,
|
PropsWithChildren,
|
||||||
createContext,
|
createContext,
|
||||||
useState,
|
|
||||||
Dispatch,
|
|
||||||
useContext,
|
useContext,
|
||||||
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
|
||||||
import { useGet } from "@/hooks/crud/useGet";
|
import { useGet } from "@/hooks/crud/useGet";
|
||||||
import { EntityType, Format } from "@/services/types";
|
import { EntityType, Format } from "@/services/types";
|
||||||
import { ISubscriber } from "@/types/subscriber.types";
|
import { ISubscriber } from "@/types/subscriber.types";
|
||||||
import { useSocketGetQuery } from "@/websocket/socket-hooks";
|
|
||||||
|
|
||||||
import { noop } from "../helpers/noop";
|
import { noop } from "../helpers/noop";
|
||||||
|
|
||||||
@ -49,10 +48,6 @@ export const ChatProvider = ({ children }: PropsWithChildren) => {
|
|||||||
setSubscriberId,
|
setSubscriberId,
|
||||||
};
|
};
|
||||||
|
|
||||||
useSocketGetQuery("/message/subscribe/");
|
|
||||||
|
|
||||||
useSocketGetQuery("/subscriber/subscribe/");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<chatContext.Provider value={context}>{children}</chatContext.Provider>
|
<chatContext.Provider value={context}>{children}</chatContext.Provider>
|
||||||
);
|
);
|
||||||
|
30
frontend/src/layout/AnonymousLayout.tsx
Normal file
30
frontend/src/layout/AnonymousLayout.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Grid } from "@mui/material";
|
||||||
|
|
||||||
|
import { LayoutProps } from ".";
|
||||||
|
|
||||||
|
import { ChatWidget } from "@/app-components/widget/ChatWidget";
|
||||||
|
|
||||||
|
import { Content } from "./content";
|
||||||
|
import { Header } from "./Header";
|
||||||
|
|
||||||
|
export const AnonymousLayout: React.FC<LayoutProps> = ({
|
||||||
|
children,
|
||||||
|
sxContent,
|
||||||
|
...rest
|
||||||
|
}) => (
|
||||||
|
<Grid container>
|
||||||
|
<Header />
|
||||||
|
<Content sx={sxContent} {...rest}>
|
||||||
|
{children}
|
||||||
|
</Content>
|
||||||
|
<ChatWidget />
|
||||||
|
</Grid>
|
||||||
|
);
|
49
frontend/src/layout/AuthenticatedLayout.tsx
Normal file
49
frontend/src/layout/AuthenticatedLayout.tsx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Grid } from "@mui/material";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import { LayoutProps } from ".";
|
||||||
|
|
||||||
|
import { ChatWidget } from "@/app-components/widget/ChatWidget";
|
||||||
|
import { useSocketGetQuery } from "@/websocket/socket-hooks";
|
||||||
|
|
||||||
|
import { Content } from "./content";
|
||||||
|
import { Header } from "./Header";
|
||||||
|
import { VerticalMenu } from "./VerticalMenu";
|
||||||
|
|
||||||
|
export const AuthenticatedLayout: React.FC<LayoutProps> = ({
|
||||||
|
children,
|
||||||
|
sxContent,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
|
const [isSideBarOpen, setIsSideBarOpen] = useState(false);
|
||||||
|
|
||||||
|
useSocketGetQuery("/message/subscribe/");
|
||||||
|
|
||||||
|
useSocketGetQuery("/subscriber/subscribe/");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container>
|
||||||
|
<Header
|
||||||
|
isSideBarOpen={isSideBarOpen}
|
||||||
|
onToggleSidebar={() => setIsSideBarOpen(true)}
|
||||||
|
/>
|
||||||
|
<VerticalMenu
|
||||||
|
isSideBarOpen={isSideBarOpen}
|
||||||
|
onToggleIn={() => setIsSideBarOpen(true)}
|
||||||
|
onToggleOut={() => setIsSideBarOpen(false)}
|
||||||
|
/>
|
||||||
|
<Content sx={sxContent} {...rest}>
|
||||||
|
{children}
|
||||||
|
</Content>
|
||||||
|
<ChatWidget />
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Hexastack. All rights reserved.
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
@ -69,8 +69,8 @@ const StyledAppBar = styled(AppBar)(() => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export type HeaderProps = {
|
export type HeaderProps = {
|
||||||
isSideBarOpen: boolean;
|
isSideBarOpen?: boolean;
|
||||||
onToggleSidebar: () => void;
|
onToggleSidebar?: () => void;
|
||||||
};
|
};
|
||||||
export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
||||||
const { apiUrl, ssoEnabled } = useConfig();
|
const { apiUrl, ssoEnabled } = useConfig();
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Hexastack. All rights reserved.
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BoxProps, Grid } from "@mui/material";
|
import { BoxProps } from "@mui/material";
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
import { ChatWidget } from "@/app-components/widget/ChatWidget";
|
import { useAuth } from "@/hooks/useAuth";
|
||||||
|
|
||||||
import { Content } from "./content";
|
import { AnonymousLayout } from "./AnonymousLayout";
|
||||||
import { Header } from "./Header";
|
import { AuthenticatedLayout } from "./AuthenticatedLayout";
|
||||||
import { VerticalMenu } from "./VerticalMenu";
|
|
||||||
|
|
||||||
export interface IContentPaddingProps {
|
export interface IContentPaddingProps {
|
||||||
hasNoPadding?: boolean;
|
hasNoPadding?: boolean;
|
||||||
@ -23,28 +21,12 @@ export type LayoutProps = IContentPaddingProps & {
|
|||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
sxContent?: BoxProps;
|
sxContent?: BoxProps;
|
||||||
};
|
};
|
||||||
export const Layout: React.FC<LayoutProps> = ({
|
export const Layout: React.FC<LayoutProps> = ({ children, ...rest }) => {
|
||||||
children,
|
const { isAuthenticated } = useAuth();
|
||||||
sxContent,
|
|
||||||
...rest
|
|
||||||
}) => {
|
|
||||||
const [isSideBarOpen, setIsSideBarOpen] = useState(false);
|
|
||||||
|
|
||||||
return (
|
return isAuthenticated ? (
|
||||||
<Grid container>
|
<AuthenticatedLayout {...rest}>{children}</AuthenticatedLayout>
|
||||||
<Header
|
) : (
|
||||||
isSideBarOpen={isSideBarOpen}
|
<AnonymousLayout {...rest}>{children}</AnonymousLayout>
|
||||||
onToggleSidebar={() => setIsSideBarOpen(true)}
|
|
||||||
/>
|
|
||||||
<VerticalMenu
|
|
||||||
isSideBarOpen={isSideBarOpen}
|
|
||||||
onToggleIn={() => setIsSideBarOpen(true)}
|
|
||||||
onToggleOut={() => setIsSideBarOpen(false)}
|
|
||||||
/>
|
|
||||||
<Content sx={sxContent} {...rest}>
|
|
||||||
{children}
|
|
||||||
</Content>
|
|
||||||
<ChatWidget />
|
|
||||||
</Grid>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user