1
1
import styled from '@emotion/styled' ;
2
- import qs from 'query-string' ;
3
2
4
3
import { LinkButton } from 'sentry/components/core/button/linkButton' ;
5
4
import { Flex } from 'sentry/components/core/layout' ;
6
5
import { IconArrow } from 'sentry/icons' ;
7
- import { useStoryBookFilesByCategory } from 'sentry/stories/view/storySidebar' ;
8
- import type { StoryTreeNode } from 'sentry/stories/view/storyTree' ;
9
- import type { StoryDescriptor } from 'sentry/stories/view/useStoriesLoader' ;
10
- import { useStory } from 'sentry/stories/view/useStory' ;
11
6
import { space } from 'sentry/styles/space' ;
12
- import { useLocation } from 'sentry/utils/useLocation' ;
13
7
14
- export function StoryFooter ( ) {
15
- const location = useLocation ( ) ;
8
+ import { useStoryBookFilesByCategory } from './storySidebar' ;
9
+ import type { StoryTreeNode } from './storyTree' ;
10
+ import { type StoryDescriptor } from './useStoriesLoader' ;
11
+ import { useStory } from './useStory' ;
16
12
13
+ export function StoryFooter ( ) {
17
14
const { story} = useStory ( ) ;
18
- const categories = useStoryBookFilesByCategory ( ) ;
19
- const pagination = findPreviousAndNextStory ( story , categories ) ;
20
-
21
- const prevLocationDescriptor = qs . stringify ( {
22
- ...location . query ,
23
- name : pagination ?. prev ?. story . filesystemPath ,
24
- } ) ;
25
- const nextLocationDescriptor = qs . stringify ( {
26
- ...location . query ,
27
- name : pagination ?. next ?. story . filesystemPath ,
28
- } ) ;
15
+ const stories = useStoryBookFilesByCategory ( ) ;
16
+ const pagination = findPreviousAndNextStory ( story , stories ) ;
29
17
30
18
return (
31
19
< Flex align = "center" justify = "space-between" gap = { space ( 2 ) } >
32
20
{ pagination ?. prev && (
33
- < Card
34
- to = { `/stories/?${ prevLocationDescriptor } ` }
35
- icon = { < IconArrow direction = "left" /> }
36
- >
21
+ < Card to = { pagination . prev . location } icon = { < IconArrow direction = "left" /> } >
37
22
< CardLabel > Previous</ CardLabel >
38
- < CardTitle > { pagination . prev . story . label } </ CardTitle >
23
+ < CardTitle > { pagination . prev . label } </ CardTitle >
39
24
</ Card >
40
25
) }
41
26
{ pagination ?. next && (
42
27
< Card
43
28
data-flip
44
- to = { `/stories/? ${ nextLocationDescriptor } ` }
29
+ to = { pagination . next . location }
45
30
icon = { < IconArrow direction = "right" /> }
46
31
>
47
32
< CardLabel > Next</ CardLabel >
48
- < CardTitle > { pagination . next . story . label } </ CardTitle >
33
+ < CardTitle > { pagination . next . label } </ CardTitle >
49
34
</ Card >
50
35
) }
51
36
</ Flex >
@@ -56,14 +41,11 @@ function findPreviousAndNextStory(
56
41
story : StoryDescriptor ,
57
42
categories : ReturnType < typeof useStoryBookFilesByCategory >
58
43
) : {
59
- next : { category : string ; story : StoryTreeNode } | undefined ;
60
- prev : { category : string ; story : StoryTreeNode } | undefined ;
44
+ next ?: StoryTreeNode ;
45
+ prev ?: StoryTreeNode ;
61
46
} | null {
62
- const stories = Object . entries ( categories ) . flatMap ( ( [ key , category ] ) =>
63
- category . map ( s => ( { category : key , story : s } ) )
64
- ) ;
65
-
66
- const currentIndex = stories . findIndex ( s => s . story . filesystemPath === story . filename ) ;
47
+ const stories = Object . values ( categories ) . flat ( ) ;
48
+ const currentIndex = stories . findIndex ( s => s . filesystemPath === story . filename ) ;
67
49
68
50
if ( currentIndex === - 1 ) {
69
51
return null ;
0 commit comments