From 1a02ae2e985a66ed3289164a9eddc20b0ca22766 Mon Sep 17 00:00:00 2001 From: mrfry Date: Mon, 30 Nov 2020 14:03:13 +0100 Subject: [PATCH] Contribute page imporvements, sidebar for cards --- src/components/sidebar.js | 20 +++ src/components/sidebar.module.css | 25 +++ src/components/todoStuff/todoCard.js | 12 +- src/components/todoStuff/todoCard.module.css | 7 +- src/components/todoStuff/todoRow.js | 8 +- src/components/todoStuff/todoRow.module.css | 6 + src/components/todoStuff/todoSidebar.js | 63 ++++++++ .../todoStuff/todoSidebar.module.css | 54 +++++++ src/components/todoStuff/todoTable.js | 3 +- src/components/todoStuff/todoTable.module.css | 3 + src/components/todoStuff/todos.js | 145 +++++++++++------- src/components/todoStuff/todos.module.css | 0 src/pages/contribute.js | 7 +- 13 files changed, 274 insertions(+), 79 deletions(-) create mode 100644 src/components/sidebar.js create mode 100644 src/components/sidebar.module.css create mode 100644 src/components/todoStuff/todoSidebar.js create mode 100644 src/components/todoStuff/todoSidebar.module.css create mode 100644 src/components/todoStuff/todos.module.css diff --git a/src/components/sidebar.js b/src/components/sidebar.js new file mode 100644 index 0000000..d853468 --- /dev/null +++ b/src/components/sidebar.js @@ -0,0 +1,20 @@ +import React from 'react' + +import styles from './sidebar.module.css' + +export default function Sidebar(props) { + const { onClose } = props + return ( +
+
{ + onClose() + }} + > + {'>'} +
+
{props.children}
+
+ ) +} diff --git a/src/components/sidebar.module.css b/src/components/sidebar.module.css new file mode 100644 index 0000000..407401c --- /dev/null +++ b/src/components/sidebar.module.css @@ -0,0 +1,25 @@ +.container { + background-color: var(--background-color); + border-left: 3px solid #99f; + top: 0; + right: 0px; + height: 100%; + width: 400px; + max-width: 100%; + position: fixed; + + display: flex; +} + +.closeBorder { + padding: 5px; + cursor: pointer; + display: flex; + flex-flow: column; + justify-content: center; + color: white; +} + +.closeBorder:hover { + background-color: #333; +} diff --git a/src/components/todoStuff/todoCard.js b/src/components/todoStuff/todoCard.js index eaf0ea2..051832a 100644 --- a/src/components/todoStuff/todoCard.js +++ b/src/components/todoStuff/todoCard.js @@ -3,19 +3,15 @@ import React from 'react' import styles from './todoCard.module.css' export default function TodoCard(props) { - const { categories, onClick, userId, clickable } = props - const { name, description, category, points, votes, id } = props.cardData + const { categories, onClick, userId } = props + const { name, category, points, votes, id } = props.cardData const voted = votes.includes(userId) return (
{ - if (clickable) { - onClick(id) - } + onClick(props.cardData) }} >
diff --git a/src/components/todoStuff/todoCard.module.css b/src/components/todoStuff/todoCard.module.css index baaf9c7..86cb918 100644 --- a/src/components/todoStuff/todoCard.module.css +++ b/src/components/todoStuff/todoCard.module.css @@ -3,17 +3,14 @@ border-radius: 2px; padding: 5px; margin: 6px 3px; + cursor: pointer; } .voted { border: 2px solid #cf9; } -.clickable { - cursor: pointer; -} - -.clickable:hover { +.card:hover { background-color: #333; border: 2px solid #f99; } diff --git a/src/components/todoStuff/todoRow.js b/src/components/todoStuff/todoRow.js index 6714428..cba5bee 100644 --- a/src/components/todoStuff/todoRow.js +++ b/src/components/todoStuff/todoRow.js @@ -3,14 +3,16 @@ import React from 'react' import styles from './todoRow.module.css' export default function TodoRow(props) { - const { categories, userId } = props - const { name, description, category, votes, id } = props.rowData + const { categories, userId, onClick } = props + const { name, category, votes, id } = props.rowData const voted = votes.includes(userId) return (
{ + onClick(props.rowData) + }} className={`${styles.row} ${voted && styles.voted}`} - title={description} >
{`#${id}`}
{name}
diff --git a/src/components/todoStuff/todoRow.module.css b/src/components/todoStuff/todoRow.module.css index 18af760..90085de 100644 --- a/src/components/todoStuff/todoRow.module.css +++ b/src/components/todoStuff/todoRow.module.css @@ -4,6 +4,12 @@ border-radius: 2px; padding: 5px; margin: 6px 3px; + cursor: pointer; +} + +.row:hover { + background-color: #333; + border: 2px solid #f99; } .row > div { diff --git a/src/components/todoStuff/todoSidebar.js b/src/components/todoStuff/todoSidebar.js new file mode 100644 index 0000000..c57c6f2 --- /dev/null +++ b/src/components/todoStuff/todoSidebar.js @@ -0,0 +1,63 @@ +import React from 'react' + +import styles from './todoSidebar.module.css' + +export default function Todos({ card, userId, categories, columns, voteOn }) { + const { name, description, category, points, votes, id } = card + const voteable = columns[card.state].clickable + + // TODO: hide vote button if not voteable + return ( +
+
+ #{id} + {name} + + {categories[category].name} + +
+
+
+
Nehézség:
+
{points}
+
+
+
Szavazatok:
+
{votes.length}
+
+
+ {description && ( + <> +
Leírás
+
+
+ + )} +
+ {voteable && ( +
{ + voteOn(card) + }} + > + {votes.includes(userId) ? 'Szavazat visszavonása' : 'Szavazás'} +
+ )} +
+ ) +} diff --git a/src/components/todoStuff/todoSidebar.module.css b/src/components/todoStuff/todoSidebar.module.css new file mode 100644 index 0000000..8159b96 --- /dev/null +++ b/src/components/todoStuff/todoSidebar.module.css @@ -0,0 +1,54 @@ +.container { + display: flex; + flex-flow: column; + margin: 5px; +} + +.container > hr { + width: 100%; +} + +.title { + color: #99f; + font-size: 18px; +} + +.name { + color: #99f; + font-size: 20px; + margin: 20px 0px; +} + +.category { + word-break: break-all; + font-size: 10px; +} + +.id { + font-size: 16px; + margin: 0px 3px; + color: #999; +} + +.row { + display: flex; + justify-content: space-between; +} + +.button { + border: 2px solid #99f; + border-radius: 3px; + text-align: center; + cursor: pointer; +} + +.button:hover { + background-color: #333; +} + +.votedtext { + color: #cf9; +} +.voted { + border: 2px solid #cf9; +} diff --git a/src/components/todoStuff/todoTable.js b/src/components/todoStuff/todoTable.js index be909fa..01e7ae9 100644 --- a/src/components/todoStuff/todoTable.js +++ b/src/components/todoStuff/todoTable.js @@ -5,7 +5,7 @@ import TodoRow from './todoRow.js' import styles from './todoTable.module.css' export default function TodoBoard(props) { - const { tables, cards, userId, categories } = props + const { tables, cards, userId, categories, onClick } = props return (
@@ -23,6 +23,7 @@ export default function TodoBoard(props) { {tableCards.map((card, i) => { return ( { @@ -13,11 +17,10 @@ const byVotes = (a, b) => { export default function Todos() { const [loaded, setLoaded] = useState(false) const [columns, setColumns] = useState(null) - const [boardCards, setBoardCards] = useState(null) - const [tables, setTables] = useState(null) - const [tableCards, setTableCards] = useState(null) + const [cards, setCards] = useState(null) const [categories, setCategories] = useState(null) const [userId, setUserId] = useState(null) + const [sidebarCard, setSidebarCard] = useState(null) useEffect(() => { console.info('Fetching todos') @@ -36,72 +39,98 @@ export default function Todos() { setCategories(data.todos.categories) setUserId(data.userId) - let bCards = [] - let tCards = [] - data.todos.cards.forEach((card) => { - if (data.todos.columns[card.state].type === 'table') { - tCards.push(card) - } else { - bCards.push(card) - } - }) - - setTableCards(tCards.sort(byVotes)) - setBoardCards(bCards.sort(byVotes)) - - let cols = {} - let tables = {} - Object.keys(data.todos.columns).forEach((key) => { - const col = data.todos.columns[key] - if (col.type !== 'table') { - cols = { - ...cols, - [key]: col, - } - } else { - tables = { - ...tables, - [key]: col, - } - } - }) - setColumns(cols) - setTables(tables) - + setCards(data.todos.cards) + setColumns(data.todos.columns) setLoaded(true) } - const onCardClick = (id) => { - fetch(`${constants.apiUrl}todos?id=${id}`, { - credentials: 'include', - }) - .then((resp) => { - return resp.json() - }) - .then((data) => { - setTodos(data) - }) + const onClick = (card) => { + setSidebarCard(card.id) } if (!loaded) { return } + let bCards = [] + let tCards = [] + cards.forEach((card) => { + if (columns[card.state].type === 'table') { + tCards.push(card) + } else { + bCards.push(card) + } + }) + bCards = bCards.sort(byVotes) + tCards = tCards.sort(byVotes) + + let cols = {} + let tables = {} + Object.keys(columns).forEach((key) => { + const col = columns[key] + if (col.type !== 'table') { + cols = { + ...cols, + [key]: col, + } + } else { + tables = { + ...tables, + [key]: col, + } + } + }) + return (
- - + {sidebarCard && ( + { + setSidebarCard(null) + }} + > + { + return card.id === sidebarCard + })} + userId={userId} + categories={categories} + columns={columns} + voteOn={(card) => { + fetch(`${constants.apiUrl}todos?id=${card.id}`, { + credentials: 'include', + }) + .then((resp) => { + return resp.json() + }) + .then((data) => { + setTodos(data) + }) + }} + /> + + )} +
+ + +
) } diff --git a/src/components/todoStuff/todos.module.css b/src/components/todoStuff/todos.module.css new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/contribute.js b/src/pages/contribute.js index 4227c8f..5d32326 100644 --- a/src/pages/contribute.js +++ b/src/pages/contribute.js @@ -62,10 +62,9 @@ export default function contribute() { return (
- Egy kártyára kattintva szavazhatsz. Minél több szavazat érkezik egy - kártyára, annál magasabb lesz a pioritása. Jobb alsó szám minél több, - annál nehezebb a feladat. Tartsd egeret kártyán részletesebb leírásért - (ha van hozzá) + Egy kártyára kattintva nézheted meg a részleteket, vagy szavazhatsz. + Minél több szavazat érkezik egy kártyára, annál magasabb lesz a + pioritása. Jobb alsó szám minél több, annál nehezebb a feladat.
Itt írhatsz todo-ra ötleteket