Skip to content

Commit

Permalink
styled componets and unikitty update - hide selected character from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Clayburn committed Nov 8, 2018
1 parent c026328 commit f48a2dc
Show file tree
Hide file tree
Showing 9 changed files with 812 additions and 150 deletions.
5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@infosum/unikitty": "^3.0.14",
"@infosum/unikitty": "^5.1.12",
"@types/node": "*",
"@types/prop-types": "^15.5.3",
"@types/react": "*",
Expand All @@ -19,7 +19,8 @@
"react-apollo": "^2.1.9",
"react-dom": "^16.4.1",
"react-router-dom": "^4.3.1",
"recompose": "^0.27.1"
"recompose": "^0.27.1",
"styled-components": "^4.0.3"
},
"devDependencies": {
"@types/jest": "^23.3.0",
Expand Down
2 changes: 1 addition & 1 deletion client/src/Games/AddGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const AddGame: React.SFC<RouteComponentProps<any>> = ({ history }) => {
contract={contract}
>
{({ setValue, formData, validate, errors }) => {
console.log('formrdata', formData);
return <div>
<h1>New Game</h1>
<FormGroup>
Expand All @@ -109,7 +110,6 @@ const AddGame: React.SFC<RouteComponentProps<any>> = ({ history }) => {
type="button"
onClick={async (e) => {
try {
e.preventDefault();
await validate(formData);
const game = {
variables: {
Expand Down
25 changes: 21 additions & 4 deletions client/src/Games/AddPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Button, Form, FormGroup, Input, Label } from '@infosum/unikitty';
import gql from 'graphql-tag';
import * as React from 'react';
import { graphql, MutateProps } from 'react-apollo';
import {
graphql,
MutateProps,
} from 'react-apollo';

import {
Button,
Form,
FormGroup,
Input,
Label,
} from '@infosum/unikitty';

import { IPlayer } from './PlayerList';

const initialData: IPlayer = {
Expand All @@ -25,7 +36,10 @@ const AddPlayer: React.SFC<MutateProps<any>> = (props) => {
<Label>Player:</Label>
<Input
value={formData.user.name}
onChange={(e) => setValue('player', e.target.value)} />
onChange={(e) => setValue('user', {
...formData.user,
name: e.target.value,
})} />
</FormGroup>
<Button
onClick={() => {
Expand All @@ -34,7 +48,10 @@ const AddPlayer: React.SFC<MutateProps<any>> = (props) => {
gamId: 1,
userId: 2,
}
}).then(() => setValue('player', ''));
}).then(() => setValue('user', {
id: '',
name: '',
}));
}}
>
Add
Expand Down
17 changes: 14 additions & 3 deletions client/src/Games/AssignCharacters.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Button, Form, FormGroup, Label, VirtualizedSelect } from '@infosum/unikitty';
import gql from 'graphql-tag';
import * as React from 'react';
import { Mutation } from 'react-apollo';

import {
Button,
Form,
FormGroup,
Input,
Label,
} from '@infosum/unikitty';

import CharacterSelect from './CharacterSelect';
import { IGame } from './Game';

Expand Down Expand Up @@ -29,6 +37,7 @@ mutation UpdatePlayerInGame($id: String, $userId: String, $characterId: String,
}
`;

// Number of good/bad players based on # of people playing.
const teamMap = {
5: { good: 3, evil: 2 },
6: { good: 4, evil: 2 },
Expand Down Expand Up @@ -57,7 +66,7 @@ const AssignCharacters: React.SFC<{ game: IGame }> = ({ game }) => {
>
{(updatePlayerInGame) => (
<Form<IUpdatePlayerRequest> initialData={initialData}>
{({ setValue, formData }) => {
{({ setValue, formData, reset }) => {
const unassignedPlayers = game.players.map((p) => ({
label: p.user.name,
value: p.user.id,
Expand All @@ -67,7 +76,8 @@ const AssignCharacters: React.SFC<{ game: IGame }> = ({ game }) => {
<Label>
Player:
</Label>
<VirtualizedSelect
<Input
type="select"
value={formData.userId}
options={unassignedPlayers}
onChange={(e) => setValue('userId', e.value)} />
Expand All @@ -91,6 +101,7 @@ const AssignCharacters: React.SFC<{ game: IGame }> = ({ game }) => {
updatePlayerInGame({
variables
});
reset();

}}
>
Expand Down
13 changes: 10 additions & 3 deletions client/src/Games/CharacterSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { FormGroup, Label, VirtualizedSelect } from '@infosum/unikitty';
import * as React from 'react';
import { Query } from "react-apollo";
import { Query } from 'react-apollo';

import {
FormGroup,
Input,
Label,
} from '@infosum/unikitty';

import { GET_CHARACTER } from '../Characters/Characters';
import { IPlayer } from './PlayerList';

Expand All @@ -24,7 +30,8 @@ const CharacterSelect: React.SFC<IProps> = ({ onChange, value, players }) => {
return (
<FormGroup>
<Label>Character</Label>
<VirtualizedSelect
<Input
type="select"
value={value}
options={options}
onChange={onChange} />
Expand Down
33 changes: 30 additions & 3 deletions client/src/Games/PlayerList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import * as React from 'react';
import styled from 'styled-components';

import {
CircleIcon,
CrossIcon,
IconStack,
TickIcon,
} from '@infosum/unikitty';

const Li = styled.li`
display: flex;
> div > div {
display: block
}
`;

export interface ICharacter {
id: string;
Expand Down Expand Up @@ -26,9 +41,21 @@ const PlayerList: React.SFC<IProps> = ({ players }) => {
<ul>
{
players.map(({ id, user, character }) =>
<li key={id}>
{user.name}: {character.name}
</li>
<Li key={id} >
<div style={{ width: '25px' }}>
{character.name ? <IconStack>
<CircleIcon width="15" height="15" />
<TickIcon fill="#fff" width="10" height="10" />
</IconStack> :
<IconStack>
<CircleIcon width="15" height="15" fill="red" />
<CrossIcon fill="#fff" width="10" height="10" />
</IconStack>}
</div>
<div>
{user.name}
</div>
</Li>
)}
</ul>
);
Expand Down
5 changes: 3 additions & 2 deletions client/src/Games/PlayerSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Query } from 'react-apollo';
import {
FormFeedback,
FormGroup,
Input,
Label,
VirtualizedSelect,
} from '@infosum/unikitty';

import { GET_USERS } from '../Users/Users';
Expand All @@ -30,7 +30,8 @@ const PlayerSelect: React.SFC<IProps> = ({ onChange, value, errors }) => {
return (
<FormGroup>
<Label>Players</Label>
<VirtualizedSelect
<Input
type="selecct"
value={value}
multi={true}
options={options}
Expand Down
Loading

0 comments on commit f48a2dc

Please sign in to comment.