-
Notifications
You must be signed in to change notification settings - Fork 0
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: prevent LibraryLayout remount #79
base: jill/fal-3984-fix-autofocus
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
Tabs, | ||
} from '@openedx/paragon'; | ||
import { useCallback } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; | ||
import { useLibraryContext } from '../common/context/LibraryContext'; | ||
|
@@ -24,6 +25,7 @@ | |
|
||
const CollectionInfo = () => { | ||
const intl = useIntl(); | ||
const navigate = useNavigate(); | ||
|
||
const { componentPickerMode } = useComponentPickerContext(); | ||
const { libraryId, setCollectionId } = useLibraryContext(); | ||
|
@@ -48,7 +50,7 @@ | |
if (componentPickerMode) { | ||
setCollectionId(collectionId); | ||
} else { | ||
navigateTo({ collectionId }); | ||
navigate(`/library/${libraryId}/collection/${collectionId}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this to differentiate "Open the collection on the sidebar" from "Open the collection page". We could add a parameter to I liked the way you did the |
||
} | ||
}, [componentPickerMode, navigateTo]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,13 +82,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => { | |
route = ROUTES.HOME; | ||
} else if (insideCollections) { | ||
// We're inside the Collections tab, | ||
route = ( | ||
(collectionId && collectionId === params.collectionId) | ||
// now open the previously-selected collection, | ||
? ROUTES.COLLECTION | ||
Comment on lines
-87
to
-88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing a redirect to the Collection page on a second click on the collection card. |
||
// or stay there to list all collections, or a selected collection. | ||
: ROUTES.COLLECTIONS | ||
); | ||
route = ROUTES.COLLECTIONS; | ||
} else if (insideCollection) { | ||
// We're viewing a Collection, so stay there, | ||
// and optionally select a component in that collection. | ||
|
@@ -103,13 +97,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => { | |
route = ROUTES.COMPONENT; | ||
} else { | ||
// We're inside the All Content tab, | ||
route = ( | ||
(collectionId && collectionId === params.collectionId) | ||
// now open the previously-selected collection | ||
? ROUTES.COLLECTION | ||
// or stay there to list all content, or optionally select a collection. | ||
: ROUTES.HOME | ||
); | ||
route = ROUTES.HOME; | ||
} | ||
|
||
const newPath = generatePath(BASE_ROUTE + route, routeParams); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the issue where the LibraryProvider was being remounted when the location.pathname changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were we trying to force a re-render before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we navigated to the Collection Page before, the first render still had
collectionId = undefined
. Remounting the context provider fixed that. It wasn't the best workaround, but it didn't cause many side effects at the time.