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:
|
||||
* 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 {
|
||||
Dispatch,
|
||||
PropsWithChildren,
|
||||
createContext,
|
||||
useState,
|
||||
Dispatch,
|
||||
useContext,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { useGet } from "@/hooks/crud/useGet";
|
||||
import { EntityType, Format } from "@/services/types";
|
||||
import { ISubscriber } from "@/types/subscriber.types";
|
||||
import { useSocketGetQuery } from "@/websocket/socket-hooks";
|
||||
|
||||
import { noop } from "../helpers/noop";
|
||||
|
||||
@ -49,10 +48,6 @@ export const ChatProvider = ({ children }: PropsWithChildren) => {
|
||||
setSubscriberId,
|
||||
};
|
||||
|
||||
useSocketGetQuery("/message/subscribe/");
|
||||
|
||||
useSocketGetQuery("/subscriber/subscribe/");
|
||||
|
||||
return (
|
||||
<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:
|
||||
* 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 = {
|
||||
isSideBarOpen: boolean;
|
||||
onToggleSidebar: () => void;
|
||||
isSideBarOpen?: boolean;
|
||||
onToggleSidebar?: () => void;
|
||||
};
|
||||
export const Header: FC<HeaderProps> = ({ isSideBarOpen, onToggleSidebar }) => {
|
||||
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:
|
||||
* 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 { BoxProps, Grid } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
import { BoxProps } from "@mui/material";
|
||||
|
||||
import { ChatWidget } from "@/app-components/widget/ChatWidget";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
|
||||
import { Content } from "./content";
|
||||
import { Header } from "./Header";
|
||||
import { VerticalMenu } from "./VerticalMenu";
|
||||
import { AnonymousLayout } from "./AnonymousLayout";
|
||||
import { AuthenticatedLayout } from "./AuthenticatedLayout";
|
||||
|
||||
export interface IContentPaddingProps {
|
||||
hasNoPadding?: boolean;
|
||||
@ -23,28 +21,12 @@ export type LayoutProps = IContentPaddingProps & {
|
||||
children: JSX.Element;
|
||||
sxContent?: BoxProps;
|
||||
};
|
||||
export const Layout: React.FC<LayoutProps> = ({
|
||||
children,
|
||||
sxContent,
|
||||
...rest
|
||||
}) => {
|
||||
const [isSideBarOpen, setIsSideBarOpen] = useState(false);
|
||||
export const Layout: React.FC<LayoutProps> = ({ children, ...rest }) => {
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
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>
|
||||
return isAuthenticated ? (
|
||||
<AuthenticatedLayout {...rest}>{children}</AuthenticatedLayout>
|
||||
) : (
|
||||
<AnonymousLayout {...rest}>{children}</AnonymousLayout>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user