mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Added todo table
This commit is contained in:
parent
1a982b69c9
commit
cbd6bf2baa
15 changed files with 608 additions and 157 deletions
|
@ -1,50 +0,0 @@
|
|||
import styles from './Helps.module.css'
|
||||
|
||||
import helps from '../data/helps.json'
|
||||
const header = helps.header
|
||||
const helpRows = helps.rows
|
||||
|
||||
export default function Helps () {
|
||||
const renderTable = () => {
|
||||
return (
|
||||
<table className={styles.helpTable}>
|
||||
<thead>
|
||||
<tr className={styles.helpHeader}>
|
||||
{header.map((h, i) => {
|
||||
return (
|
||||
<td key={i}>
|
||||
{h}
|
||||
</td>
|
||||
)
|
||||
})}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Object.keys(helpRows).map((key, i) => {
|
||||
const item = helpRows[key]
|
||||
return (
|
||||
<tr className={styles.helpRow} key={i}>
|
||||
<td>
|
||||
{item.name}
|
||||
</td>
|
||||
<td>
|
||||
{item.description}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className={styles.text}>
|
||||
<div className={styles.title}>
|
||||
Amiben tudsz segíteni:
|
||||
</div>
|
||||
<div>
|
||||
{renderTable()}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
.text {
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.helpTable {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.helpTable td {
|
||||
padding: 5px 2px;
|
||||
}
|
||||
|
||||
.helpHeader {
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.helpRow td {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.title {
|
||||
text-align: center;
|
||||
}
|
48
src/components/todoStuff/todoCard.js
Normal file
48
src/components/todoStuff/todoCard.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import React from 'react'
|
||||
|
||||
import styles from './todoCard.module.css'
|
||||
|
||||
const clickableTypes = ['todo', 'blocked', 'inprogress', 'testing']
|
||||
|
||||
export default function TodoCard(props) {
|
||||
const { categories, type, onClick, userId } = props
|
||||
const { name, description, category, points, votes, id } = props.cardData
|
||||
const clickable = clickableTypes.includes(type)
|
||||
const voted = votes.includes(userId)
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${styles.card} ${clickable && styles.clickable} ${voted &&
|
||||
styles.voted}`}
|
||||
title={description}
|
||||
onClick={() => {
|
||||
if (clickable) {
|
||||
onClick(id)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className={styles.description}>
|
||||
<span className={styles.id}>{`#${id}`}</span>
|
||||
{name}
|
||||
</div>
|
||||
<div className={styles.category}>
|
||||
<span
|
||||
style={{
|
||||
backgroundColor: categories[category].color,
|
||||
color: 'white',
|
||||
borderRadius: '2px',
|
||||
padding: '0px 2px',
|
||||
}}
|
||||
>
|
||||
{category}
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.numbers}>
|
||||
<div>
|
||||
<div>{`Votes: ${votes.length}`}</div>
|
||||
</div>
|
||||
<div>{points}</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
48
src/components/todoStuff/todoCard.module.css
Normal file
48
src/components/todoStuff/todoCard.module.css
Normal file
|
@ -0,0 +1,48 @@
|
|||
.card {
|
||||
border: 2px solid #99f;
|
||||
border-radius: 2px;
|
||||
padding: 5px;
|
||||
margin: 6px 3px;
|
||||
}
|
||||
|
||||
.voted {
|
||||
border: 2px solid #cf9;
|
||||
}
|
||||
|
||||
.clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clickable:hover {
|
||||
background-color: #333;
|
||||
border: 2px solid #f99;
|
||||
}
|
||||
|
||||
.card > div {
|
||||
margin: 5px 0px;
|
||||
}
|
||||
|
||||
.description {
|
||||
word-break: normal;
|
||||
font-size: 14px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.category {
|
||||
word-break: break-all;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.numbers {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.numbers > div {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.id {
|
||||
margin: 0px 3px;
|
||||
color: #999;
|
||||
}
|
82
src/components/todoStuff/todoTable.js
Normal file
82
src/components/todoStuff/todoTable.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
|
||||
import LoadingIndicator from '../LoadingIndicator.js'
|
||||
import TodoCard from './todoCard.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')
|
||||
getTodos()
|
||||
}, [])
|
||||
|
||||
const getTodos = () => {
|
||||
fetch(`${constants.apiUrl}todos`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
setCards(data.todos.cards)
|
||||
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) => {
|
||||
console.log(data)
|
||||
getTodos()
|
||||
})
|
||||
}
|
||||
|
||||
if (!cards || !columns || !categories) {
|
||||
return <LoadingIndicator />
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.table}>
|
||||
{Object.keys(columns).map((key) => {
|
||||
const category = columns[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}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
16
src/components/todoStuff/todoTable.module.css
Normal file
16
src/components/todoStuff/todoTable.module.css
Normal file
|
@ -0,0 +1,16 @@
|
|||
.table {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.categoryName {
|
||||
text-align: center;
|
||||
margin: 5px 0px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tableCol {
|
||||
flex: 1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue