Skip to content

Commit 398493b

Browse files
Add path to EventContext
1 parent ac2f3d5 commit 398493b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/services/events/hooks.test.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ describe('useEventContext', () => {
120120
}
121121

122122
describe('when called on owner page', () => {
123-
it('sets event context with ownerid and no repoid', async () => {
123+
it('sets event context with path, ownerid, and no repoid', async () => {
124124
setup({})
125125
renderHook(() => useEventContext(), {
126126
wrapper: ownerWrapper,
127127
})
128128

129129
await waitFor(() => {
130130
expect(mockedSetContext).toHaveBeenCalledWith({
131+
path: '/:provider/:owner',
131132
owner: {
132133
id: mockOwnerContext.owner.ownerid,
133134
},
@@ -138,14 +139,15 @@ describe('useEventContext', () => {
138139
})
139140

140141
describe('when called on repo page', () => {
141-
it('sets event context with ownerid and repoid', async () => {
142+
it('sets event context with path, ownerid, and repoid', async () => {
142143
setup({})
143144
renderHook(useEventContext, {
144145
wrapper: repoWrapper,
145146
})
146147

147148
await waitFor(() => {
148149
expect(mockedSetContext).toHaveBeenCalledWith({
150+
path: '/:provider/:owner/:repo',
149151
owner: {
150152
id: mockOwnerContext.owner.ownerid,
151153
},
@@ -167,6 +169,7 @@ describe('useEventContext', () => {
167169

168170
await waitFor(() => {
169171
expect(mockedSetContext).toHaveBeenCalledWith({
172+
path: '/:provider/:owner',
170173
owner: undefined,
171174
repo: undefined,
172175
})

src/services/events/hooks.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
useQuery as useQueryV5,
44
} from '@tanstack/react-queryV5'
55
import { useRef } from 'react'
6-
import { useParams } from 'react-router'
6+
import { useParams, useRouteMatch } from 'react-router'
77
import { z } from 'zod'
88

99
import {
@@ -26,6 +26,7 @@ export function useEventContext() {
2626
}>()
2727
const context = useRef<EventContext>({})
2828

29+
const { path } = useRouteMatch()
2930
const { data: ownerData } = useQueryV5(
3031
OwnerContextQueryOpts({ provider, owner })
3132
)
@@ -34,11 +35,13 @@ export function useEventContext() {
3435
)
3536

3637
if (
38+
path !== context.current.path ||
3739
ownerData?.ownerid !== context.current.owner?.id ||
3840
repoData?.repoid !== context.current.repo?.id
3941
) {
4042
// only update if this is a new owner or repo
4143
const newContext: EventContext = {
44+
path,
4245
owner: ownerData?.ownerid
4346
? {
4447
id: ownerData?.ownerid,

src/services/events/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type EventContext = {
5454
id: number
5555
isPrivate?: boolean
5656
}
57+
path?: string
5758
}
5859

5960
export abstract class EventTracker {

0 commit comments

Comments
 (0)