Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@testing-library/user-event": "^14.4.3",
"axios": "^1.3.5",
"isbn-validate": "^1.0.3",
"lodash": "^4.17.21",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
147 changes: 136 additions & 11 deletions src/components/Library/Library.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { orderBy } from 'lodash';
import { alpha } from '@mui/material/styles';
import { useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
Expand Down Expand Up @@ -65,6 +66,10 @@ export default function Library() {
const [showSnackBar, handleSnackBar] = useState(false);
const [removedItemName, setRemovedItemName] = useState('');

//table sorting states
const [sortOrder,setSortOrder]=useState(false);
const [sortingColumn,setSortingColumn]=useState("")

//Modal states
const [showModal, handleModalBox] = useState(false);
const [name, setName] = useState('');
Expand Down Expand Up @@ -150,6 +155,33 @@ export default function Library() {
}
};

// books table sort
const handleSort=(columnName,order)=>{
if (columnName == 'title') {
const sortedRows = orderBy(myRows, ['name'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'author') {
const sortedRows = orderBy(myRows, ['author'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'category') {
const sortedRows = orderBy(myRows, ['category'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'publisher') {
const sortedRows = orderBy(myRows, ['publisher'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'year') {
const sortedRows = orderBy(myRows, ['year'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'isbn') {
const sortedRows = orderBy(myRows, ['isbn'], [order]);
setMyRows(sortedRows);
} else if (columnName == 'edition') {
const sortedRows = orderBy(myRows, ['edition'], [order]);
setMyRows(sortedRows);
}
}


//Check if ISBN is valid
const handleISBNChange = (event) => {
const value = event.target.value;
Expand Down Expand Up @@ -271,9 +303,7 @@ export default function Library() {
)}
</Box>
</Modal>
//book review modal end//

//book read review modal start//
//book review modal end// //book read review modal start//
<div>
<Dialog
open={enableReviewModal}
Expand Down Expand Up @@ -423,13 +453,108 @@ export default function Library() {
<TableHead>
<TableRow>
<TableCell>Action</TableCell>
<TableCell>Title</TableCell>
<TableCell align='center'>Author</TableCell>
<TableCell align='center'>Category</TableCell>
<TableCell align='center'>Publisher</TableCell>
<TableCell align='center'>ISBN</TableCell>
<TableCell align='center'>Year</TableCell>
<TableCell align='center'>Edition</TableCell>
<TableCell align='center'>
<TableSortLabel
active={true}
direction={
sortingColumn == 'title' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('title');
handleSort('title', sortOrder ? 'asc' : 'desc');
}}>
Title
</TableSortLabel>
</TableCell>
<TableCell align='center'>
<TableSortLabel
active={true}
direction={
sortingColumn == 'author' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('author');
handleSort('author', sortOrder ? 'asc' : 'desc');
}}>
Author
</TableSortLabel>{' '}
</TableCell>
<TableCell align='center'>
{' '}
<TableSortLabel
active={true}
direction={
sortingColumn == 'category' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('category');
handleSort('category', sortOrder ? 'asc' : 'desc');
}}>
Category
</TableSortLabel>{' '}
</TableCell>
<TableCell align='center'>
{' '}
<TableSortLabel
active={true}
direction={
sortingColumn == 'publisher' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('publisher');
handleSort('publisher', sortOrder ? 'asc' : 'desc');
}}>
Publisher
</TableSortLabel>{' '}
</TableCell>
<TableCell align='center'>
{' '}
<TableSortLabel
active={true}
direction={
sortingColumn == 'isbn' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('isbn');
handleSort('isbn', sortOrder ? 'asc' : 'desc');
}}>
ISBN
</TableSortLabel>
</TableCell>
<TableCell align='center'>
{' '}
<TableSortLabel
active={true}
direction={
sortingColumn == 'year' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('year');
handleSort('year', sortOrder ? 'asc' : 'desc');
}}>
Year
</TableSortLabel>{' '}
</TableCell>
<TableCell align='center'>
<TableSortLabel
active={true}
direction={
sortingColumn == 'edition' && sortOrder ? 'dsc' : 'asc'
}
onClick={() => {
setSortOrder(!sortOrder);
setSortingColumn('edition');
handleSort('edition', sortOrder ? 'asc' : 'desc');
}}>
Edition
</TableSortLabel>
</TableCell>
<TableCell align='center'>Review</TableCell>
</TableRow>
</TableHead>
Expand Down Expand Up @@ -457,7 +582,7 @@ export default function Library() {
}}
/>
</TableCell>
<TableCell component='th' scope='row'>
<TableCell component='th' scope='row' align='center'>
{row.name}
</TableCell>
<TableCell align='center'>{row.author}</TableCell>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Library/data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "Learning the Vi Editor",
"author": "",
"author": "Arnold Robins and Linda Lamb",
"publisher": "O'Reilly",
"isbn": "1-56592-426-6",
"year": "1998",
Expand Down