mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Sorting todos
This commit is contained in:
parent
12affac1a2
commit
4a7ad2d6c8
1 changed files with 13 additions and 10 deletions
|
@ -14,10 +14,6 @@ export default function TodoTable() {
|
|||
|
||||
useEffect(() => {
|
||||
console.info('Fetching todos')
|
||||
getTodos()
|
||||
}, [])
|
||||
|
||||
const getTodos = () => {
|
||||
fetch(`${constants.apiUrl}todos`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
|
@ -25,11 +21,19 @@ export default function TodoTable() {
|
|||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
setCards(data.todos.cards)
|
||||
setColumns(data.todos.columns)
|
||||
setCategories(data.todos.categories)
|
||||
setUserId(data.userId)
|
||||
setTodos(data)
|
||||
})
|
||||
}, [])
|
||||
|
||||
const setTodos = (data) => {
|
||||
setCards(
|
||||
data.todos.cards.sort((a, b) => {
|
||||
return b.votes.length - a.votes.length
|
||||
})
|
||||
)
|
||||
setColumns(data.todos.columns)
|
||||
setCategories(data.todos.categories)
|
||||
setUserId(data.userId)
|
||||
}
|
||||
|
||||
const onCardClick = (id) => {
|
||||
|
@ -40,8 +44,7 @@ export default function TodoTable() {
|
|||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data)
|
||||
getTodos()
|
||||
setTodos(data)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue