-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
stories: remove location.state from storybook routing #102760
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
Changes from all commits
775c7cc
135dff5
11ab6ab
9c8b6f1
18cebd0
26f521b
f57dd73
9d29c02
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 |
|---|---|---|
|
|
@@ -18,20 +18,15 @@ export function StoryFooter() { | |
| const pagination = findPreviousAndNextStory(story, stories); | ||
| const organization = useOrganization(); | ||
|
|
||
| const {state: prevState, ...prevTo} = pagination?.prev?.location ?? {}; | ||
| const {state: nextState, ...nextTo} = pagination?.next?.location ?? {}; | ||
|
|
||
| return ( | ||
| <Flex align="center" justify="between" gap="xl"> | ||
| {pagination?.prev && ( | ||
| <Card | ||
| to={{ | ||
| ...prevTo, | ||
| pathname: normalizeUrl( | ||
| `/organizations/${organization.slug}${pagination.prev.location.pathname}` | ||
| `/organizations/${organization.slug}/stories/${pagination.prev.category}/${pagination.prev.slug}` | ||
| ), | ||
| }} | ||
| state={prevState} | ||
| icon={<IconArrow direction="left" />} | ||
| > | ||
| <Text variant="muted" as="div"> | ||
|
|
@@ -46,12 +41,10 @@ export function StoryFooter() { | |
| <Card | ||
| data-flip | ||
| to={{ | ||
| ...nextTo, | ||
| pathname: normalizeUrl( | ||
| `/organizations/${organization.slug}${nextTo.pathname}` | ||
| `/organizations/${organization.slug}/stories/${pagination.next.category}/${pagination.next.slug}` | ||
| ), | ||
| }} | ||
| state={nextState} | ||
| icon={<IconArrow direction="right" />} | ||
| > | ||
| <Text variant="muted" as="div" align="right"> | ||
|
|
@@ -74,16 +67,25 @@ function findPreviousAndNextStory( | |
| prev?: StoryTreeNode; | ||
| } | null { | ||
| const stories = Object.values(categories).flat(); | ||
| const currentIndex = stories.findIndex(s => s.filesystemPath === story.filename); | ||
| const queue = [...stories]; | ||
|
|
||
| while (queue.length > 0) { | ||
| const node = queue.pop(); | ||
| if (!node) break; | ||
|
|
||
| if (node.filesystemPath === story.filename) { | ||
| return { | ||
| prev: queue[queue.length - 1] ?? undefined, | ||
| next: queue[queue.length + 1] ?? undefined, | ||
|
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. Bug: The 🔍 Detailed AnalysisThe 💡 Suggested FixRe-implement the pagination logic in 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| }; | ||
| } | ||
|
|
||
| if (currentIndex === -1) { | ||
| return null; | ||
| for (const key in node.children) { | ||
| queue.push(node.children[key]!); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| prev: stories[currentIndex - 1] ?? undefined, | ||
| next: stories[currentIndex + 1] ?? undefined, | ||
| }; | ||
| return null; | ||
|
Contributor
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. Bug: Broken Pagination: Flatten Before Finding NeighborsThe pagination logic in |
||
| } | ||
|
|
||
| const Card = styled(LinkButton)` | ||
|
|
||
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 meant that we could only ever have category/name stories, and couldn't use the same structure for stories that like components/replay/... See eslint.config.mjs to see the routing difference now