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

MUR-4: added part of murder assign list #20

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions src/common/localization/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
16 changes: 16 additions & 0 deletions src/common/localization/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
4 changes: 3 additions & 1 deletion src/common/types/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +24,6 @@ export type Game = {|
...NewGame,
preferences: GamePreferences,
owner: Player,
players: Player[]
players: Player[],
assignments: MurderAssignment[]
|}
5 changes: 5 additions & 0 deletions src/common/types/murder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow

export type Murder = {|
id: number
|}
11 changes: 11 additions & 0 deletions src/common/types/murderAssignment.js
Original file line number Diff line number Diff line change
@@ -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
|}
21 changes: 21 additions & 0 deletions src/nav/game/components/AssignmentsList.js
Original file line number Diff line number Diff line change
@@ -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<PropsType> {
render () {
const { assignments } = this.props
return <>
{ assignments.map<Card>(assignment => (
<MurderAssignmentCard key={ assignment.id } assignment={ assignment }/>
)) }
</>
}
}
66 changes: 66 additions & 0 deletions src/nav/game/components/GameMurderAssignmentScreen.js
Original file line number Diff line number Diff line change
@@ -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<NavigationState>
|}

type StateType = {|
loading: boolean
|}

export default class GameMurderAssignmentScreen extends React.Component<PropsType> {
state = {
loading: false
}

componentDidMount () {
this.refreshAssignments()
}

fetchGameAgain: (Game) => Promise<?Game> = (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 = <RefreshControl refreshing={loading} onRefresh={this.refreshAssignments()}/>
return <Content refreshControl={refreshControl}>
{ (game.assignments && !isEmpty(game.assignments))
? <View>
<AssignmentsList assignments={game.assignments} navigation={navigation}/>
</View>
: <View>
<Text>{ i18n.t('games.assignments.empty') }</Text>
</View>
}
</Content>
}
}
5 changes: 5 additions & 0 deletions src/nav/game/components/GameTabsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -48,6 +49,10 @@ export default class GameTabsScreen extends React.Component<PropsType> {

render () {
return <Tab.Navigator tabBar={this.buildTabBar} backBehavior='none'>
<Tab.Screen name="Game.MurderAssignment" component={this.addGameProp(GameMurderAssignmentScreen)} options={{
title: i18n.t('game.murderAssignment.title'),
icon: <Icon name='target' type="MaterialCommunityIcons"/>
}}/>
<Tab.Screen name="Game.Participants" component={this.addGameProp(GameParticipantsScreen)} options={{
title: i18n.t('game.participants.title'),
icon: <Icon android='md-people' ios='ios-people'/>
Expand Down
47 changes: 47 additions & 0 deletions src/nav/game/components/MurderAssignmentCard.js
Original file line number Diff line number Diff line change
@@ -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<PropsType> {
getAssignmentClaim () {
const { assignment } = this.props
const target = assignment.target
switch (this.props.assignment.state) {
case 'PENDING':
return <>
<Text>{ i18n.t('game.assignments.current.claim', { target: target.name }) }</Text>
<Icon name=""/>
</>
case 'FULFILLED':
return <>
<Text>{ i18n.t('game.assignments.former.claim') }</Text>
<Icon name=""/>
</>
case 'FAILED':
return <>
<Text>{ i18n.t('game.assignments.failed.claim', { target: target.name }) }</Text>
<Icon name=""/>
</>
case 'PLAYER_LEAVED':
return <>
<Text>{ i18n.t('game.assignments.leaved.claim', { target: target.name }) }</Text>
<Icon name=""/>
</>
}
}

render () {
return <Card>
<CardItem header bordered>
{ this.getAssignmentClaim() }
</CardItem>
</Card>
}
}