Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hub/client/application/hub/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const workspaceResponseSchema = z.object({
repositories: z.array(repositorySchema),
repositoryPermissionsAvailable: z.literal(true).optional(),
reviewInboxAvailable: z.boolean().optional(),
inboxHasUnread: z.boolean().optional(),
publicSharingSettingsAvailable: z.boolean().optional(),
capabilities: workspaceCapabilitiesSchema.optional(),
welcomeHidden: z.boolean().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { notifyInboxRead } from "@utils/notification/read-updates"
import { requestJson } from "../request-json"

export async function acknowledgeInboxActivity(
input: { notificationId: number; prototypeId: string; threadId: number; commentId: number },
input: {
viewerId: string
notificationId: number
prototypeId: string
threadId: number
commentId: number
},
signal: AbortSignal,
) {
const url = new URL(`/api/notifications/${input.notificationId}`, window.location.origin)
Expand All @@ -24,6 +30,7 @@ export async function acknowledgeInboxActivity(
signal,
body: JSON.stringify({ notification: { read: true, version: notice.version } }),
})
if (!signal.aborted) notifyInboxRead({ id: notice.id, saved, startedAt })
if (!signal.aborted)
notifyInboxRead({ viewerId: input.viewerId, id: notice.id, saved, startedAt })
}
}
259 changes: 205 additions & 54 deletions hub/client/application/hub/routes/real-workspace-navigation.test.tsx

Large diffs are not rendered by default.

100 changes: 47 additions & 53 deletions hub/client/application/hub/routes/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import { RouteFeedback } from "@application/hub/route-feedback"
import { useWorkspaceRepositoryPermissions } from "@application/hub/use-workspace-repository-permissions"
import { hubWorkspace } from "@application/hub/view-models/hub-workspace"
import { WorkspaceCompletionContext } from "@application/hub/workspace-completion-context"
import { WorkspaceInboxCountContext } from "@application/hub/workspace-inbox-count-context"
import { HubWorkspace } from "@features/hub-workspace"
import { useNotificationInbox } from "@hooks/use-notification-inbox"

import type { Route } from "./+types/index"
import type { WorkspaceRouteHandle } from "./types"
Expand Down Expand Up @@ -121,17 +119,34 @@ export default function Workspace({ loaderData }: Pick<Route.ComponentProps, "lo
return <Outlet context={null} />
}
const { workspace } = loaderData
const viewerKey = `${workspace.viewer.id}:${workspace.viewer.provider ?? ""}:${workspace.capabilities?.administerHub ?? false}`
const viewerKey = `${workspace.viewer.id}:${workspace.viewer.provider ?? ""}`
return <SignedInWorkspace key={viewerKey} data={loaderData} handle={handle} />
}

function SignedInWorkspace({
data,
handle,
}: {
type WorkspaceFrameProps = {
data: WorkspaceData
handle?: WorkspaceRouteHandle
}) {
inboxHasUnread?: boolean
}

function SignedInWorkspace({ data, handle }: WorkspaceFrameProps) {
const { inboxHasUnread } = data.workspace
const [lastUnread, setLastUnread] = useState(inboxHasUnread)
if (inboxHasUnread !== undefined && inboxHasUnread !== lastUnread) {
setLastUnread(inboxHasUnread)
}

return (
<WorkspaceSession
key={String(data.workspace.capabilities?.administerHub ?? false)}
data={data}
handle={handle}
inboxHasUnread={inboxHasUnread ?? lastUnread}
/>
)
}

function WorkspaceSession({ data, handle, inboxHasUnread }: WorkspaceFrameProps) {
const { key } = useLocation()
const navigationPending = useNavigation().state !== "idle"
const revalidator = useRevalidator()
Expand Down Expand Up @@ -160,18 +175,12 @@ function SignedInWorkspace({
}
}}
>
<WorkspaceNavigationFrame data={data} handle={handle} />
<WorkspaceNavigationFrame data={data} handle={handle} inboxHasUnread={inboxHasUnread} />
</WorkspaceCompletionContext>
)
}

