Skip to content

Commit

Permalink
Merge pull request #545 from cloudnativedaysjp/feat/include_talkid_in…
Browse files Browse the repository at this point in the history
…_mutate

feat: Include talkID in viewCount
  • Loading branch information
jacopen authored Feb 17, 2025
2 parents b50e50d + b904b4f commit 54aa29f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/components/TalkInfo/TalkInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const TalkInfo: React.FC<Props> = ({
eventAbbr,
profileId,
selectedTrack?.name,
selectedTalk?.id,
)
useEffect(() => {
return () => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/hooks/__tests__/useViewerCount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe.only('useViewerCount', () => {
profileId: 42,
trackName: 'B',
count: 5,
talkID: 10,
}
const got = {
count: 0,
Expand Down Expand Up @@ -58,6 +59,7 @@ describe.only('useViewerCount', () => {
given.confName,
given.profileId,
given.trackName,
given.talkID,
)
got.count = count
if (!!timer && !!count) {
Expand Down
10 changes: 6 additions & 4 deletions src/components/hooks/useViewerCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const useViewerCount = (
eventAbbr: string,
profileId: number | undefined,
selectedTrackName: string | undefined,
selectedTalkId: number | undefined,
): [number, NodeJS.Timeout | null] => {
const [viewerCounts, setViewerCounts] = useState<Record<string, number>>({})
const [curTrack, setCurTrack] = useState<string>('')
Expand All @@ -29,8 +30,8 @@ export const useViewerCount = (
})

const viewTrack = gql(`
mutation ViewTrack($profileID: Int!, $trackName: String!) {
viewTrack(input: { profileID: $profileID, trackName: $trackName })
mutation ViewTrack($profileID: Int!, $trackName: String!, $talkID: Int!) {
viewTrack(input: { profileID: $profileID, trackName: $trackName, talkID: $talkID })
}
`)
useEffect(() => {
Expand All @@ -56,7 +57,7 @@ export const useViewerCount = (
const [setViewTrack, { error: viewTrackError }] = useMutation(viewTrack)

useEffect(() => {
if (!profileId || !selectedTrackName) {
if (!profileId || !selectedTrackName || !selectedTalkId) {
return
}
if (selectedTrackName === curTrack) {
Expand All @@ -71,14 +72,15 @@ export const useViewerCount = (
variables: {
profileID: profileId,
trackName: selectedTrackName,
talkID: selectedTalkId,
},
})
}
mutate()
setTimer(setInterval(mutate, 30 * 1000))

setCurTrack(selectedTrackName)
}, [selectedTrackName, profileId, timer, curTrack])
}, [selectedTrackName, selectedTalkId, profileId, timer, curTrack])

useEffect(() => {
if (viewTrackError) {
Expand Down

0 comments on commit 54aa29f

Please sign in to comment.