| @@ -21,11 +21,10 @@ import { Calendar } from "./components/calendar/Calendar"; | |||||
| import { Login } from "./components/auth/Login"; | import { Login } from "./components/auth/Login"; | ||||
| import { Signup } from "./components/auth/Signup"; | import { Signup } from "./components/auth/Signup"; | ||||
| export const SERVER_URL = 'http://localhost:8001'; | |||||
| export const SERVER_URL = 'https://anamnesis.webtrigon.com'; | |||||
| export const API_TOKEN = { "Authorization": `Bearer ${localStorage.anamnesisToken}` } | export const API_TOKEN = { "Authorization": `Bearer ${localStorage.anamnesisToken}` } | ||||
| export var userProfileData: IProfile = { | |||||
| export const userProfileData: IProfile = { | |||||
| name: 'Neymar Jr', | name: 'Neymar Jr', | ||||
| image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSERA5Pm3aRBV7AaI8tvpZfzpD24ZgrU1_8NA&usqp=CAU', | image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSERA5Pm3aRBV7AaI8tvpZfzpD24ZgrU1_8NA&usqp=CAU', | ||||
| medal: { | medal: { | ||||
| @@ -1,4 +1,4 @@ | |||||
| import React, { useEffect, useState } from "react"; | |||||
| import React, { useState } from "react"; | |||||
| import styles from './AddCategory.module.scss'; | import styles from './AddCategory.module.scss'; | ||||
| import { ReactComponent as PlusIcon } from '../../assets/icons/plus.svg'; | import { ReactComponent as PlusIcon } from '../../assets/icons/plus.svg'; | ||||
| import { ReactComponent as BrainIcon } from '../../assets/icons/bx-brain.svg'; | import { ReactComponent as BrainIcon } from '../../assets/icons/bx-brain.svg'; | ||||
| @@ -6,7 +6,7 @@ import { ReactComponent as TimeIcon } from '../../assets/icons/time.svg'; | |||||
| import { ReactComponent as TimerIcon } from '../../assets/icons/timer.svg'; | import { ReactComponent as TimerIcon } from '../../assets/icons/timer.svg'; | ||||
| import { ReactComponent as TextIcon } from '../../assets/icons/text.svg'; | import { ReactComponent as TextIcon } from '../../assets/icons/text.svg'; | ||||
| import { MobileCategory } from "../../shared/models/category"; | import { MobileCategory } from "../../shared/models/category"; | ||||
| import { addCategory, categoryDetails } from "../../services/category"; | |||||
| import { addCategory, getCategoryDetails } from "../../services/category"; | |||||
| type ownProps = { | type ownProps = { | ||||
| hidePopup: () => void | hidePopup: () => void | ||||
| @@ -18,21 +18,18 @@ export const AddCategory: React.FC<ownProps> = (props: ownProps) => { | |||||
| const [newCategory, setnewCategory] = useState<string>(''); | const [newCategory, setnewCategory] = useState<string>(''); | ||||
| const [showIconSet, setShowIconSet] = useState<Boolean>(false); | const [showIconSet, setShowIconSet] = useState<Boolean>(false); | ||||
| let temp: Array<MobileCategory> = JSON.parse(localStorage.getItem("catagories") || "[]") | |||||
| function addNewCategory() { | function addNewCategory() { | ||||
| console.log(temp) | |||||
| addCategory(newCategory).then((category: any) => { | |||||
| categoryDetails(category.data).then((category: any) => { | |||||
| temp.push(category.data) | |||||
| }) | |||||
| console.log(category.data) | |||||
| let currentCategories: Array<MobileCategory> = JSON.parse(localStorage.getItem("categories") || "[]"); | |||||
| addCategory(newCategory).then((response: any) => { | |||||
| getCategoryDetails(response.data).then((data: any) => { | |||||
| currentCategories.push(data.data); | |||||
| localStorage.setItem("categories", JSON.stringify(currentCategories)); | |||||
| }); | |||||
| }, err => { | }, err => { | ||||
| console.log("Unable to Add category", err) | console.log("Unable to Add category", err) | ||||
| }) | |||||
| }); | |||||
| } | } | ||||
| console.log(newCategory) | |||||
| return <div className={styles.popupHolder}> | return <div className={styles.popupHolder}> | ||||
| <div className={styles.background} onClick={props.hidePopup}></div> | <div className={styles.background} onClick={props.hidePopup}></div> | ||||
| @@ -64,10 +64,22 @@ | |||||
| padding-left: 2rem; | padding-left: 2rem; | ||||
| font-size: 1.4rem; | font-size: 1.4rem; | ||||
| } | } | ||||
| button { | |||||
| height: 50px; | |||||
| width: 50px; | |||||
| border-radius: 50%; | |||||
| border: none; | |||||
| transform: scale(0.8); | |||||
| background-color: var(--teal); | |||||
| display: flex; | |||||
| align-items: center; | |||||
| justify-content: center; | |||||
| } | |||||
| svg { | svg { | ||||
| width: 5rem; | width: 5rem; | ||||
| fill: var(--red); | |||||
| fill: white; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -11,30 +11,20 @@ import { getWordResult } from "../../services/words"; | |||||
| import { Word } from "../../shared/models/word"; | import { Word } from "../../shared/models/word"; | ||||
| export const AddWord: React.FC = () => { | export const AddWord: React.FC = () => { | ||||
| const [searchWordResult, setSearchResult] = useState<Array<Word>>(); | |||||
| const [searchResult, setSearchResult] = useState<Array<Word>>(); | |||||
| const [selectedWord, setSelectedWord] = useState<Word>(); | const [selectedWord, setSelectedWord] = useState<Word>(); | ||||
| const [searchWord, setSearchWord] = useState<string>(''); | |||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const searchWords = (searchWord: string) => { | |||||
| console.log(searchWord.length) | |||||
| setTimeout(() => { | |||||
| if (searchWord.length > 0) { | |||||
| getWordResult(searchWord).then((wordResult: any) => { | |||||
| let result: Array<Word> = wordResult.data | |||||
| console.log(result.slice(0,10)) | |||||
| setSearchResult(result); | |||||
| }, err => { | |||||
| console.log("Unable to search Words", err) | |||||
| }) | |||||
| } else { | |||||
| getWordResult("Aa").then((wordResult: any) => { | |||||
| let result: Array<Word> = wordResult.data | |||||
| setSearchResult(result); | |||||
| }) | |||||
| } | |||||
| }, 1000) | |||||
| const searchWords = () => { | |||||
| if (searchWord.length > 0) { | |||||
| getWordResult(searchWord).then((wordResult: any) => { | |||||
| let result: Array<Word> = wordResult.data; | |||||
| setSearchResult(result); | |||||
| }, err => { | |||||
| console.log("Unable to search Words", err) | |||||
| }); | |||||
| } | |||||
| } | } | ||||
| return <section className="modalPage"> | return <section className="modalPage"> | ||||
| @@ -61,13 +51,15 @@ export const AddWord: React.FC = () => { | |||||
| {!selectedWord && <section> | {!selectedWord && <section> | ||||
| <div className={styles.searchBarHolder}> | <div className={styles.searchBarHolder}> | ||||
| <div className={styles.searchBar}> | <div className={styles.searchBar}> | ||||
| <input type="text" autoFocus={true} placeholder={'Search and add a word'} onChange={(event) => searchWords(event.currentTarget.value)} /> | |||||
| <SearchIcon /> | |||||
| <input type="text" autoFocus={true} placeholder={'Search and add a word'} onChange={(event) => setSearchWord(event.currentTarget.value)} /> | |||||
| <button onClick={() => searchWords()}> | |||||
| <SearchIcon /> | |||||
| </button> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <ul className={styles.searchResult}> | |||||
| {searchWordResult?.map((word) => { | |||||
| { searchResult && <ul className={styles.searchResult}> | |||||
| {searchResult.map((word) => { | |||||
| return <li key={word.name}> | return <li key={word.name}> | ||||
| <header> | <header> | ||||
| <h4> {word.name} <span> {word.pronounciation} </span> </h4> | <h4> {word.name} <span> {word.pronounciation} </span> </h4> | ||||
| @@ -82,7 +74,7 @@ export const AddWord: React.FC = () => { | |||||
| <button className={styles.addButton} onClick={() => setSelectedWord(word)}> <AddIcon /> Add </button> | <button className={styles.addButton} onClick={() => setSelectedWord(word)}> <AddIcon /> Add </button> | ||||
| </li> | </li> | ||||
| })} | })} | ||||
| </ul> | |||||
| </ul> } | |||||
| </section>} | </section>} | ||||
| @@ -9,12 +9,11 @@ import { Category } from "../../shared/models/category"; | |||||
| export const Categories: React.FC = () => { | export const Categories: React.FC = () => { | ||||
| const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState<Boolean>(false); | const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState<Boolean>(false); | ||||
| const [categoryResult, setCategories] = useState<Array<Category>>([]) | |||||
| let userCategories = JSON.parse(localStorage.getItem("catagories") || "[]") | |||||
| const [categoryResult, setCategories] = useState<Array<Category>>([]); | |||||
| const userCategories = JSON.parse(localStorage.getItem("categories") || "[]"); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| getUserCategory(); | |||||
| setCategories(userCategories); | |||||
| }, []) | }, []) | ||||
| const filterCategories = (text: string) => { | const filterCategories = (text: string) => { | ||||
| @@ -29,10 +28,6 @@ export const Categories: React.FC = () => { | |||||
| } | } | ||||
| } | } | ||||
| function getUserCategory() { | |||||
| setCategories(userCategories) | |||||
| } | |||||
| return <section className="page"> | return <section className="page"> | ||||
| <header className={styles.pageHeader}> | <header className={styles.pageHeader}> | ||||
| <LogoIcon /> | <LogoIcon /> | ||||
| @@ -62,7 +57,7 @@ export const Categories: React.FC = () => { | |||||
| <section className={styles.Grid}> | <section className={styles.Grid}> | ||||
| <ul> | <ul> | ||||
| {categoryResult.map((category, index) => { | {categoryResult.map((category, index) => { | ||||
| return <li key={category.name}> | |||||
| return <li key={index}> | |||||
| <div className={styles.icon}> | <div className={styles.icon}> | ||||
| {category.icon} | {category.icon} | ||||
| </div> | </div> | ||||
| @@ -17,55 +17,54 @@ import { AddCategory } from "../add-category/AddCategory"; | |||||
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import { userProfileData } from "../../App"; | import { userProfileData } from "../../App"; | ||||
| import { getUserProfile } from "../../services/user"; | import { getUserProfile } from "../../services/user"; | ||||
| import { User } from "../../shared/models/user" | |||||
| import { categoryDetails } from "../../services/category"; | |||||
| import { MongoUser } from "../../shared/models/user" | |||||
| import { getCategoryDetails } from "../../services/category"; | |||||
| import { MobileCategory } from "../../shared/models/category"; | import { MobileCategory } from "../../shared/models/category"; | ||||
| export const Home: React.FC = () => { | export const Home: React.FC = () => { | ||||
| const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState<Boolean>(false); | const [isAddCategoryPopupOpen, setAddCategoryPopupState] = useState<Boolean>(false); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const [userProfile, setUserProfile] = useState<User>() | |||||
| const [userProfile, setUserProfile] = useState<MongoUser>() | |||||
| const [allCatagories, setAllCatagories] = useState<Array<MobileCategory>>([]) | const [allCatagories, setAllCatagories] = useState<Array<MobileCategory>>([]) | ||||
| useEffect(() => { | |||||
| User(); | |||||
| }, []) | |||||
| function User() { | |||||
| const getUserProfileData = () => { | |||||
| getUserProfile().then((data: any) => { | getUserProfile().then((data: any) => { | ||||
| let userData: MongoUser = data.data; | |||||
| setUserProfile(userData); | |||||
| let userData = data.data | |||||
| localStorage.setItem("catagoryIds", JSON.stringify(userData.categories)) | |||||
| setUserProfile(userData) | |||||
| getUserCategory(); | |||||
| if (userData.categories) { | |||||
| getUserCategoryDetails(userData.categories) | |||||
| } | |||||
| }, (err) => { | }, (err) => { | ||||
| console.log(err) | console.log(err) | ||||
| }) | }) | ||||
| } | } | ||||
| let allCategoryDetails: Array<MobileCategory> = [] | |||||
| const getUserCategoryDetails = (categoryIds: Array<string>) => { | |||||
| let allCategoryDetails: Array<MobileCategory> = []; | |||||
| function getUserCategory() { | |||||
| let categoryIds: Array<string> = JSON.parse(localStorage.getItem("catagoryIds") || "[]") | |||||
| let catagoryDetails: Array<MobileCategory> = JSON.parse(localStorage.getItem("catagories") || "[]") | |||||
| categoryIds.forEach((catagoryId) => { | |||||
| getCategoryDetails(catagoryId).then((categoryDetails: any) => { | |||||
| allCategoryDetails.push(categoryDetails.data); | |||||
| if (categoryIds.length === allCategoryDetails.length) { | |||||
| setAllCatagories(allCategoryDetails); | |||||
| localStorage.setItem("categories", JSON.stringify(allCategoryDetails)) | |||||
| } | |||||
| categoryIds.map((catagories: any) => { | |||||
| categoryDetails(catagories).then((categoryDetails: any) => { | |||||
| allCategoryDetails.push(categoryDetails.data) | |||||
| localStorage.setItem("catagories", JSON.stringify(allCategoryDetails)) | |||||
| }, (err) => { | }, (err) => { | ||||
| console.log("Error fetching Category Details", err) | console.log("Error fetching Category Details", err) | ||||
| }) | |||||
| }) | |||||
| console.log(catagoryDetails) | |||||
| setAllCatagories(catagoryDetails) | |||||
| }); | |||||
| }); | |||||
| } | } | ||||
| console.log(allCatagories) | |||||
| useEffect(() => { | |||||
| getUserProfileData(); | |||||
| console.log("rendering Home"); | |||||
| }, [localStorage.getItem('categories')]); | |||||
| return <section className="page"> | return <section className="page"> | ||||
| @@ -163,7 +162,7 @@ export const Home: React.FC = () => { | |||||
| <ul> | <ul> | ||||
| {userProfileData.categories.map((category, categoryIndex) => { | {userProfileData.categories.map((category, categoryIndex) => { | ||||
| return category.shelves.map((shelf, shelfIndex) => { | return category.shelves.map((shelf, shelfIndex) => { | ||||
| return <li key={shelf.name} onClick={() => { | |||||
| return <li key={shelfIndex} onClick={() => { | |||||
| history.push('/shelf-details/category_id=' + categoryIndex + '&&shelf_id=' + shelfIndex); | history.push('/shelf-details/category_id=' + categoryIndex + '&&shelf_id=' + shelfIndex); | ||||
| }}> | }}> | ||||
| <div className={styles.progress}> | <div className={styles.progress}> | ||||
| @@ -205,8 +204,8 @@ export const Home: React.FC = () => { | |||||
| </button> | </button> | ||||
| </header> | </header> | ||||
| <ul> | <ul> | ||||
| {allCatagories.map((category: any, index: any) => { | |||||
| return <li key={category.name} onClick={() => { | |||||
| {allCatagories.map((category, index) => { | |||||
| return <li key={index} onClick={() => { | |||||
| history.push('/category-details/category_id=' + index); | history.push('/category-details/category_id=' + index); | ||||
| }}> | }}> | ||||
| <div className={styles.icon}> | <div className={styles.icon}> | ||||
| @@ -214,7 +213,7 @@ export const Home: React.FC = () => { | |||||
| </div> | </div> | ||||
| <div className={styles.info}> | <div className={styles.info}> | ||||
| <label> {category.name} </label> | <label> {category.name} </label> | ||||
| <span> {category.shelves?.length > 0 ? category.shelves?.length : 0} Shelves </span> | |||||
| <span> {category.shelves && category.shelves?.length > 0 ? category.shelves.length : 0} Shelves </span> | |||||
| </div> | </div> | ||||
| </li> | </li> | ||||
| })} | })} | ||||
| @@ -6,7 +6,6 @@ import { ICategory } from "../../structure/category"; | |||||
| import { IShelf } from "../../structure/shelf"; | import { IShelf } from "../../structure/shelf"; | ||||
| import { userProfileData } from "../../App"; | import { userProfileData } from "../../App"; | ||||
| import { ReactComponent as BookIcon } from '../../assets/icons/book-sharp.svg'; | import { ReactComponent as BookIcon } from '../../assets/icons/book-sharp.svg'; | ||||
| import { ReactComponent as MoreIcon } from '../../assets/icons/more-alt.svg'; | |||||
| import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg'; | import { ReactComponent as SearchIcon } from '../../assets/icons/bx-search-alt.svg'; | ||||
| import { ReactComponent as SpeakerIcon } from '../../assets/icons/speaker.svg'; | import { ReactComponent as SpeakerIcon } from '../../assets/icons/speaker.svg'; | ||||
| import { ReactComponent as ChevronLeft } from '../../assets/icons/chevron-left.svg'; | import { ReactComponent as ChevronLeft } from '../../assets/icons/chevron-left.svg'; | ||||
| @@ -12,7 +12,7 @@ export const addCategory = async (name: string) => { | |||||
| //Need to be changed | //Need to be changed | ||||
| export const categoryDetails = async (id: string) => { | |||||
| export const getCategoryDetails = async (id: string) => { | |||||
| return await axios.get(SERVER_URL + '/category/details/', { | return await axios.get(SERVER_URL + '/category/details/', { | ||||
| params: { _id: id }, | params: { _id: id }, | ||||
| headers: API_TOKEN | headers: API_TOKEN | ||||