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
|
@ -3,9 +3,8 @@ import React from 'react'
|
|||
import styles from './todoCard.module.css'
|
||||
|
||||
export default function TodoCard(props) {
|
||||
const { categories, type, onClick, userId, clickableTypes } = props
|
||||
const { categories, onClick, userId, clickable } = props
|
||||
const { name, description, category, points, votes, id } = props.cardData
|
||||
const clickable = clickableTypes.includes(type)
|
||||
const voted = votes.includes(userId)
|
||||
|
||||
return (
|
||||
|
|
|
@ -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>
|
||||
)
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
.table {
|
||||
display: flex;
|
||||
min-width: 800px;
|
||||
max-height: 600px;
|
||||
}
|
||||
|
||||
.categoryName {
|
||||
text-align: center;
|
||||
margin: 5px 0px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tableCol {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.tableContainer {
|
||||
overflow-x: scroll;
|
||||
overflow-y: scroll;
|
||||
margin: 5px 0px;
|
||||
}
|
||||
|
||||
.table {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.container {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.title {
|
||||
text-align: center;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue