Skip to content

Commit

Permalink
remove scroll routes
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 20, 2024
1 parent d60626a commit 8c9db00
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { CssBaseline, ThemeProvider } from "@mui/material"
import { type ThemeProviderProps } from "@mui/material/styles/ThemeProvider"
import { useCallback, type FC, type ReactNode } from "react"
import { Provider, type ProviderProps } from "react-redux"
import { BrowserRouter } from "react-router-dom"
import { BrowserRouter, Routes as RouterRoutes } from "react-router-dom"
import { type Action } from "redux"

import { ScrollRoutes } from "./router"
import { InactiveDialog, ScreenTimeDialog } from "../features"
import { useCountdown, useEventListener, useLocation } from "../hooks"
// import "../scripts"
Expand Down Expand Up @@ -43,7 +42,7 @@ const Routes: FC<
return (
<>
{!headerExcludePaths.includes(pathname) && header}
<ScrollRoutes>{routes}</ScrollRoutes>
<RouterRoutes>{routes}</RouterRoutes>
{!footerExcludePaths.includes(pathname) && footer}
</>
)
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
25 changes: 0 additions & 25 deletions src/components/router/ScrollRoutes.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ export * from "./LinkTab"
export { default as LinkTab } from "./LinkTab"
export * from "./Navigate"
export { default as Navigate } from "./Navigate"
export * from "./ScrollRoutes"
export { default as ScrollRoutes } from "./ScrollRoutes"

0 comments on commit 8c9db00

Please sign in to comment.