Skip to content

Commit 403486e

Browse files
committed
track add/remove source/language
1 parent b84849f commit 403486e

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/components/Elements/ChipsSet/ChipsSet.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ const Chip = ({ option, onSelect, active = false }: ChipProps) => {
1616
</button>
1717
)
1818
}
19-
type ChangeAction = 'ADD' | 'REMOVE'
19+
type ChangeAction = {
20+
option: Option
21+
action: 'ADD' | 'REMOVE'
22+
}
2023
type ChipsSetProps = {
2124
options: Option[]
2225
className?: string
2326
defaultValues?: string[]
2427
canSelectMultiple?: boolean
25-
onChange?: (action: ChangeAction, options: Option[]) => void
28+
onChange?: (changes: ChangeAction, options: Option[]) => void
2629
}
2730

2831
export const ChipsSet = ({
@@ -43,7 +46,10 @@ export const ChipsSet = ({
4346
setSelectedChips(newVal)
4447
onChange &&
4548
onChange(
46-
'REMOVE',
49+
{
50+
option,
51+
action: 'REMOVE',
52+
},
4753
options.filter((opt) => newVal.some((selectedVal) => selectedVal === opt.value))
4854
)
4955
} else {
@@ -57,7 +63,10 @@ export const ChipsSet = ({
5763
setSelectedChips(newVal)
5864
onChange &&
5965
onChange(
60-
'ADD',
66+
{
67+
option,
68+
action: 'ADD',
69+
},
6170
options.filter((opt) => newVal.some((selectedVal) => selectedVal === opt.value))
6271
)
6372
}

src/features/settings/components/SourceSettings.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ChipsSet } from 'src/components/Elements'
22
import { SettingsContentLayout } from 'src/components/Layout/SettingsContentLayout/SettingsContentLayout'
33
import { SUPPORTED_CARDS } from 'src/config/supportedCards'
4+
import { trackSourceAdd, trackSourceRemove } from 'src/lib/analytics'
45
import { useUserPreferences } from 'src/stores/preferences'
56
import { SelectedCard } from 'src/types'
67
import { RssSetting } from './RssSetting'
78

89
export const SourceSettings = () => {
910
const { cards, setCards, userCustomCards } = useUserPreferences()
10-
console.log('new cards', cards)
11+
1112
const mergedSources = [
1213
...SUPPORTED_CARDS.map((source) => {
1314
return {
@@ -41,7 +42,7 @@ export const SourceSettings = () => {
4142
canSelectMultiple={true}
4243
options={mergedSources}
4344
defaultValues={defaultValues}
44-
onChange={(_, selectedChips) => {
45+
onChange={(changes, selectedChips) => {
4546
const selectedValues = selectedChips.map((chip) => chip.value)
4647

4748
const cards = (selectedValues
@@ -56,6 +57,12 @@ export const SourceSettings = () => {
5657
}) || []) as SelectedCard[]
5758

5859
setCards(cards)
60+
61+
if (changes.action == 'ADD') {
62+
trackSourceAdd(changes.option.value)
63+
} else {
64+
trackSourceRemove(changes.option.value)
65+
}
5966
}}
6067
/>
6168
<hr />

src/features/settings/components/TopicSettings.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChipsSet } from 'src/components/Elements'
22
import { SettingsContentLayout } from 'src/components/Layout/SettingsContentLayout/SettingsContentLayout'
33
import { Tag, useRemoteConfigStore } from 'src/features/remoteConfig'
4+
import { trackLanguageAdd, trackLanguageRemove } from 'src/lib/analytics'
45
import { useUserPreferences } from 'src/stores/preferences'
56

67
export const TopicSettings = () => {
@@ -25,12 +26,18 @@ export const TopicSettings = () => {
2526
canSelectMultiple={true}
2627
options={tags}
2728
defaultValues={userSelectedTags.map((tag) => tag.value)}
28-
onChange={(_, selectedChips) => {
29+
onChange={(changes, selectedChips) => {
2930
const selectedTags =
3031
(selectedChips
3132
.map((tag) => supportedTags.find((st) => st.value === tag.value))
3233
.filter(Boolean) as Tag[]) || []
3334
setTags(selectedTags)
35+
36+
if (changes.action == 'ADD') {
37+
trackLanguageAdd(changes.option.value)
38+
} else {
39+
trackLanguageRemove(changes.option.value)
40+
}
3441
}}
3542
/>
3643
</SettingsContentLayout>

0 commit comments

Comments
 (0)