-
Notifications
You must be signed in to change notification settings - Fork 5
Collections Navigation Bug Fix #692
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d6181dd
efb1894
c94e4d4
cfaa9fc
3816a17
413ef98
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 |
|---|---|---|
|
|
@@ -13,6 +13,23 @@ interface NewEditedCollectionForm { | |
| thumbnail: File | null | ||
| } | ||
|
|
||
| interface MenuItemLike { | ||
| label: string | ||
| path: string | ||
| items?: ReadonlyArray<MenuItemLike> | null | ||
| } | ||
|
|
||
| const toMenuItemInput = ( | ||
| nodes: ReadonlyArray<MenuItemLike> | null | undefined | ||
| ): ReadonlyArray<Dailp.MenuItemInput> | null => { | ||
| if (!nodes?.length) return null | ||
| return nodes.map((n) => ({ | ||
| label: n.label, | ||
| path: n.path, | ||
| items: toMenuItemInput(n.items), | ||
| })) | ||
| } | ||
|
|
||
| const NewEditedCollectionPage = () => { | ||
| const { user } = useUser() | ||
| const [formData, setFormData] = useState<NewEditedCollectionForm>({ | ||
|
|
@@ -23,6 +40,10 @@ const NewEditedCollectionPage = () => { | |
| const [isSubmitting, setIsSubmitting] = useState(false) | ||
| const [error, setError] = useState<string | null>(null) | ||
| const [, addEditedCollection] = Dailp.useAddEditedCollectionMutation() | ||
| const [, updateMenu] = Dailp.useUpdateMenuMutation() | ||
| const [{ data: menuData }] = Dailp.useMenuBySlugQuery({ | ||
| variables: { slug: "default-nav" }, | ||
| }) | ||
|
|
||
| const handleEditedCollectionSubmit = async ( | ||
| e: React.FormEvent<HTMLFormElement> | ||
|
|
@@ -60,8 +81,41 @@ const NewEditedCollectionPage = () => { | |
| "Successfully created collection with ID:", | ||
| result.data.createEditedCollection | ||
| ) | ||
|
|
||
| const newSlug = result.data.createEditedCollection | ||
| const menu = menuData?.menuBySlug | ||
| if (menu) { | ||
| const updatedItems: MenuItemLike[] = (menu.items ?? []).map( | ||
| (item) => { | ||
| if (item.label.toLowerCase() === "collections") { | ||
| return { | ||
| label: item.label, | ||
| path: item.path, | ||
| items: [ | ||
| ...(item.items ?? []), | ||
| { | ||
| label: formData.title, | ||
| path: `/collections/${newSlug}`, | ||
| items: [], | ||
| }, | ||
| ], | ||
| } | ||
| } | ||
| return item | ||
| } | ||
| ) | ||
|
|
||
| updateMenu({ | ||
| menu: { | ||
| id: menu.id, | ||
| name: menu.name, | ||
| items: toMenuItemInput(updatedItems), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // Navigate to the new collection or show success message | ||
| navigate(`/collections/${result.data.createEditedCollection}`) | ||
| navigate(`/collections/${newSlug}`) | ||
| } else { | ||
|
Collaborator
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. After I create a new collection, I get taken to a blank page
Collaborator
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. Based on the logs, it seems like creating the edited collection works, but it breaks when attempting to navigate to the new page (
Collaborator
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. It seems like the collections here use the id for the collection page slugs (ex. new collection page slug is
Collaborator
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. You might want to add a query to return the slug instead of the id or add a new query to fetch the slug
Collaborator
Author
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. The slug returning the id and navigating to what seems to be
Collaborator
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. That sounds good! I was just wondering if that was causing the issue |
||
| console.log("No data returned from mutation") | ||
| setError("No data returned from mutation") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.