diff --git a/src/common/localization/de.js b/src/common/localization/de.js index 9af4e52..c4674a8 100644 --- a/src/common/localization/de.js +++ b/src/common/localization/de.js @@ -47,6 +47,22 @@ export default { ok: 'OK' }, game: { + assignments: { + title: 'Mordauftrag', + empty: 'Das Spiel hat noch begonnen', + current: { + claim: 'Dein aktueller Mordauftrag gilt %{target}' + }, + former: { + claim: 'Du hast %{target} erfolgreich ermordet' + }, + failed: { + claim: 'Du hast das vor %{target} das zeitliche gesegnet' + }, + leaved: { + claim: 'Du hast dich Feige aus dem Staub gemacht' + } + }, participants: { title: 'Teilnehmer' }, diff --git a/src/common/localization/en.js b/src/common/localization/en.js index 9c221bd..d54ecfb 100644 --- a/src/common/localization/en.js +++ b/src/common/localization/en.js @@ -47,6 +47,22 @@ export default { ok: 'OK' }, game: { + assignments: { + title: 'Murder assignment', + empty: 'Game has not started yet', + current: { + claim: 'Your current murder assignee is %{target}' + }, + former: { + claim: 'You have successfully murdered %{target}' + }, + failed: { + claim: 'You have died before killing %{target}' + }, + leaved: { + claim: 'You ran away like a coward' + } + }, participants: { title: 'Participants' }, diff --git a/src/common/types/game.js b/src/common/types/game.js index 59f3f78..b4a9f07 100644 --- a/src/common/types/game.js +++ b/src/common/types/game.js @@ -2,6 +2,7 @@ import type { GamePreferences, NewGamePreferences } from './gamePreferences' import type { NewPlayer, Player } from './player' +import type {MurderAssignment} from "./murderAssignment"; export const GAME_CODE_LENGTH = 6 export const MIN_GAME_TITLE_LENGTH = 3 @@ -23,5 +24,6 @@ export type Game = {| ...NewGame, preferences: GamePreferences, owner: Player, - players: Player[] + players: Player[], + assignments: MurderAssignment[] |} diff --git a/src/common/types/murder.js b/src/common/types/murder.js new file mode 100644 index 0000000..de7654d --- /dev/null +++ b/src/common/types/murder.js @@ -0,0 +1,5 @@ +// @flow + +export type Murder = {| + id: number +|} diff --git a/src/common/types/murderAssignment.js b/src/common/types/murderAssignment.js new file mode 100644 index 0000000..3eee0ff --- /dev/null +++ b/src/common/types/murderAssignment.js @@ -0,0 +1,11 @@ +// @flow + +export type MurderAssignmentState = 'PENDING' | 'FULFILLED' | 'FAILED' | 'PLAYER_LEAVED'; + +export type MurderAssignment = {| + id: number, + killer: Player, + target: Player, + state: MurderAssignmentState, + murder: Murder +|} diff --git a/src/nav/game/components/AssignmentsList.js b/src/nav/game/components/AssignmentsList.js new file mode 100644 index 0000000..28a2eb1 --- /dev/null +++ b/src/nav/game/components/AssignmentsList.js @@ -0,0 +1,21 @@ +// @flow + +import React from 'react' +import type { MurderAssignment } from '../../../common/types/murderAssignment'; +import MurderAssignmentCard from './MurderAssignmentCard' +import { Card } from 'native-base' + +type PropsType = {| + assignments: MurderAssignment[] +|} + +export default class AssignmentsList extends React.Component { + render () { + const { assignments } = this.props + return <> + { assignments.map(assignment => ( + + )) } + + } +} diff --git a/src/nav/game/components/GameMurderAssignmentScreen.js b/src/nav/game/components/GameMurderAssignmentScreen.js new file mode 100644 index 0000000..e041405 --- /dev/null +++ b/src/nav/game/components/GameMurderAssignmentScreen.js @@ -0,0 +1,66 @@ +// @flow + +import React from 'react' +import { Content, Text } from 'native-base' +import type { Game } from '../../../common/types/game' +import { RefreshControl, View } from 'react-native' +import isEmpty from 'react-native-web/dist/vendor/react-native/isEmpty' +import AssignmentsList from './AssignmentsList' +import ApiError from '../../../common/api/apiError' +import { toastifyError } from '../../../common/funtions/errorHandling' +import GamesApi from '../../../common/api/gamesApi' +import i18n from 'i18n-js' + +type PropsType = {| + game: Game, + navigation: NavigationScreenProp +|} + +type StateType = {| + loading: boolean +|} + +export default class GameMurderAssignmentScreen extends React.Component { + state = { + loading: false + } + + componentDidMount () { + this.refreshAssignments() + } + + fetchGameAgain: (Game) => Promise = (game: Game) => GamesApi.getGame(game.id) + .then(game => game.deleted ? null : game) + .catch(error => ApiError.handle(error, new Map([ + [404, () => null] + ]))) + + refreshAssignments () { + this.setState({ loading: true }) + const { game } = this.props + Promise.all( + this.props.game = this.fetchGameAgain(game) + .then(updatedGame => { + + }) + ) + .catch(toastifyError) + .finally(() => this.setState({ loading: false })) + } + + render () { + const { loading } = this.state + const { game, navigation } = this.props + const refreshControl = + return + { (game.assignments && !isEmpty(game.assignments)) + ? + + + : + { i18n.t('games.assignments.empty') } + + } + + } +} diff --git a/src/nav/game/components/GameTabsScreen.js b/src/nav/game/components/GameTabsScreen.js index 15eae7b..66341c4 100644 --- a/src/nav/game/components/GameTabsScreen.js +++ b/src/nav/game/components/GameTabsScreen.js @@ -7,6 +7,7 @@ import type { NavigationScreenProp, NavigationState, NavigationStateRoute } from import i18n from 'i18n-js' import GameParticipantsScreen from './GameParticipantsScreen' import GamePreferencesScreen from './GamePreferencesScreen' +import GameMurderAssignmentScreen from './GameMurderAssignmentScreen'; const Tab = createBottomTabNavigator() @@ -48,6 +49,10 @@ export default class GameTabsScreen extends React.Component { render () { return + + }}/> diff --git a/src/nav/game/components/MurderAssignmentCard.js b/src/nav/game/components/MurderAssignmentCard.js new file mode 100644 index 0000000..e7b5e36 --- /dev/null +++ b/src/nav/game/components/MurderAssignmentCard.js @@ -0,0 +1,47 @@ +// @flow + +import React from 'react' +import { MurderAssignment } from '../../../common/types/murderAssignment' +import { Card, CardItem, Icon, Text } from 'native-base' +import i18n from 'i18n-js' + +type PropsType = {| + assignment: MurderAssignment +|} + +export default class MurderAssignmentCard extends React.Component { + getAssignmentClaim () { + const { assignment } = this.props + const target = assignment.target + switch (this.props.assignment.state) { + case 'PENDING': + return <> + { i18n.t('game.assignments.current.claim', { target: target.name }) } + + + case 'FULFILLED': + return <> + { i18n.t('game.assignments.former.claim') } + + + case 'FAILED': + return <> + { i18n.t('game.assignments.failed.claim', { target: target.name }) } + + + case 'PLAYER_LEAVED': + return <> + { i18n.t('game.assignments.leaved.claim', { target: target.name }) } + + + } + } + + render () { + return + + { this.getAssignmentClaim() } + + + } +}