-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from wyne/android-menu
- Loading branch information
Showing
8 changed files
with
289 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
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 { AnyAction, ThunkDispatch } from '@reduxjs/toolkit'; | ||
import { Alert, Platform } from 'react-native'; | ||
|
||
import { gameDelete, selectGameById } from '../../../redux/GamesSlice'; | ||
import { useAppDispatch, useAppSelector } from '../../../redux/hooks'; | ||
|
||
import AndroidPopupMenu from './AndroidPopupMenu'; | ||
import IOSPopupMenu from './IOSPopupMenu'; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
gameId: string; | ||
navigation: NativeStackNavigationProp<ParamListBase, string, undefined>; | ||
asyncSetCurrentGame: (dispatch: ThunkDispatch<unknown, undefined, AnyAction>) => Promise<void>; | ||
chooseGameHandler: () => void; | ||
index: number; | ||
} | ||
|
||
const AbstractPopupMenu: React.FC<Props> = (props) => { | ||
const dispatch = useAppDispatch(); | ||
|
||
if (props.gameId == null) { return null; } | ||
const gameTitle = useAppSelector(state => selectGameById(state, props.gameId)?.title); | ||
const roundTotal = useAppSelector(state => selectGameById(state, props.gameId)?.roundTotal); | ||
const playerIds = useAppSelector(state => selectGameById(state, props.gameId)?.playerIds); | ||
if (roundTotal == null || playerIds == null) { return null; } | ||
|
||
/** | ||
* Share Game | ||
*/ | ||
const shareGameHandler = async () => { | ||
props.asyncSetCurrentGame(dispatch).then(() => { | ||
props.navigation.navigate("Share"); | ||
}); | ||
|
||
await analytics().logEvent('menu_share', { | ||
round_count: roundTotal, | ||
player_count: playerIds.length, | ||
}); | ||
}; | ||
|
||
/** | ||
* Edit Game | ||
*/ | ||
const editGameHandler = async () => { | ||
props.asyncSetCurrentGame(dispatch).then(() => { | ||
props.navigation.navigate("Settings", { reason: 'edit_game' }); | ||
}); | ||
|
||
await analytics().logEvent('menu_edit', { | ||
round_count: roundTotal, | ||
player_count: playerIds.length, | ||
}); | ||
}; | ||
|
||
/** | ||
* Delete Game | ||
*/ | ||
const deleteGameHandler = async () => { | ||
Alert.alert( | ||
'Delete Game', | ||
`Are you sure you want to delete ${gameTitle}?`, | ||
[ | ||
{ | ||
text: 'Cancel', | ||
onPress: () => { }, | ||
style: 'cancel', | ||
}, | ||
{ | ||
text: 'OK', | ||
onPress: () => { | ||
dispatch(gameDelete(props.gameId)); | ||
} | ||
}, | ||
], | ||
{ cancelable: false }, | ||
); | ||
|
||
await analytics().logEvent('delete_game', { | ||
index: props.index, | ||
round_count: roundTotal, | ||
player_count: playerIds.length, | ||
}); | ||
}; | ||
|
||
return Platform.select({ | ||
ios: ( | ||
<IOSPopupMenu | ||
gameTitle={gameTitle} | ||
editGameHandler={editGameHandler} | ||
shareGameHandler={shareGameHandler} | ||
deleteGameHandler={deleteGameHandler} | ||
> | ||
{props.children} | ||
</IOSPopupMenu> | ||
), | ||
android: ( | ||
<AndroidPopupMenu | ||
gameTitle={gameTitle} | ||
chooseGameHandler={props.chooseGameHandler} | ||
editGameHandler={editGameHandler} | ||
shareGameHandler={shareGameHandler} | ||
deleteGameHandler={deleteGameHandler} | ||
> | ||
{props.children} | ||
</AndroidPopupMenu> | ||
), | ||
}); | ||
}; | ||
|
||
export default AbstractPopupMenu; |
Oops, something went wrong.