Skip to content

Commit 5f77e59

Browse files
Display citizen's hungriness
1 parent 7f84912 commit 5f77e59

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/generated/graphql.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export type Citizen = {
140140
name: Scalars['String']['output'];
141141
skillSet: Array<SkillLevel>;
142142
stomach: Scalars['Int']['output'];
143+
stomachCapacity: Scalars['Int']['output'];
143144
};
144145

145146
export type CitizenInput = {
@@ -1108,7 +1109,7 @@ export type GetCitizensQueryVariables = Exact<{
11081109
}>;
11091110

11101111

1111-
export type GetCitizensQuery = { __typename?: 'Query', citizensFromIsland: { __typename?: 'CitizenList', citizens: Array<{ __typename?: 'Citizen', id: string, bornOn: number, name: string, isHomeless: boolean }> } | { __typename?: 'NotFound' } };
1112+
export type GetCitizensQuery = { __typename?: 'Query', citizensFromIsland: { __typename?: 'CitizenList', citizens: Array<{ __typename?: 'Citizen', id: string, bornOn: number, name: string, isHomeless: boolean, stomach: number, stomachCapacity: number }> } | { __typename?: 'NotFound' } };
11121113

11131114
export type GetEventsQueryVariables = Exact<{
11141115
input: EventsInput;
@@ -2100,6 +2101,8 @@ export const GetCitizensDocument = gql`
21002101
bornOn
21012102
name
21022103
isHomeless
2104+
stomach
2105+
stomachCapacity
21032106
}
21042107
}
21052108
}

‎src/pages/island/Citizens.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const CitizensPage = () => {
2828
bornOn
2929
name
3030
isHomeless
31+
stomach
32+
stomachCapacity
3133
}
3234
}
3335
}
@@ -45,6 +47,8 @@ const CitizensPage = () => {
4547
bornOn: c.bornOn,
4648
name: c.name,
4749
isHomeless: c.isHomeless,
50+
stomach: c.stomach,
51+
stomachCapacity: c.stomachCapacity,
4852
});
4953
}
5054
}
@@ -91,13 +95,23 @@ const TableStyle = styled.table`
9195
`;
9296

9397
const CitizenItem: FunctionComponent<{ citizen: citizen }> = ({ citizen }) => {
98+
const hungriness = citizen.stomach / citizen.stomachCapacity;
99+
const isHungry = hungriness < 0.5 && hungriness >= 0.1;
100+
const isStarving = hungriness < 0.1;
101+
94102
return (
95103
<tr>
96104
<td>
97105
<NavLink to={'/citizen/' + citizen.id}>{citizen.name}</NavLink>{' '}
98106
{citizen.isHomeless && (
99107
<Label text="Homeless" textColor="#fff" backgroundColor="#b66" />
100108
)}
109+
{isHungry && (
110+
<Label text="Hungry" textColor="#fff" backgroundColor="#b66" />
111+
)}
112+
{isStarving && (
113+
<Label text="Starving" textColor="#fff" backgroundColor="#b66" />
114+
)}
101115
</td>
102116
<td>{DateTime.fromMillis(citizen.bornOn * 1000).toRelative()}</td>
103117
</tr>
@@ -109,6 +123,8 @@ interface citizen {
109123
bornOn: number;
110124
name: string;
111125
isHomeless: boolean;
126+
stomach: number;
127+
stomachCapacity: number;
112128
}
113129

114130
export default CitizensPage;

0 commit comments

Comments
 (0)