Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of Life improvements 24-Q2 #419

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 35 additions & 6 deletions src/components/Headers/GameHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import React from 'react';
import analytics from '@react-native-firebase/analytics';
import { ParamListBase } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { Text, StyleSheet, TouchableOpacity } from 'react-native';
import * as Haptics from 'expo-haptics';
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
import { Button } from 'react-native-elements';
import { Icon } from 'react-native-elements/dist/icons/Icon';

import { roundNext, roundPrevious , selectGameById } from '../../../redux/GamesSlice';
import { roundNext, roundPrevious, selectGameById } from '../../../redux/GamesSlice';
import { useAppDispatch, useAppSelector } from '../../../redux/hooks';
import { systemBlue } from '../../constants';
import AddendButton from '../Buttons/AddendButton';
Expand Down Expand Up @@ -38,9 +39,10 @@ const PrevRoundButton: React.FunctionComponent<PrevRoundButtonProps> = ({ prevRo
interface NextRoundButtonProps {
nextRoundHandler: () => void;
visible: boolean;
showPlus?: boolean;
}

const NextRoundButton: React.FunctionComponent<NextRoundButtonProps> = ({ nextRoundHandler, visible }) => {
const NextRoundButton: React.FunctionComponent<NextRoundButtonProps> = ({ nextRoundHandler, visible, showPlus = false }) => {
return (
<TouchableOpacity style={[styles.headerButton]}
onPress={nextRoundHandler}>
Expand All @@ -50,6 +52,19 @@ const NextRoundButton: React.FunctionComponent<NextRoundButtonProps> = ({ nextRo
color={systemBlue}
style={{ opacity: visible ? 0 : 1 }}
/>
{showPlus &&
<Icon name="plus"
type="font-awesome-5"
size={7}
color={systemBlue}
containerStyle={{
position: 'absolute',
top: 9,
right: 9,
opacity: visible ? 0 : 1
}}
/>
}
</TouchableOpacity>
);
};
Expand Down Expand Up @@ -83,20 +98,31 @@ const GameHeader: React.FunctionComponent<Props> = ({ navigation }) => {
const nextRoundHandler = async () => {
if (isLastRound && currentGame.locked) return;

if (isLastRound) {
// Stronger haptics if creating a new round
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
} else {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}

dispatch(roundNext(currentGame.id));
await analytics().logEvent('round_change', {
analytics().logEvent('round_change', {
game_id: currentGameId,
source: 'next button',
round: roundCurrent,
});
};

const prevRoundHandler = async () => {
if (isFirstRound) return;

Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);

dispatch(roundPrevious(currentGame.id));
await analytics().logEvent('round_change', {
analytics().logEvent('round_change', {
game_id: currentGameId,
source: 'previous button',
round: roundCurrent,
});
};

Expand All @@ -109,7 +135,10 @@ const GameHeader: React.FunctionComponent<Props> = ({ navigation }) => {
headerCenter={<>
<PrevRoundButton prevRoundHandler={prevRoundHandler} visible={isFirstRound} />
<Text style={styles.title}>Round {roundCurrent + 1}</Text>
<NextRoundButton nextRoundHandler={nextRoundHandler} visible={isLastRound && (currentGame.locked || false)} />
<NextRoundButton nextRoundHandler={nextRoundHandler}
visible={isLastRound && (currentGame.locked || false)}
showPlus={isLastRound && !currentGame.locked}
/>
</>}
headerRight={!currentGame.locked && <AddendButton />}
/>
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