Skip to content

Commit

Permalink
Merge pull request #488 from wyne/edit-player-analytics
Browse files Browse the repository at this point in the history
Fix edit player analytics
  • Loading branch information
wyne authored Aug 4, 2024
2 parents 0b21442 + d80b337 commit 570177d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/components/PlayerListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const PlayerListItem: React.FunctionComponent<Props> = ({
onPress={() => {
if (edit) { return; }
navigation.navigate('EditPlayer', { playerId: playerId, index: index });

logEvent('edit_player', {
game_id: currentGameId,
player_index: index,
});
}}
disabled={isActive}
style={[{
Expand Down
20 changes: 12 additions & 8 deletions src/screens/EditPlayerScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { ParamListBase, RouteProp } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
Expand Down Expand Up @@ -46,6 +46,14 @@ const EditPlayerScreen: React.FC<EditPlayerScreenProps> = ({
if (typeof currentGame == 'undefined') return null;
if (index == null) { return null; }

const [nameChanged, setNameChanged] = useState(false);

useEffect(() => {
if (nameChanged) {
logEvent('player_name_changed');
}
}, [nameChanged]);

const onEndEditingHandler = (e: NativeSyntheticEvent<TextInputEndEditingEventData>) => {
const text = e.nativeEvent.text;

Expand Down Expand Up @@ -73,13 +81,6 @@ const EditPlayerScreen: React.FC<EditPlayerScreenProps> = ({
playerName: text,
}
}));

logEvent('update_player', {
game_id: currentGame.id,
player_index: index,
});

// navigation.goBack();
};

const inputRef = React.useRef<TextInput>(null);
Expand Down Expand Up @@ -111,6 +112,9 @@ const EditPlayerScreen: React.FC<EditPlayerScreenProps> = ({
maxLength={15}
onChangeText={onChangeHandler}
onEndEditing={onEndEditingHandler}
onTextInput={() => {
setNameChanged(true);
}}
placeholder='Player Name'
renderErrorMessage={false}
selectTextOnFocus={true}
Expand Down

0 comments on commit 570177d

Please sign in to comment.