searchWords(event.currentTarget.value)} />
@@ -56,29 +67,29 @@ export const AddWord: React.FC = () => {
- { searchWordResult.map((word) => {
+ {searchWordResult?.map((word) => {
return -
-
{ word.name } { word.pronounciation }
+ {word.name} {word.pronounciation}
-
{ word.grammaticalDetails[0].typeName }
-
{ word.grammaticalDetails[0].description }
+
{word.grammaticalDetails[0]?.type}
+
{word.grammaticalDetails[0]?.description}
- }) }
+ })}
- }
+ }
- { selectedWord &&
+ {selectedWord &&
@@ -87,7 +98,7 @@ export const AddWord: React.FC = () => {
- { userProfileData.categories.map((category, categoryIndex) => {
+ {userProfileData.categories.map((category, categoryIndex) => {
return category.shelves.map((shelf, shelfIndex) => {
return {
let findWord = userProfileData.categories[categoryIndex].shelves[shelfIndex].words.find(word => word.name.toLowerCase().includes(selectedWord.name.toLowerCase()));
@@ -95,24 +106,24 @@ export const AddWord: React.FC = () => {
if (findWord) {
alert("Word already Present!");
} else {
- userProfileData.categories[categoryIndex].shelves[shelfIndex].words.push(selectedWord);
+ // userProfileData.categories[categoryIndex].shelves[shelfIndex].words.push(selectedWord);
history.push('/shelf-details/category_id=' + categoryIndex + '&&shelf_id=' + shelfIndex);
- }
+ }
}}>
- { category.icon }
+ {category.icon}
-
- { category.name }
+
+ {category.name}
})
- }) }
+ })}
Create New Shelf
- }
-
+ }
+
}
\ No newline at end of file
diff --git a/src/components/categories/Categories.tsx b/src/components/categories/Categories.tsx
index e806d28..64fbe92 100644
--- a/src/components/categories/Categories.tsx
+++ b/src/components/categories/Categories.tsx
@@ -1,28 +1,38 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import styles from './Categories.module.scss';
import { ReactComponent as LogoIcon } from '../../assets/icons/anamnesis.svg';
import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg';
import { ReactComponent as PlusCircledIcon } from '../../assets/icons/plus-circle.svg';
import { NavLink } from "react-router-dom";
-import { ICategory } from "../../structure/category";
import { AddCategory } from "../add-category/AddCategory";
-import { userProfileData } from "../../App";
+import { Category } from "../../shared/models/category";
export const Categories: React.FC = () => {
- const [categoryResult, setCategories] = useState
>(userProfileData.categories);
const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState(false);
+ const [categoryResult, setCategories] = useState>([])
+ let userCategories = JSON.parse(localStorage.getItem("catagories") || "[]")
+
+ useEffect(() => {
+ getUserCategory();
+ }, [])
+
const filterCategories = (text: string) => {
if (text.length > 0) {
- let result = userProfileData.categories.filter(category => {
+ let result: any = categoryResult.filter(category => {
return category.name.toLowerCase().includes(text.toLowerCase());
});
+ console.log(result)
setCategories(result);
} else {
- setCategories(userProfileData.categories);
+ setCategories(userCategories);
}
}
+ function getUserCategory() {
+ setCategories(userCategories)
+ }
+
return
@@ -32,12 +42,12 @@ export const Categories: React.FC = () => {
-
+
-
+
filterCategories(event.currentTarget.value)} />
@@ -51,20 +61,19 @@ export const Categories: React.FC = () => {
-
- { isAddCategoryPopupOpen &&
setAddCategoryPopupState(false)} /> }
+ {isAddCategoryPopupOpen && setAddCategoryPopupState(false)} />}
}
\ No newline at end of file
diff --git a/src/components/home/Home.tsx b/src/components/home/Home.tsx
index 2f395fb..c5ad040 100644
--- a/src/components/home/Home.tsx
+++ b/src/components/home/Home.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import styles from './Home.module.scss';
import { ReactComponent as LogoIcon } from '../../assets/icons/anamnesis.svg';
import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg';
@@ -16,26 +16,56 @@ import { NavLink } from "react-router-dom";
import { AddCategory } from "../add-category/AddCategory";
import { useHistory } from "react-router-dom";
import { userProfileData } from "../../App";
-import { addCategory, getCategory, updateCategory } from "../../services/category";
import { getUserProfile } from "../../services/user";
-import { getWordResult } from "../../services/words";
+import { User } from "../../shared/models/user"
+import { categoryDetails } from "../../services/category";
+import { MobileCategory } from "../../shared/models/category";
export const Home: React.FC = () => {
const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState(false);
const history = useHistory();
+ const [userProfile, setUserProfile] = useState()
+ const [allCatagories, setAllCatagories] = useState>([])
- getUserProfile().then((data) => {
- console.log("UserProfile", data)
- }, (err) => {
- console.log(err)
- })
-
- getWordResult('Ple').then((data) => {
- console.log("Words", data.data)
- }, (err) => {
- console.log(err)
- })
+
+ useEffect(() => {
+ User();
+ }, [])
+
+ function User() {
+ getUserProfile().then((data: any) => {
+
+ let userData = data.data
+ localStorage.setItem("catagoryIds", JSON.stringify(userData.categories))
+ setUserProfile(userData)
+ getUserCategory();
+ }, (err) => {
+ console.log(err)
+ })
+ }
+
+ let allCategoryDetails: Array = []
+
+ function getUserCategory() {
+ let categoryIds: Array = JSON.parse(localStorage.getItem("catagoryIds") || "[]")
+ let catagoryDetails: Array = JSON.parse(localStorage.getItem("catagories") || "[]")
+
+
+ categoryIds.map((catagories: any) => {
+ categoryDetails(catagories).then((categoryDetails: any) => {
+ allCategoryDetails.push(categoryDetails.data)
+ localStorage.setItem("catagories", JSON.stringify(allCategoryDetails))
+ }, (err) => {
+ console.log("Error fetching Category Details", err)
+ })
+ })
+
+ console.log(catagoryDetails)
+ setAllCatagories(catagoryDetails)
+ }
+
+ console.log(allCatagories)
return
@@ -62,7 +92,7 @@ export const Home: React.FC = () => {
{userProfileData.medal.icon}
-
Neymar Junior
+
{userProfile?.name}
1.2K
@@ -175,7 +205,7 @@ export const Home: React.FC = () => {
- {userProfileData.categories.map((category, index) => {
+ {allCatagories.map((category: any, index: any) => {
return - {
history.push('/category-details/category_id=' + index);
}}>
@@ -184,7 +214,7 @@ export const Home: React.FC = () => {
- {category.shelves.length} Shelves
+ {category.shelves?.length > 0 ? category.shelves?.length : 0} Shelves
})}
diff --git a/src/services/category.ts b/src/services/category.ts
index 3f04e9c..8a7f71d 100644
--- a/src/services/category.ts
+++ b/src/services/category.ts
@@ -12,7 +12,7 @@ export const addCategory = async (name: string) => {
//Need to be changed
-export const getCategory = async (id: string) => {
+export const categoryDetails = async (id: string) => {
return await axios.get(SERVER_URL + '/category/details/', {
params: { _id: id },
headers: API_TOKEN
diff --git a/src/shared b/src/shared
index 7dc8d39..f4b5742 160000
--- a/src/shared
+++ b/src/shared
@@ -1 +1 @@
-Subproject commit 7dc8d39f1be0f5159aa473de31620a72c77b98af
+Subproject commit f4b5742e27cf554dc922fa1af415bafea7214b30