Skip to content

Commit

Permalink
Fix game settings page navigation on first create
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Apr 18, 2024
1 parent 543bf0d commit cd2ba91
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type RootStackParamList = {
List: undefined;
Game: undefined;
Settings: {
reason?: string;
source?: string;
};
AppInfo: undefined;
Share: undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Buttons/CheckButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('CheckButton', () => {
const navigation = useNavigationMock();

it.skip('should navigate to Game screen when pressed', async () => {
const { getByRole } = render(<CheckButton navigation={navigation} route={{ key: 'Settings', name: 'Settings', params: { reason: 'new_game' } }} />);
const { getByRole } = render(<CheckButton navigation={navigation} route={{ key: 'Settings', name: 'Settings', params: { source: 'new_game' } }} />);
const button = getByRole('button');
await waitFor(() => {
fireEvent.press(button);
Expand All @@ -18,7 +18,7 @@ describe('CheckButton', () => {
});

it.skip('should navigate back a screen when pressed', async () => {
const { getByRole } = render(<CheckButton navigation={navigation} route={{ key: 'Settings', name: 'Settings', params: { reason: '' } }} />);
const { getByRole } = render(<CheckButton navigation={navigation} route={{ key: 'Settings', name: 'Settings', params: { source: '' } }} />);
const button = getByRole('button');
await waitFor(() => {
fireEvent.press(button);
Expand Down
9 changes: 4 additions & 5 deletions src/components/Buttons/CheckButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HeaderButton from './HeaderButton';

type RouteParams = {
Settings: {
reason?: string;
source?: string;
};
};
interface Props {
Expand All @@ -24,11 +24,10 @@ const CheckButton: React.FunctionComponent<Props> = ({ navigation, route }) => {
return (
<HeaderButton accessibilityLabel='Save Game' onPress={async () => {
await analytics().logEvent('save_game');
if (route?.params?.reason === 'new_game') {
navigation.navigate('Game');
if (route?.params?.source === 'list_screen') {
navigation.navigate('List');
} else {
//TODO: when the game is first created, this will go back instead of to game screen
navigation.goBack();
navigation.navigate('Game');
}
}}>
<Text style={{ color: systemBlue, fontSize: 20 }}>Done</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Buttons/NewGameButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NewGameButton: React.FunctionComponent<Props> = ({ navigation }) => {
})
).then(() => {
setTimeout(() => {
navigation.navigate('Settings', { reason: 'new_game' });
navigation.navigate('Settings', { source: 'new_game' });
}, 500);
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Headers/SettingsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CustomHeader from './CustomHeader';

type RouteParams = {
Settings: {
reason?: string;
source?: string;
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/PopupMenu/AbstractPopupMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const AbstractPopupMenu: React.FC<Props> = (props) => {
*/
const editGameHandler = async () => {
props.setCurrentGameCallback();
props.navigation.navigate('Settings', { reason: 'edit_game' });
props.navigation.navigate('Settings', { source: 'list_screen' });

await analytics().logEvent('menu_edit', {
round_count: roundTotal,
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import logger from '../Logger';

type RouteParams = {
Settings: {
reason?: string;
source?: string;
};
};

Expand Down

0 comments on commit cd2ba91

Please sign in to comment.