-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
530 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
packages/@steedos-widgets/liveblocks/src/components/InboxPopover.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
.inbox { | ||
background: #fff; | ||
width: 460px; | ||
height: 560px; | ||
max-height: calc(100vh - var(--header-height) - 10px); | ||
display: flex; | ||
flex-direction: column; | ||
outline: none; | ||
overflow-y: auto; | ||
border-radius: 0.75rem; | ||
box-shadow: | ||
0 0 0 1px rgb(0 0 0 / 4%), | ||
0 2px 6px rgb(0 0 0 / 8%), | ||
0 8px 26px rgb(0 0 0 / 12%); | ||
} | ||
|
||
.inbox-header { | ||
position: sticky; | ||
top: 0; | ||
z-index: 1; | ||
display: flex; | ||
place-items: center; | ||
justify-content: space-between; | ||
background: #fff; | ||
width: 100%; | ||
padding: 0.5rem 0.5rem 0.5rem 1rem; | ||
box-shadow: | ||
0 0 0 1px rgb(0 0 0 / 4%), | ||
0 2px 6px rgb(0 0 0 / 4%), | ||
0 8px 26px rgb(0 0 0 / 6%); | ||
} | ||
|
||
.inbox-title { | ||
font-weight: 500; | ||
} | ||
|
||
.inbox-buttons { | ||
display: flex; | ||
gap: 6px; | ||
} | ||
|
||
.inbox-list { | ||
box-shadow: 0 0 0 1px rgb(0 0 0 / 8%); | ||
} | ||
|
||
.inbox-unread-count { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
transform: translate(50%, -50%); | ||
display: flex; | ||
place-content: center; | ||
place-items: center; | ||
background: var(--accent); | ||
color: #fff; | ||
font-size: 0.65rem; | ||
font-weight: 500; | ||
height: 1rem; | ||
min-width: 1rem; | ||
padding: 0 0.25rem; | ||
border-radius: 9999px; | ||
} | ||
|
||
|
||
.inbox-content { | ||
display: flex; | ||
min-height: 100vh; | ||
padding: calc(var(--header-height) + 1rem) 1rem 1rem | ||
calc(var(--sidebar-width) + 1rem); | ||
overflow-y: auto; | ||
} | ||
|
||
.inbox-button { | ||
all: unset; | ||
position: relative; | ||
display: flex; | ||
place-items: center; | ||
place-content: center; | ||
padding: 0.5rem 0.75rem; | ||
font-size: 0.875rem; | ||
border-radius: 0.5rem; | ||
background: #f3f3f3; | ||
color: #555; | ||
} | ||
|
||
.inbox-button.square { | ||
padding: 0; | ||
width: 2rem; | ||
height: 2rem; | ||
} | ||
|
||
.inbox-button.destructive { | ||
background: #fde5e5; | ||
color: #953939; | ||
} | ||
|
||
.inbox-button:hover, | ||
.inbox-button:focus-visible { | ||
background: #e8e8e8; | ||
cursor: pointer; | ||
} | ||
|
||
.inbox-button.destructive:hover, | ||
.inbox-button.destructive:focus-visible{ | ||
background: #ffd6d6; | ||
} |
131 changes: 131 additions & 0 deletions
131
packages/@steedos-widgets/liveblocks/src/components/InboxPopover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
"use client"; | ||
import React from 'react'; | ||
import { InboxNotification, InboxNotificationList } from "@liveblocks/react-ui"; | ||
import * as Popover from "@radix-ui/react-popover"; | ||
import { | ||
useDeleteAllInboxNotifications, | ||
useInboxNotifications, | ||
useMarkAllInboxNotificationsAsRead, | ||
useUnreadInboxNotificationsCount, | ||
} from "@liveblocks/react/suspense"; | ||
import { ClientSideSuspense } from "@liveblocks/react"; | ||
import { Loading } from "./Loading"; | ||
import { ComponentPropsWithoutRef, useEffect, useState } from "react"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import clsx from "clsx"; | ||
// import { Link } from "./Link"; | ||
// import { usePathname } from "next/navigation"; | ||
import './InboxPopover.css'; | ||
|
||
|
||
function Inbox({ className, ...props }: ComponentPropsWithoutRef<"div">) { | ||
const { inboxNotifications } = useInboxNotifications(); | ||
|
||
return inboxNotifications.length === 0 ? ( | ||
<div className={clsx(className, "empty")}> | ||
There aren’t any notifications yet. | ||
</div> | ||
) : ( | ||
<div className={className} {...props}> | ||
<InboxNotificationList className="inbox-list"> | ||
{inboxNotifications.map((inboxNotification) => { | ||
return ( | ||
<InboxNotification | ||
key={inboxNotification.id} | ||
inboxNotification={inboxNotification} | ||
// components={{ Anchor: Link }} | ||
/> | ||
); | ||
})} | ||
</InboxNotificationList> | ||
</div> | ||
); | ||
} | ||
|
||
function InboxPopoverUnreadCount() { | ||
const { count } = useUnreadInboxNotificationsCount(); | ||
|
||
return count ? <div className="inbox-unread-count">{count}</div> : null; | ||
} | ||
|
||
export function AmisInboxPopover({ | ||
className, | ||
...props | ||
}: Popover.PopoverContentProps) { | ||
const [isOpen, setOpen] = useState(false); | ||
const markAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead(); | ||
const deleteAllInboxNotifications = useDeleteAllInboxNotifications(); | ||
// const pathname = usePathname(); | ||
|
||
// useEffect(() => { | ||
// setOpen(false); | ||
// }, [pathname]); | ||
|
||
return ( | ||
<Popover.Root open={isOpen} onOpenChange={setOpen}> | ||
<Popover.Trigger className={clsx(className, "inbox-button square")}> | ||
<ErrorBoundary fallback={null}> | ||
<ClientSideSuspense fallback={null}> | ||
<InboxPopoverUnreadCount /> | ||
</ClientSideSuspense> | ||
</ErrorBoundary> | ||
<svg | ||
width="20" | ||
height="20" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="m3.6 9.8 1.9-4.6A2 2 0 0 1 7.3 4h5.4a2 2 0 0 1 1.8 1.2l2 4.6V13a2 2 0 0 1-2 2h-9a2 2 0 0 1-2-2V9.8Z" | ||
stroke="currentColor" | ||
strokeWidth="1.5" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M3.5 10h3c.3 0 .6.1.8.4l.9 1.2c.2.3.5.4.8.4h2c.3 0 .6-.1.8-.4l.9-1.2c.2-.3.5-.4.8-.4h3" | ||
stroke="currentColor" | ||
strokeWidth="1.5" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
</Popover.Trigger> | ||
<Popover.Portal> | ||
<Popover.Content | ||
className="inbox" | ||
collisionPadding={16} | ||
sideOffset={8} | ||
{...props} | ||
> | ||
<div className="inbox-header"> | ||
<span className="inbox-title">Notifications</span> | ||
<div className="inbox-buttons"> | ||
<button | ||
className="inbox-button" | ||
onClick={markAllInboxNotificationsAsRead} | ||
> | ||
Mark all as read | ||
</button> | ||
<button | ||
className="inbox-button destructive" | ||
onClick={deleteAllInboxNotifications} | ||
> | ||
Delete all | ||
</button> | ||
</div> | ||
</div> | ||
<ErrorBoundary | ||
fallback={ | ||
<div className="error"> | ||
There was an error while getting notifications. | ||
</div> | ||
} | ||
> | ||
<ClientSideSuspense fallback={<Loading />}> | ||
<Inbox /> | ||
</ClientSideSuspense> | ||
</ErrorBoundary> | ||
</Popover.Content> | ||
</Popover.Portal> | ||
</Popover.Root> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/@steedos-widgets/liveblocks/src/components/Loading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
|
||
export function Loading() { | ||
return ( | ||
<svg className="animate-spin h-5 w-5 mr-3 ..." viewBox="0 0 24 24"> | ||
</svg> | ||
); | ||
} |
Oops, something went wrong.