Skip to content

Commit

Permalink
updated search tracking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
okeino committed Dec 12, 2023
1 parent c5ace63 commit 3db56a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
15 changes: 5 additions & 10 deletions src/components/molecules/buttonPlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ export default function ButtonPlay({
prefersAudio?: boolean;
className?: string;
}): JSX.Element {
const { isPaused, play, pause, trackPlay, trackPause } = usePlaybackSession(
recording,
{
playlistRecordings,
prefersAudio,
}
);
const { isPaused, play, pause } = usePlaybackSession(recording, {
playlistRecordings,
prefersAudio,
});
const intl = useIntl();

const label = isPaused
Expand All @@ -73,9 +70,7 @@ export default function ButtonPlay({
? IconPauseLarge
: IconPause
}
onClick={() =>
isPaused ? (play(), trackPlay()) : (pause(), trackPause())
}
onClick={() => (isPaused ? play() : pause())}
color={
active
? isBackgroundColorDark(backgroundColor)
Expand Down
4 changes: 1 addition & 3 deletions src/components/molecules/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ const Player = ({
(shouldShowPoster || posterHovered) && styles.posterPlayShown
)}
onClick={() =>
session.isPaused
? (session.play(), session.trackPlay())
: (session.pause(), session.trackPause())
session.isPaused ? session.play() : session.pause()
}
onTouchStart={() => setPosterHovered(true)}
onTouchEnd={() => setPosterHovered(false)}
Expand Down
5 changes: 3 additions & 2 deletions src/components/molecules/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default function SearchBar({
useEffect(() => {
if (isFocused) {
document.addEventListener('keydown', handleSubmit);
analytics.track('search', { term: term });
} else {
document.removeEventListener('keydown', handleSubmit);
}
Expand Down Expand Up @@ -87,7 +86,9 @@ export default function SearchBar({
value={term ?? ''}
onChange={({ target }) => onTermChange(target.value)}
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
onBlur={() => {
setIsFocused(false), analytics.track('search', { term: term });
}}
placeholder={
isFocused
? ''
Expand Down
2 changes: 2 additions & 0 deletions src/lib/usePlaybackSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ export default function usePlaybackSession(
// TODO: Maybe only if `isLoaded` is true
// Or perhaps throw an exception, since the user should never be presented
// with a pause button for a recording that isn't loaded.
trackPause();
context.pause();
}

function play() {
trackPlay();
afterLoad((c) => c.play());
}

Expand Down

0 comments on commit 3db56a8

Please sign in to comment.