Skip to content

Commit

Permalink
Changed admin book details section and sync with search book reducer
Browse files Browse the repository at this point in the history
animeshdhara committed Jul 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9aaf7e2 commit dcb4903
Showing 6 changed files with 26 additions and 17 deletions.
15 changes: 11 additions & 4 deletions src/common_components/ViewBookDetails/ShowBookDetails.jsx
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import '../../pages/user/bookDetails/BookDetailsDesign.css'
import { useNavigate, useParams } from "react-router-dom";
import { useDispatch, useSelector } from 'react-redux';
import { fetchRelatedBookList } from '../../features/relatedBoolReducer/RelatedBookReducer';
import { setSearchQueryResult } from '../../features/searchBookReducer/SearchBookReducer';
import { setOverlayState } from '../../features/showOverlayReducer/ShowOverlayReducer';
//Material ui icons
import ArrowBackOutlinedIcon from '@mui/icons-material/ArrowBackOutlined';
@@ -30,9 +31,11 @@ export default function ShowBookDetails(props) {

const apiURL = import.meta.env.VITE_APP_API_URL;

const [book, setBook] = useState(undefined); //Initially book will be undefined, if changed to null then gives error as we are reading book.book.description
const [loading, setLoading] = useState(true);
const [user_book, setUserBook] = useState(undefined); //Initially book will be undefined, if changed to null then gives error as we are reading book.book.description
const admin_book = useSelector((state)=>state.searchBookList.books)[isbn];
const book = props.type === 'user'?user_book:admin_book;

const [loading, setLoading] = useState(true);
const description_length = 50;//Describe description length to be shown in frontend.

useEffect(() => {
@@ -43,10 +46,14 @@ export default function ShowBookDetails(props) {
);
if (response.status === 200) {
const data = await response.json();
setBook(data);
setDetails(data.book.description.substring(0, description_length));
if(props.type === 'admin'){
dispatch(setSearchQueryResult([data]));
}
setUserBook(data);
setLoading(false);
dispatch(setOverlayState(false));

setDetails(data.book.description.substring(0, description_length));
console.log("overlay after: ",showOverlay);
}
}
2 changes: 1 addition & 1 deletion src/common_components/cards_admin/AdminCard.jsx
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import TravelExploreTwoToneIcon from '@mui/icons-material/TravelExploreTwoTone'

const AdminCard = ({ Object }) => {

const path = `/admin/book/viewdetails/${Object.book.isbn}`
const path = `/admin/books/view-details/${Object.book.isbn}`
return (
<div className="custom-frame">
<div className="custom-image" style={{ backgroundImage: `url(${Object.book.cover_img})` }}></div>
8 changes: 4 additions & 4 deletions src/common_components/footer/Footer.jsx
Original file line number Diff line number Diff line change
@@ -8,17 +8,17 @@ export default function Footer() {
<div className="logo">
<div className="logo_img_name">

<img className='logg-image' src="/Book_logo.png" alt="Image loading...." />
<span className='font-serif text-2xl'>LitLib</span>
<img className='logg-image' src="/Library_Management_System/Book_logo.png" alt="Image loading...." />
<span className='text-2xl'>LitLib</span>
</div>
<Link to="/" className='text-xl underline hover:text-gray-500'>Contact Support</Link>
</div>
<div className="about">
<h1 className='font-serif text-2xl font-bold '>About</h1>
<h1 className='text-2xl font-bold '>About</h1>
<p className='text-left '>LitLib is an attempt to create a digital platform for streamlining the physical processes involved with college libraries, for both users and admins.</p>
</div>
<div className="details">
<h1 className='font-serif text-2xl font-bold '>Library Details</h1>
<h1 className='text-2xl font-bold '>Library Details</h1>
<span className=' left_text mt-1'>Name: <span className='right_text'>JU ETCE Departmental Library</span></span>
<span className=' left_text mt-1'>Address: <span className='right_text'>Kolkata</span></span>
<span className=' left_text mt-1'>Contact no.: <span className='right_text'>123
6 changes: 4 additions & 2 deletions src/features/searchBookReducer/SearchBookReducer.jsx
Original file line number Diff line number Diff line change
@@ -15,14 +15,16 @@ const searchBookListSlice = createSlice({
return acc
}, {})
},

updateSearchBookDetails: (state, action)=>{
const book_details = action.payload;
state.books[book_details.book.isbn] = book_details;
},
updateSearchBookAvailability: (state, action)=>{
console.log("called update search book avl : ",action.payload);
const {isbn, noOfCopies} = action.payload;
state.books[isbn].availability = noOfCopies;
console.log("isbn: ",isbn," no: ",noOfCopies);
state.books[isbn].book.no_of_copies = noOfCopies;
}

},
10 changes: 5 additions & 5 deletions src/pages/admin/adminBookDetails/AdminButtonSection.jsx
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ export default function AdminButtonSection(props) {
const ISBN = props.isbn;
const searchBookList = useSelector((state) => state.searchBookList.books);
const book_data = searchBookList[ISBN];
// const book_data = props.book;

console.log("book at admin book details section: ",book_data);

@@ -108,9 +109,8 @@ export default function AdminButtonSection(props) {

if(response.status === 200){
toast.success("Book details updated successfully.")
dispatch(setOverlayState(false));

const book_details= book_data;

let book_details={book:{},};
book_details.book.shelving_no = shelVingNo;
book_details.book.isbn = isbn;
book_details.book.date_of_publication = date_publication;
@@ -121,9 +121,9 @@ export default function AdminButtonSection(props) {
book_details.author_name = author;
book_details.sub_name = book_title;
book_details.book.no_of_copies = noOfCopies;

console.log("updated book admin: ",book_details);
dispatch(updateSearchBookDetails(book_details));// TODO check correctness.

dispatch(setOverlayState(false));
}
else{
toast.error("Error! updating book details.");
2 changes: 1 addition & 1 deletion src/pages/user/bookDetails/UserButtonSection.jsx
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ export default function UserButtonSection(props) {
const dispatch = useDispatch();

const noOfCopies = props.no_of_copies;
const isbn_no = props.book.book.isbn;
const isbn_no = props.book.book.isbn;
const navigate = useNavigate();
const wishListBook = useSelector((state)=> state.user.wishList);

0 comments on commit dcb4903

Please sign in to comment.