From c3d5588e667e7fc80d8376df777c27349a6d1fd7 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Thu, 28 Oct 2021 19:05:42 +0530 Subject: [PATCH] Add Shelf form integration + Pull shared module + code cleanup --- src/components/add-category/AddCategory.tsx | 4 +- src/components/add-shelf/AddShelf.tsx | 49 ++++++++++++++------- src/components/categories/Categories.tsx | 7 ++- src/components/home/Home.tsx | 16 +++---- src/services/shelf.ts | 12 +++-- src/shared | 2 +- 6 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/components/add-category/AddCategory.tsx b/src/components/add-category/AddCategory.tsx index 5c281f3..b869cfd 100644 --- a/src/components/add-category/AddCategory.tsx +++ b/src/components/add-category/AddCategory.tsx @@ -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 TextIcon } from '../../assets/icons/text.svg'; import { addCategory, getCategoryDetails } from "../../services/category"; -import { User } from "../../shared/models/user"; +import { MobileUser } from "../../shared/models/user"; type ownProps = { hidePopup: () => void @@ -17,7 +17,7 @@ const IconSet = [, , , ] export const AddCategory: React.FC = (props: ownProps) => { const [newCategory, setnewCategory] = useState(''); const [showIconSet, setShowIconSet] = useState(false); - const userProfile: User = JSON.parse(localStorage.getItem('userProfile') || ""); + const userProfile: MobileUser = JSON.parse(localStorage.getItem('userProfile') || ""); const addNewCategory = () => { addCategory(newCategory).then((response: any) => { diff --git a/src/components/add-shelf/AddShelf.tsx b/src/components/add-shelf/AddShelf.tsx index 2ae5a18..f25312e 100644 --- a/src/components/add-shelf/AddShelf.tsx +++ b/src/components/add-shelf/AddShelf.tsx @@ -3,17 +3,20 @@ import styles from './AddShelf.module.scss'; import { ReactComponent as CloseIcon } from '../../assets/icons/close.svg'; import { ReactComponent as PlusIcon } from '../../assets/icons/plus.svg'; import { ReactComponent as CheckCircle } from '../../assets/icons/check.svg'; -import { IShelf } from "../../structure/shelf"; -import { userProfileData } from "../../App"; +import { Shelf } from "../../shared/models/shelf"; +import { MobileUser } from "../../shared/models/user"; +import { addShelf, getShelfDetails } from "../../services/shelf"; export const AddShelf: React.FC = () => { - const [selectedCategoryIndex, setCategoryIndex] = useState(); - const [newShelf, setnewSelf] = useState({ + const userProfile: MobileUser = JSON.parse(localStorage.getItem('userProfile') || ""); + + const [selectedCategory, setSelectedCategory] = useState(""); + + const [newShelf, setnewSelf] = useState({ name: '', - words: [], - revisedWords: [], description: '', - viewPermission: 'PRIVATE' + isArchived: false, + viewType: 'PRIVATE', }); return
@@ -49,16 +52,16 @@ export const AddShelf: React.FC = () => {
    - { userProfileData.categories.map((category, index) => { - return
  • setCategoryIndex(index)} - className={index === selectedCategoryIndex ? '' : styles.inactive}> - { index === selectedCategoryIndex && } + { userProfile && userProfile.categories?.map((category, index) => { + return
  • setSelectedCategory(category._id)} + className={category._id === selectedCategory ? '' : styles.inactive}> + { category._id === selectedCategory && }
    { category.icon }
    - { category.shelves.length } Shelves + { category.shelves?.length } Shelves
  • })} @@ -67,10 +70,10 @@ export const AddShelf: React.FC = () => {
    -
    { +
    { setnewSelf({ ...newShelf, - viewPermission: newShelf.viewPermission === 'PRIVATE' ? 'PUBLIC' : 'PRIVATE', + viewType: newShelf.viewType === 'PRIVATE' ? 'PUBLIC' : 'PRIVATE', }); } }> @@ -78,9 +81,21 @@ export const AddShelf: React.FC = () => {
*/} - {/*
+

@@ -158,13 +158,13 @@ export const Home: React.FC = () => { }) })} -

*/} +
- { userProfile &&
+ { userProfile && userProfile.categories &&

- Categories { ({userProfile.categories?.length}) } + Categories { ({userProfile.categories.length}) }

@@ -174,9 +174,9 @@ export const Home: React.FC = () => {
    - {userProfile.categories?.map((category: any, index) => { + {userProfile.categories?.map((category, index) => { return
  • { - history.push('/category-details/category_id=' + index); + history.push('/category-details/category_id=' + category._id); }}>
    {category.icon} diff --git a/src/services/shelf.ts b/src/services/shelf.ts index 75a7ae8..5746c1f 100644 --- a/src/services/shelf.ts +++ b/src/services/shelf.ts @@ -1,19 +1,23 @@ import axios from "axios"; import { API_TOKEN, SERVER_URL } from "../App"; +import { viewPermissionType } from "../shared/models/variables"; -export const getAllShelf = async (categoryId: string) => { - return await axios.get(SERVER_URL + '/shelf/details/?_id=' + { categoryId: categoryId }, +export const getShelfDetails = async (categoryId: string) => { + return await axios.get(SERVER_URL + '/shelf/details/?_id=' + categoryId, { headers: API_TOKEN }) } -export const addShelf = async (categoryId: string, name: string) => { +export const addShelf = async (categoryId: string, name: string, isArchived: boolean, viewType: viewPermissionType, description?: string) => { return await axios.post(SERVER_URL + '/shelf/add/', { categoryId: categoryId, - name: name + name: name, + description: description, + isArchived: isArchived, + viewType: viewType }, { headers: API_TOKEN diff --git a/src/shared b/src/shared index f4b5742..d222fdf 160000 --- a/src/shared +++ b/src/shared @@ -1 +1 @@ -Subproject commit f4b5742e27cf554dc922fa1af415bafea7214b30 +Subproject commit d222fdf4c43980569323c9d50371c2d9be6b03b0