Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Portal frontend 5 #60

Merged
merged 2 commits into from
Sep 20, 2024
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
23 changes: 0 additions & 23 deletions src/components/ScrollRoutes.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export * from "./ItemizedList"
export { default as ItemizedList } from "./ItemizedList"
export * from "./OrderedGrid"
export { default as OrderedGrid } from "./OrderedGrid"
export * from "./ScrollRoutes"
export { default as ScrollRoutes } from "./ScrollRoutes"
export * from "./SyncError"
export { default as SyncError } from "./SyncError"
export * from "./TablePagination"
Expand Down
48 changes: 23 additions & 25 deletions src/components/page/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Children } from "react"
import { Children, useEffect } from "react"
import { useLocation, type Location } from "react-router-dom"

import {
Expand All @@ -15,6 +15,7 @@ export type PageState = {
index?: number
props: NotificationProps
}>
scroll: { x: number; y: number }
}

export interface PageProps<
Expand All @@ -30,7 +31,15 @@ const Page = <
children,
session,
}: PageProps<SessionUserType>): JSX.Element => {
const { state } = useLocation() as Location<unknown>
const { state } = useLocation() as Location<null | Partial<PageState>>

let { scroll, notifications } = state || {}
scroll = scroll || { x: 0, y: 0 }
notifications = notifications || []

useEffect(() => {
window.scroll(scroll.x, scroll.y)
}, [scroll.x, scroll.y])

return (
<>
Expand All @@ -41,32 +50,21 @@ const Page = <
: (children as UseSessionChildrenFunction<false>)(metadata)
}

const childrenArray = Children.toArray(children)
if (notifications.length) {
const childrenArray = Children.toArray(children)

notifications.forEach((notification, index) => {
childrenArray.splice(
notification.index ?? index,
0,
<Notification {...notification.props} />,
)
})

if (
typeof state === "object" &&
state !== null &&
"notifications" in state &&
Array.isArray(state.notifications) &&
state.notifications.every(
(notification: unknown) =>
typeof notification === "object" &&
notification !== null &&
"props" in notification,
)
) {
;(state.notifications as PageState["notifications"]).forEach(
(notification, index) => {
childrenArray.splice(
notification.index ?? index,
0,
<Notification {...notification.props} />,
)
},
)
return childrenArray
}

return childrenArray
return children
}, session)}
</>
)
Expand Down