Skip to content

Commit a97816a

Browse files
committed
Add another fields from database
1 parent acfada5 commit a97816a

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

img/cooking.png

70.9 KB
Loading

img/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const UNKNOWN = require('./unknown.png');
22

33
export const CATEGORY_NEWSPAPERS = require('./news-papers.png');
4+
export const CATEGORY_COOKING = require('./cooking.png');
45

56
export const NEWSPAPERS_DIVAINA = require('./divaina.png');
67
export const NEWSPAPERS_LANKADEEPA = require('./lankadeepa.png');

src/api/Api.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ class Api {
2525
const finalArr = [];
2626
categories()
2727
.then((categoriesData) => {
28-
Object.keys(categoriesData).map((key) => {
29-
const title = key;
30-
const newTitle = title.charAt(0).toUpperCase() + title.slice(1);
31-
return finalArr.push({ id: categoriesData[key], title: newTitle, thumbnail: undefined });
32-
// we have to add Thumbnail (both - to Firebase and app)
28+
Object.keys(categoriesData).map((key, index) => {
29+
const categoryObject = categoriesData[key];
30+
return finalArr.push({
31+
id: index + 1,
32+
title: categoryObject.title,
33+
thumbnail: categoryObject.thumbnail,
34+
});
3335
});
3436
return finalArr;
3537
})
3638
.then((nextData) => {
3739
const newArray = [];
3840
nextData.map((key, index) => sites(key.title)
3941
.then((siteData) => {
40-
const itemsArray = []; // helper Array to store all formatted items
42+
const itemsArray = [];
4143
Object.keys(siteData).map((key1, index1) => itemsArray.push({
4244
id: `${finalArr[index].id}_${index1}`,
4345
title: siteData[key1].title,
44-
url: `http://${siteData[key1].url}`, // for now it will produce bad URL for links starting with http:// or https:// [needs to be changed in database]
46+
url: siteData[key1].url,
4547
thumbnail: siteData[key1].thumbnail,
4648
}));
4749
newArray.push({ ...finalArr[index], items: itemsArray });

src/components/App.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ class Categories extends Component {
3737
const { navigate } = this.props.navigation;
3838

3939
let nodes = null;
40-
if (this.props.categoryData.length !== 0) {
41-
nodes = this.props.categoryData.map(category => (
42-
<BoxItem
43-
key={category.id}
44-
onPress={() => navigate('Detail', { title: category.title, items: category.items })}
45-
{...category}
46-
/>
47-
));
48-
}
40+
nodes = this.props.categoryData.map(category => (
41+
<BoxItem
42+
key={category.id}
43+
onPress={() => navigate('Detail', { title: category.title, items: category.items })}
44+
{...category}
45+
/>
46+
));
4947

5048
return nodes === null ? null : (
5149
<TwoColumnView>

0 commit comments

Comments
 (0)