Skip to content

Commit

Permalink
Add notifications feed to app
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbleasel committed Jan 12, 2025
1 parent beef5ef commit 6d637bf
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
12 changes: 11 additions & 1 deletion apps/app/app/(authenticated)/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { OrganizationSwitcher, UserButton } from '@repo/auth/client';
import { ModeToggle } from '@repo/design-system/components/mode-toggle';
import { Button } from '@repo/design-system/components/ui/button';
import {
Collapsible,
CollapsibleContent,
Expand Down Expand Up @@ -33,8 +34,10 @@ import {
useSidebar,
} from '@repo/design-system/components/ui/sidebar';
import { cn } from '@repo/design-system/lib/utils';
import { NotificationsTrigger } from '@repo/notifications/components/trigger';
import {
AnchorIcon,
BellIcon,
BookOpenIcon,
BotIcon,
ChevronRightIcon,
Expand Down Expand Up @@ -331,7 +334,14 @@ export const GlobalSidebar = ({ children }: GlobalSidebarProperties) => {
},
}}
/>
<ModeToggle />
<div className="flex shrink-0 items-center gap-px">
<ModeToggle />
<NotificationsTrigger>
<Button variant="ghost" size="icon" className="shrink-0">
<BellIcon size={16} className="text-muted-foreground" />
</Button>
</NotificationsTrigger>
</div>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/components/mode-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ModeToggle = () => {
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="outline"
variant="ghost"
size="icon"
className="shrink-0 text-foreground"
>
Expand Down
29 changes: 0 additions & 29 deletions packages/notifications/components/feed.tsx

This file was deleted.

48 changes: 48 additions & 0 deletions packages/notifications/components/trigger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use client';

import { NotificationFeedPopover } from '@knocklabs/react';
import { useRef, useState } from 'react';
import type { ReactElement, RefObject } from 'react';
import { keys } from '../keys';

// Required CSS import, unless you're overriding the styling
import '@knocklabs/react/dist/index.css';

type NotificationsTriggerProperties = {
children: ReactElement;
};

export const NotificationsTrigger = ({
children,
}: NotificationsTriggerProperties) => {
const [isVisible, setIsVisible] = useState(false);
const notifButtonRef = useRef<HTMLDivElement>(null);

if (!keys().NEXT_PUBLIC_KNOCK_API_KEY) {
return null;
}

return (
<>
{/* biome-ignore lint/nursery/noStaticElementInteractions: "avoid nested buttons" */}
<div
onClick={() => setIsVisible(!isVisible)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
setIsVisible(!isVisible);
}
}}
ref={notifButtonRef}
>
{children}
</div>
{notifButtonRef.current && (
<NotificationFeedPopover
buttonRef={notifButtonRef as RefObject<HTMLElement>}
isVisible={isVisible}
onClose={() => setIsVisible(false)}
/>
)}
</>
);
};
4 changes: 4 additions & 0 deletions packages/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const secure = async (
const decision = await aj.protect(req);

if (decision.isDenied()) {
console.warn(
`Arcjet decision: ${JSON.stringify(decision.reason, null, 2)}`
);

if (decision.reason.isBot()) {
throw new Error('No bots allowed');
}
Expand Down

0 comments on commit 6d637bf

Please sign in to comment.