mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
* React 18 upgrade * fix: Force synchronous React rendering in server HTML export React 18 can defer a legacy ReactDOM.render commit when sync work is queued, leaving exported component nodes empty. Wrap the render in flushSync, and flush unmount-scheduled passive effects before global env cleanup so React never runs without a window. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor: Move server ComponentView to createRoot ReactDOM.render and unmountComponentAtNode are removed in React 19. flushSync around root.render keeps the mount synchronous for the HTML-export path, which reads the DOM immediately after. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Enable CI --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
105 lines
2.9 KiB
TypeScript
105 lines
2.9 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import {
|
|
Drawer,
|
|
DrawerContent,
|
|
DrawerTitle,
|
|
DrawerTrigger,
|
|
} from "~/components/primitives/Drawer";
|
|
import {
|
|
Popover,
|
|
PopoverTrigger,
|
|
PopoverContent,
|
|
} from "~/components/primitives/Popover";
|
|
import useConsumeQueryParam from "~/hooks/useConsumeQueryParam";
|
|
import useMobile from "~/hooks/useMobile";
|
|
import useStores from "~/hooks/useStores";
|
|
import { isTruthyQueryValue } from "~/utils/urls";
|
|
import Notifications from "./Notifications";
|
|
|
|
type Props = {
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
const NotificationsPopover: React.FC<Props> = ({ children }: Props) => {
|
|
const { t } = useTranslation();
|
|
const { notifications } = useStores();
|
|
const shouldOpen = isTruthyQueryValue(useConsumeQueryParam("notifications"));
|
|
const [open, setOpen] = useState(shouldOpen);
|
|
const isMobile = useMobile();
|
|
const scrollableRef = useRef<HTMLDivElement>(null);
|
|
const drawerContentRef = useRef<React.ElementRef<typeof DrawerContent>>(null);
|
|
|
|
useEffect(() => {
|
|
void notifications.fetchPage({ archived: false });
|
|
}, [notifications]);
|
|
|
|
const handleRequestClose = useCallback(() => {
|
|
setOpen(false);
|
|
}, []);
|
|
|
|
const handleAutoFocus = useCallback((event: Event) => {
|
|
// Prevent focus from moving to the popover content
|
|
event.preventDefault();
|
|
|
|
// Reset scroll position to the top when popover is opened
|
|
if (scrollableRef.current) {
|
|
scrollableRef.current.scrollTop = 0;
|
|
scrollableRef.current.focus();
|
|
}
|
|
}, []);
|
|
|
|
const enablePointerEvents = useCallback(() => {
|
|
if (drawerContentRef.current) {
|
|
drawerContentRef.current.style.pointerEvents = "auto";
|
|
}
|
|
}, []);
|
|
|
|
const disablePointerEvents = useCallback(() => {
|
|
if (drawerContentRef.current) {
|
|
drawerContentRef.current.style.pointerEvents = "none";
|
|
}
|
|
}, []);
|
|
|
|
const notificationsList = (
|
|
<Notifications onRequestClose={handleRequestClose} ref={scrollableRef} />
|
|
);
|
|
|
|
if (isMobile) {
|
|
return (
|
|
<Drawer open={open} onOpenChange={setOpen}>
|
|
<DrawerTrigger asChild>{children}</DrawerTrigger>
|
|
<DrawerContent
|
|
ref={drawerContentRef}
|
|
aria-label={t("Notifications")}
|
|
aria-describedby={undefined}
|
|
onAnimationStart={disablePointerEvents}
|
|
onAnimationEnd={enablePointerEvents}
|
|
>
|
|
<DrawerTitle hidden>{t("Notifications")}</DrawerTitle>
|
|
{notificationsList}
|
|
</DrawerContent>
|
|
</Drawer>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger>{children}</PopoverTrigger>
|
|
<PopoverContent
|
|
aria-label={t("Notifications")}
|
|
side="top"
|
|
align="start"
|
|
onOpenAutoFocus={handleAutoFocus}
|
|
scrollable={false}
|
|
shrink
|
|
>
|
|
{notificationsList}
|
|
</PopoverContent>
|
|
</Popover>
|
|
);
|
|
};
|
|
|
|
export default observer(NotificationsPopover);
|