Skip to content

Add paging to users/{user_ID}/tasks #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion ui/react-ui/src/components/app/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './App.css';
import {BrowserRouter as Router, Route,} from 'react-router-dom';
import UserTasks from '../routes/userTasks/UserTasks.js';
import UserTasks from '../routes/userTasks/UserTasksPaginated.js';
import Home from '../routes/home/Home.js';
import User from '../routes/userid/userid.js';
import Users from '../routes/users/UsersPaginated';
Expand Down
4 changes: 3 additions & 1 deletion ui/react-ui/src/components/routes/userTasks/UserTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const UserTasks = () => {
.catch((error) => console.error(error))
}, [userId]);

/*
function deleteTask(taskId){
const messages = this.state.messages.filter((_, index) => index !== i)
this.setState({ messages });

}
*/

return (
<>
Expand All @@ -37,7 +39,7 @@ const UserTasks = () => {
? <BootstrapTable heatherItems={Object.keys(userTasks[2][0])} rows={userTasks[2]} />
: <h3>User {userId} Tasks Not Found</h3>
}
<button onClick={() => this.deleteTask()}>Delete Task</button>
{/* <button onClick={() => this.deleteTask()}>Delete Task</button> */}
</Container>
</>
)
Expand Down
73 changes: 73 additions & 0 deletions ui/react-ui/src/components/routes/userTasks/UserTasksPaginated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, {useState, useEffect} from 'react';
import {useParams} from 'react-router-dom';
import BackButton from '../../bootstrapBackButton/BootstrapBackButton'
import BootstrapTable from 'react-bootstrap-table-next';
import paginationFactory from 'react-bootstrap-table2-paginator'
import * as ReactBootStrap from 'react-bootstrap';
import axios from 'axios';

const UserTasksPaginated = () => {
let [userTasks, setUserTasks] = useState([]);
let [loading, setLoading] = useState(false);
let {userId} = useParams();

const columns = [
{dataField: "taskId", text: "Task ID"},
{dataField: "title", text: "Task"},
{dataField: "description", text: "Description"},
{dataField: "createdDate", text: "Date Created"},
{dataField: "dueDate", text: "Due Date"},
{dataField: "completed", text: "Is Complete"},
{dataField: "completedDate", text: "Date Completed"}
]

// TODO:
// Add options to delete a task
// sort of present in original UserTasks.js but didn't really work

const getData = async (userId)=>{
try{
/*
* I wanted to use the fetchTableState from ../../utils
* But it just returned the data in a really unhelpful way with an incorrect
* "title" and "subtitle" tacked onto the front
*/
const data = await axios.get(
`https://nsc-fun-dev-usw2-thursday.azurewebsites.net/api/users/${userId}/tasks`
);
console.log(data);
setUserTasks(data.data);
} catch (error) {
console.error(error);
}
}

useEffect(() => {
getData(userId);
setLoading(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it should go before your axios call. I don't see any place that shuts off loading afterwards

}, [userId]);

// TODO:
// Table spacing is bad in narrow windows

return (
<div className="pagination">
<div><BackButton /></div>
{loading
?(
<div className="table-wrapper">
<BootstrapTable
rowStyle = {{backgroundColor: 'white'}}
className="table"
keyField="taskId"
data={userTasks}
columns={columns}
pagination={paginationFactory()}
/>
</div>
): (<ReactBootStrap.Spinner animation="border" />)}
</div>
)
}

export default UserTasksPaginated;