mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Contribute page imporvements, minor site imporvements
This commit is contained in:
parent
c68a445117
commit
cc3def0e6f
9 changed files with 78 additions and 138 deletions
|
@ -1,90 +1,35 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
import React from 'react'
|
||||
|
||||
import LoadingIndicator from '../LoadingIndicator.js'
|
||||
import TodoCard from './todoCard.js'
|
||||
import TodoRow from './todoRow.js'
|
||||
|
||||
import constants from '../../constants.json'
|
||||
import styles from './todoTable.module.css'
|
||||
|
||||
export default function TodoTable() {
|
||||
const [cards, setCards] = useState(null)
|
||||
const [columns, setColumns] = useState(null)
|
||||
const [categories, setCategories] = useState(null)
|
||||
const [userId, setUserId] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
console.info('Fetching todos')
|
||||
fetch(`${constants.apiUrl}todos`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
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) => {
|
||||
fetch(`${constants.apiUrl}todos?id=${id}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
setTodos(data)
|
||||
})
|
||||
}
|
||||
|
||||
if (!cards || !columns || !categories) {
|
||||
return <LoadingIndicator />
|
||||
}
|
||||
export default function TodoBoard(props) {
|
||||
const { tables, cards, userId, categories } = props
|
||||
|
||||
return (
|
||||
<div className={styles.tableContainer}>
|
||||
<div className={styles.table}>
|
||||
{Object.keys(columns).map((key) => {
|
||||
const category = columns[key]
|
||||
{Object.keys(tables).map((key) => {
|
||||
const table = tables[key]
|
||||
|
||||
const tableCards = cards.filter((card) => {
|
||||
return card.state === key
|
||||
})
|
||||
|
||||
return (
|
||||
<div className={styles.tableCol} key={key}>
|
||||
<div className={styles.categoryName}>{category.name}</div>
|
||||
{cards.map((card, i) => {
|
||||
if (card.state === key) {
|
||||
return (
|
||||
<TodoCard
|
||||
key={i}
|
||||
type={key}
|
||||
cardData={card}
|
||||
userId={userId}
|
||||
categories={categories}
|
||||
onClick={onCardClick}
|
||||
clickableTypes={Object.keys(columns).reduce(
|
||||
(acc, key) => {
|
||||
const col = columns[key]
|
||||
if (col.clickable) {
|
||||
acc.push(key)
|
||||
}
|
||||
return acc
|
||||
},
|
||||
[]
|
||||
)}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
<div className={styles.container} key={key}>
|
||||
<div className={styles.title}>{table.name}</div>
|
||||
{tableCards.map((card, i) => {
|
||||
return (
|
||||
<TodoRow
|
||||
key={i}
|
||||
type={key}
|
||||
rowData={card}
|
||||
userId={userId}
|
||||
categories={categories}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue