Skip to content

Commit

Permalink
Display dummy resources
Browse files Browse the repository at this point in the history
  • Loading branch information
migue1s committed May 24, 2020
1 parent 1054309 commit 1a7308e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/containers/Resources.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {Text, View, SectionList} from 'react-native';
import {useResources} from '../hooks';
import {ResourceType} from '../types';

const Resources = () => {
const data = useResources();

return (
<View>
<Text>{JSON.stringify(data, null, 2)}</Text>
<SectionList
sections={data}
renderSectionHeader={({section}) => <Text>{section.header}</Text>}
renderItem={({item}) => <Text>{item.name}</Text>}
/>
</View>
);
};

export default Resources;

const styles = StyleSheet.create({});
13 changes: 9 additions & 4 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ export const useResourcesByCategory = (category: string) => {
};

export const useResources = () => {
const resources = useSelector(
(state: ReduxState) => state.game.resourceCount,
);
const resources = useSelector((state: ReduxState) => state.game.resources);

return chain(resources)
const resourceGroups = chain(Object.values(resources))
.pickBy((r) => r.unlocked)
.filter(
(r) =>
Expand All @@ -23,4 +21,11 @@ export const useResources = () => {
)
.groupBy((r) => r && r.category)
.value();

return Object.keys(resourceGroups).map((key) => {
return {
header: key,
data: resourceGroups[key],
};
});
};

0 comments on commit 1a7308e

Please sign in to comment.