Skip to content

Commit

Permalink
fix opening document issue (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur authored Aug 10, 2024
1 parent 16b3224 commit f4dfbdc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 12 additions & 1 deletion ui2/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useLocation} from "react-router-dom"
import {useEffect, useRef} from "react"
import "@mantine/core/styles.css"
import {AppShell} from "@mantine/core"
Expand All @@ -21,6 +22,7 @@ import Uploader from "@/components/Uploader"
function App() {
const {height, width} = useViewportSize()
const navigate = useNavigate()
const location = useLocation()
const dispatch = useDispatch()
const status = useSelector(selectCurrentUserStatus)
const error = useSelector(selectCurrentUserError)
Expand All @@ -29,7 +31,16 @@ function App() {
const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
if (status == "succeeded" && user) {
/* notice *EXACT match* of the root route.
Without it, user will always be redirected to home folder,
even when he/she opens a document via direct url pasting in browser */
if (status == "succeeded" && user && location.pathname == "/") {
/*
This code addresses following problem: what happens when user lands
on root route (i.e. "/")?
Without any code change - the app shell will be render an empty outlet!!!
What we need though is to render "home" folder by default.
*/
navigate(`/home/${user.home_folder_id}`)
}
}, [status])
Expand Down
3 changes: 1 addition & 2 deletions ui2/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const router = createBrowserRouter([
{
path: "/home/:folderId",
element: <Home />,
loader: homeLoader,
index: true
loader: homeLoader
},
{
path: "/inbox/:folderId",
Expand Down

0 comments on commit f4dfbdc

Please sign in to comment.