Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ Our users are keen to be able to add point values to tasks with a natural langua
## Feature Four

If you've got some extra time left, it would be great for our users to be able to update the point value of an existing task. Implement the UI however you think best.

Thank you
12 changes: 11 additions & 1 deletion src/components/CreateEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ export const CreateEntry = ({ onSave }: Props) => {
const [value, setValue] = useState<string>('');

const handleAdd = () => {
value && onSave({ name: value, points: 0 });
let actualPoint: number = 0;
let points = value.substr(-5);
let name: string = value.substr(0, value.length-5);
let actualPointString: string = points.substr(0, 2);
if (isNaN(parseInt(actualPointString))) {
actualPoint = 0;
name = value;
} else {
actualPoint = parseInt(actualPointString.trim());
}
value && onSave({ name: name.trim(), points: actualPoint });
setValue('');
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/ItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const styles = StyleSheet.create({
paddingHorizontal: 16,
marginTop: 2,
backgroundColor: 'white',
fontWeight: 'bold'
},
containerCritical: {
backgroundColor: '#ffdddd',
Expand All @@ -19,6 +20,11 @@ const styles = StyleSheet.create({
},
textCritical: {
fontWeight: 'bold',
},
critical: {
backgroundColor: 'red',
color: 'yellow',
fontWeight: 'bold'
}
});

Expand All @@ -28,7 +34,7 @@ type Props = {
}

export const ItemCard: React.FC<Props> = ({ children, onDelete, critical }) => (
<View testID="itemCard" style={{ ...styles.container, ...(critical ? styles.containerCritical : {}) }}>
<View testID="itemCard" style={{ ...styles.container, ...( styles.critical ) , ...(critical ? styles.containerCritical : {}) }}>
<Text testID="itemName" style={{ ...styles.text, ...(critical ? styles.textCritical : {}) }}>{children}</Text>
<Button testID="itemDeleteButton" onPress={onDelete} title="Delete" />
</View>
Expand Down
23 changes: 22 additions & 1 deletion src/components/Todos.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { View, Text, FlatList, StyleSheet, Button } from 'react-native';

import { CreateEntry } from './CreateEntry';
Expand All @@ -15,11 +15,31 @@ const styles = StyleSheet.create({
fontSize: 16,
textAlign: 'center',
},
critical: {
fontWeight: 'bold'
}
});

const sortItems = (testingITems: Item[]) => {
testingITems.sort((item, item2)=>{
if(item.points < item2.points) {
return 1;
} else if (item.points > item2.points){
return -1;
}
return 0;
});
}

export const Todos = () => {
const defaultItems = sample.map((item, index) => ({ key: `item${index}`, ...item }));
sortItems(defaultItems);
const [items, setItems] = useState<Item[]>(defaultItems);

useEffect(()=>{
sortItems(items);
}, [items]);


const addItem = (newItem: NewItem) => {
const item = { key: `item${items.length}`, ...newItem };
Expand All @@ -38,6 +58,7 @@ export const Todos = () => {
data={items}
renderItem={({ item }) => (
<ItemCard
critical = {item.points >= 10 ? true: false}
key={item.key}
onDelete={() => deleteItem(item.key)}
>{item.name}</ItemCard>
Expand Down
2 changes: 1 addition & 1 deletion src/data/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

export const sample = [
{ name: 'Check it twice', points: 5 },
{ name: 'Make a list', points: 6 },
{ name: 'Get the job 👍🏼', points: 10 },
{ name: 'Make a list', points: 6 },
];