function WorkspaceNavigationFrame({
data,
handle,
}: {
data: WorkspaceData
handle?: WorkspaceRouteHandle
}) {
function WorkspaceNavigationFrame({ data, handle, inboxHasUnread }: WorkspaceFrameProps) {
const { pathname, search } = useLocation()
const parameters = new URLSearchParams(search)
const repositoryId = readWorkspaceRepositoryId({ pathname, searchParams: parameters })
Expand All @@ -182,17 +191,6 @@ function WorkspaceNavigationFrame({
)
const section = handle?.workspaceSection
const navigation = hubWorkspace(workspace, parameters, section)
const configuration = checkingWorkspace ? undefined : navigation.notificationInbox
const inbox = useNotificationInbox({
path: configuration?.path,
authenticityToken: navigation.authenticityToken,
initialUnreadCount: navigation.notificationsUnreadCount,
initialUnreadOnly: true,
autoLoad: false,
autoCount: Boolean(configuration) && section !== "notifications",
synchronize: Boolean(configuration),
limit: 10,
})

if (checkingWorkspace) {
return (
Expand All @@ -204,31 +202,27 @@ function WorkspaceNavigationFrame({
)
}
return (
<WorkspaceInboxCountContext value={inbox.onUnreadCountChange}>
<HubWorkspace
contentResetKey={pathname}
defaultNavigationCollapsed={handle?.defaultNavigationCollapsed}
onRetryPermissions={retry}
data={{
...navigation,
emptyRepositoryLabel: data.repositoryNavigationError
? "Repository navigation unavailable"
: navigation.emptyRepositoryLabel,
repositoryUnavailableMessage: data.repositoryNavigationError
? "Hub could not load repository navigation."
: undefined,
liveInbox: configuration
? { ...inbox, copy: configuration.copy, onOpen: () => inbox.onOpen(true) }
: undefined,
inboxPreviewScope: pathname,
}}
>
{data.repositoryNavigationError && !handle?.independentOfRepositoryNavigation ? (
<RouteErrorFeedback error={data.repositoryNavigationError} embedded />
) : (
<Outlet context={workspace} />
)}
</HubWorkspace>
</WorkspaceInboxCountContext>
<HubWorkspace
contentResetKey={pathname}
defaultNavigationCollapsed={handle?.defaultNavigationCollapsed}
onRetryPermissions={retry}
data={{
...navigation,
notificationsUnread: inboxHasUnread,
emptyRepositoryLabel: data.repositoryNavigationError
? "Repository navigation unavailable"
: navigation.emptyRepositoryLabel,
repositoryUnavailableMessage: data.repositoryNavigationError
? "Hub could not load repository navigation."
: undefined,
inboxPreviewScope: pathname,
}}
>
{data.repositoryNavigationError && !handle?.independentOfRepositoryNavigation ? (
<RouteErrorFeedback error={data.repositoryNavigationError} embedded />
) : (
<Outlet context={workspace} />
)}
</HubWorkspace>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export function PrototypeScreen({
!message.deletedAt &&
(message.kind === "root" ? message.id : message.rootId) === commentId,
)
const viewerId = workspace.viewer.id
useEffect(() => {
if (
!notificationId ||
Expand All @@ -191,6 +192,7 @@ export function PrototypeScreen({
const controller = new AbortController()
void acknowledgeInboxActivity(
{
viewerId,
notificationId,
prototypeId: data.prototype.id,
threadId: commentId,
Expand All @@ -201,7 +203,7 @@ export function PrototypeScreen({
if (!controller.signal.aborted) setFailedNotification(notificationId)
})
return () => controller.abort()
}, [notificationId, commentId, messageId, targetExists, opened, data.prototype.id])
}, [notificationId, commentId, messageId, targetExists, opened, data.prototype.id, viewerId])
let notificationError: string | undefined
if (notificationId !== null) {
if (!review.comments.loading && !targetExists) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { useContext } from "react"
import { useSearchParams } from "react-router"

import type { WorkspaceResponse } from "@application/hub/contracts/types"
import { hubWorkspace } from "@application/hub/view-models/hub-workspace"
import { WorkspaceInboxCountContext } from "@application/hub/workspace-inbox-count-context"
import { useNotificationInbox } from "@hooks/use-notification-inbox"
import { NotificationsPage } from "@pages/notifications-page"
import { notificationInboxConfiguration } from "@utils/notification/inbox-configuration"

export function RealInboxScreen({ workspace }: { workspace: WorkspaceResponse }) {
const [search, setSearch] = useSearchParams()
const onUnreadCountChange = useContext(WorkspaceInboxCountContext)
const inbox = useNotificationInbox({
path: notificationInboxConfiguration.path,
authenticityToken: "",
unreadOnly: search.get("unread") === "true",
synchronize: true,
onUnreadCountChange,
viewerId: workspace.viewer.id,
})
return (
<NotificationsPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export function workspaceNavigation(
notificationInbox: inboxConnected
? { ...notificationInboxConfiguration, connected: true }
: undefined,
notificationsUnread: false,
notificationsUnreadCount: 0,
notificationsUnreadLabel: "Inbox, 0 unread",
notificationsUnread: workspace.inboxHasUnread,
inboxViewerId: workspace.viewer.id,
administrationLinks: admin
? [
{
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions hub/client/components/repository-navigation-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type RepositoryNavigationItemProps = {
icon: ElementType
label: string
ariaLabel?: string
count?: number
} & (
| {
href: string
Expand All @@ -27,7 +26,6 @@ type RepositoryNavigationItemProps = {
/** Renders a sidebar destination or a control with the same row treatment. */
export function RepositoryNavigationItem({
ariaLabel,
count,
expanded,
external = false,
href,
Expand All @@ -42,19 +40,13 @@ export function RepositoryNavigationItem({
<Icon size={16} />
</span>
<span className="repository-navigation-item__label">{label}</span>
{count !== undefined && count > 0 ? (
<span className="repository-navigation-item__count" aria-hidden="true">
{count}
</span>
) : null}
</>
)

return href !== undefined ? (
<a
href={href}
className="repository-navigation-item"
data-has-count={count !== undefined && count > 0 ? "true" : undefined}
data-active={selected ? "true" : undefined}
aria-current={selected ? "page" : undefined}
aria-label={ariaLabel}
Expand All @@ -68,7 +60,6 @@ export function RepositoryNavigationItem({
<button
type="button"
className="repository-navigation-item"
data-has-count={count !== undefined && count > 0 ? "true" : undefined}
aria-expanded={expanded}
onClick={onClick}
>
Expand Down
35 changes: 0 additions & 35 deletions hub/client/components/repository-navigation-item/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,6 @@
white-space: nowrap;
}

.repository-navigation-item[data-has-count="true"] .repository-navigation-item__label {
width: auto;
flex: 1;
}

.repository-navigation-item__count {
position: relative;
z-index: 1;
display: inline-flex;
min-width: 1.375rem;
height: 1.375rem;
margin-inline-end: 0.5rem;
padding-inline: 0.375rem;
border-radius: 1rem;
background: var(--hub-primary-bg);
color: var(--hub-primary-fg);
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 0.75rem;
font-weight: 600;
}

.repository-navigation[data-collapsed="true"] .repository-navigation-item__count {
position: absolute;
top: 0;
right: 0;
min-width: 1.125rem;
height: 1.125rem;
margin: 0;
padding-inline: 0.25rem;
border: 2px solid var(--hub-canvas-muted);
font-size: 0.625rem;
}

.repository-navigation[data-collapsed="true"] .repository-navigation-item__label {
width: 0;
}
Expand Down
Loading
Loading