Skip to content

Commit e21280b

Browse files
committed
extract useLoadReplayReader from ReplayLoadingState, inject instead
1 parent f4296be commit e21280b

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

static/app/components/events/eventHydrationDiff/replayDiffContent.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {space} from 'sentry/styles/space';
1717
import type {Event} from 'sentry/types/event';
1818
import type {Group} from 'sentry/types/group';
1919
import {getReplayDiffOffsetsFromEvent} from 'sentry/utils/replays/getDiffTimestamps';
20+
import useLoadReplayReader from 'sentry/utils/replays/hooks/useLoadReplayReader';
21+
import useOrganization from 'sentry/utils/useOrganization';
2022
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
2123
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
2224

@@ -40,9 +42,17 @@ export default function ReplayDiffContent({event, group, orgSlug, replaySlug}: P
4042
);
4143
};
4244
}
45+
46+
const organization = useOrganization();
47+
const readerResult = useLoadReplayReader({
48+
orgSlug: organization.slug,
49+
replaySlug,
50+
clipWindow: undefined,
51+
});
52+
4353
return (
4454
<ReplayLoadingState
45-
replaySlug={replaySlug}
55+
readerResult={readerResult}
4656
renderArchived={wrapInSection(() => (
4757
<ArchivedReplayAlert message={t('The replay for this event has been deleted.')} />
4858
))}

static/app/components/replays/player/__stories__/replaySlugChooser.tsx

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {css} from '@emotion/react';
33

44
import Providers from 'sentry/components/replays/player/__stories__/providers';
55
import ReplayLoadingState from 'sentry/components/replays/player/replayLoadingState';
6+
import useLoadReplayReader from 'sentry/utils/replays/hooks/useLoadReplayReader';
7+
import useOrganization from 'sentry/utils/useOrganization';
68
import {useSessionStorage} from 'sentry/utils/useSessionStorage';
79

810
type Props =
@@ -14,33 +16,50 @@ export default function ReplaySlugChooser(props: Props) {
1416

1517
const [replaySlug, setReplaySlug] = useSessionStorage('stories:replaySlug', '');
1618

17-
let content = null;
18-
if (replaySlug) {
19-
if (children) {
20-
content = (
21-
<ReplayLoadingState replaySlug={replaySlug}>
19+
const input = (
20+
<input
21+
defaultValue={replaySlug}
22+
onChange={event => {
23+
setReplaySlug(event.target.value);
24+
}}
25+
placeholder="Paste a replaySlug"
26+
css={css`
27+
font-variant-numeric: tabular-nums;
28+
`}
29+
size={34}
30+
/>
31+
);
32+
33+
if (replaySlug && children) {
34+
function Content() {
35+
const organization = useOrganization();
36+
const readerResult = useLoadReplayReader({
37+
orgSlug: organization.slug,
38+
replaySlug,
39+
clipWindow: undefined,
40+
});
41+
return (
42+
<ReplayLoadingState readerResult={readerResult}>
2243
{({replay}) => <Providers replay={replay}>{children}</Providers>}
2344
</ReplayLoadingState>
2445
);
25-
} else if (render) {
26-
content = render(replaySlug);
2746
}
47+
return (
48+
<Fragment>
49+
{input}
50+
<Content />
51+
</Fragment>
52+
);
2853
}
2954

30-
return (
31-
<Fragment>
32-
<input
33-
defaultValue={replaySlug}
34-
onChange={event => {
35-
setReplaySlug(event.target.value);
36-
}}
37-
placeholder="Paste a replaySlug"
38-
css={css`
39-
font-variant-numeric: tabular-nums;
40-
`}
41-
size={34}
42-
/>
43-
{content}
44-
</Fragment>
45-
);
55+
if (replaySlug && render) {
56+
return (
57+
<Fragment>
58+
{input}
59+
{render(replaySlug)}
60+
</Fragment>
61+
);
62+
}
63+
64+
return null;
4665
}

static/app/components/replays/player/replayLoadingState.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,28 @@ import type {ReactNode} from 'react';
33
import LoadingIndicator from 'sentry/components/loadingIndicator';
44
import ArchivedReplayAlert from 'sentry/components/replays/alerts/archivedReplayAlert';
55
import MissingReplayAlert from 'sentry/components/replays/alerts/missingReplayAlert';
6-
import useLoadReplayReader from 'sentry/utils/replays/hooks/useLoadReplayReader';
6+
import type useLoadReplayReader from 'sentry/utils/replays/hooks/useLoadReplayReader';
77
import type ReplayReader from 'sentry/utils/replays/replayReader';
88
import useOrganization from 'sentry/utils/useOrganization';
99

10-
type ClipWindow = {
11-
// When to stop the replay, given it continues into that time
12-
endTimestampMs: number;
13-
14-
// When to start the replay, given its start time is early enough
15-
startTimestampMs: number;
16-
};
17-
1810
type ReplayReaderResult = ReturnType<typeof useLoadReplayReader>;
1911

2012
export default function ReplayLoadingState({
2113
children,
22-
replaySlug,
23-
clipWindow,
14+
readerResult,
2415
renderArchived,
2516
renderError,
2617
renderLoading,
2718
renderMissing,
2819
}: {
2920
children: (props: {replay: ReplayReader}) => ReactNode;
30-
replaySlug: string;
31-
clipWindow?: ClipWindow;
21+
readerResult: ReplayReaderResult;
3222
renderArchived?: (results: ReplayReaderResult) => ReactNode;
3323
renderError?: (results: ReplayReaderResult) => ReactNode;
3424
renderLoading?: (results: ReplayReaderResult) => ReactNode;
3525
renderMissing?: (results: ReplayReaderResult) => ReactNode;
3626
}) {
3727
const organization = useOrganization();
38-
const readerResult = useLoadReplayReader({
39-
orgSlug: organization.slug,
40-
replaySlug,
41-
clipWindow,
42-
});
4328

4429
if (readerResult.fetchError) {
4530
return renderError ? (

0 commit comments

Comments
 (0)