mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Added reactions on news items
This commit is contained in:
parent
62b35eac68
commit
64697efc96
10 changed files with 5711 additions and 87 deletions
|
@ -18,7 +18,7 @@ module.exports = {
|
||||||
'no-prototype-builtins': 'off',
|
'no-prototype-builtins': 'off',
|
||||||
'id-length': [
|
'id-length': [
|
||||||
'warn',
|
'warn',
|
||||||
{ exceptions: ['x', 'i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b'] },
|
{ exceptions: ['x', 'i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b', 'e'] },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
root: true,
|
root: true,
|
||||||
|
|
29
src/components/newsEntry.js
Normal file
29
src/components/newsEntry.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import ReactButton from './reactButton.js'
|
||||||
|
|
||||||
|
import styles from './newsEntry.module.css'
|
||||||
|
|
||||||
|
export default function NewsEntry({ newsKey, newsItem, uid, onReact }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className={styles.newsContainer}>
|
||||||
|
<div className={styles.itemNumber}>{newsKey} :</div>
|
||||||
|
<div
|
||||||
|
className={styles.newsTitle}
|
||||||
|
dangerouslySetInnerHTML={{ __html: newsItem.title }}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={styles.newsBody}
|
||||||
|
dangerouslySetInnerHTML={{ __html: newsItem.body }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<ReactButton
|
||||||
|
existingReacts={newsItem.reacts}
|
||||||
|
uid={uid}
|
||||||
|
onClick={onReact}
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
26
src/components/newsEntry.module.css
Normal file
26
src/components/newsEntry.module.css
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
.newsBody {
|
||||||
|
margin: 0px 5px;
|
||||||
|
font-size: 18px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsTitle {
|
||||||
|
font-size: 28px;
|
||||||
|
color: var(--text-color);
|
||||||
|
margin: 0px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemNumber {
|
||||||
|
color: #fff;
|
||||||
|
margin: 0px 5px;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsContainer {
|
||||||
|
margin: 20px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsContainer img {
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 200px;
|
||||||
|
}
|
109
src/components/reactButton.js
Normal file
109
src/components/reactButton.js
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
import Tooltip from './tooltip.js'
|
||||||
|
|
||||||
|
import styles from './reactButton.module.css'
|
||||||
|
import reactions from '../data/reactions.json'
|
||||||
|
|
||||||
|
const breakEvery = 7
|
||||||
|
|
||||||
|
function ExistingReacts({ existingReacts, onClick, uid }) {
|
||||||
|
return (
|
||||||
|
<div className={styles.reactionContainer}>
|
||||||
|
<div>React</div>
|
||||||
|
{existingReacts &&
|
||||||
|
Object.keys(existingReacts).map((key) => {
|
||||||
|
const currReact = existingReacts[key]
|
||||||
|
const react = reactions[key]
|
||||||
|
if (!react) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`${currReact.includes(uid) && styles.reacted}`}
|
||||||
|
key={key}
|
||||||
|
onClick={() => {
|
||||||
|
onClick(key, currReact.includes(uid))
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{react.emoji} {currReact.length}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function RenderEmojis({ onClick }) {
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
|
||||||
|
let index = 0
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Keresés..."
|
||||||
|
onChange={(event) => {
|
||||||
|
setSearch(event.target.value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{Object.keys(reactions).map((key) => {
|
||||||
|
const reaction = reactions[key]
|
||||||
|
if (!key.includes(search.toLowerCase())) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{index++ % breakEvery === 0 && (
|
||||||
|
<div key={`${key}_break`} className={styles.break} />
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
title={key}
|
||||||
|
key={key}
|
||||||
|
onClick={() => {
|
||||||
|
onClick(key)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{reaction.emoji}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ReactButton({ onClick, existingReacts, uid }) {
|
||||||
|
const [opened, setOpened] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onMouseEnter={() => {
|
||||||
|
setOpened(true)
|
||||||
|
}}
|
||||||
|
onMouseLeave={() => {
|
||||||
|
setOpened(false)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Tooltip
|
||||||
|
opened={opened}
|
||||||
|
text={() => (
|
||||||
|
<ExistingReacts
|
||||||
|
uid={uid}
|
||||||
|
onClick={onClick}
|
||||||
|
existingReacts={existingReacts}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className={styles.reactionContainer}>
|
||||||
|
<RenderEmojis
|
||||||
|
onClick={(e) => {
|
||||||
|
// setOpened(false)
|
||||||
|
onClick(e)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
37
src/components/reactButton.module.css
Normal file
37
src/components/reactButton.module.css
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
.reactionContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reactionContainer > input {
|
||||||
|
width: 100%;
|
||||||
|
background-color: var(--background-color);
|
||||||
|
color: var(--text-color);
|
||||||
|
border: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
margin: 2px 5px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reactionContainer > div {
|
||||||
|
margin: 2px 2px;
|
||||||
|
padding: 0px 8px;
|
||||||
|
background-color: #444;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reactionContainer > div:hover {
|
||||||
|
background-color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.break {
|
||||||
|
flex-basis: 100%;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reacted {
|
||||||
|
color: yellow;
|
||||||
|
}
|
13
src/components/tooltip.js
Normal file
13
src/components/tooltip.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import React from 'react'
|
||||||
|
import styles from './tooltip.module.css'
|
||||||
|
|
||||||
|
export default function Tooltip({ children, text, opened }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className={styles.tooltip}>
|
||||||
|
{text()}
|
||||||
|
{opened && <span className={styles.tooltiptext}>{children}</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
28
src/components/tooltip.module.css
Normal file
28
src/components/tooltip.module.css
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
.tooltip {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
border-bottom: 1px dotted black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip .tooltiptext {
|
||||||
|
width: 280px;
|
||||||
|
height: 250px;
|
||||||
|
max-width: 280px;
|
||||||
|
max-height: 250px;
|
||||||
|
background-color: #555;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 5px;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
bottom: 100%;
|
||||||
|
left: 0%;
|
||||||
|
margin-left: -60px;
|
||||||
|
transition: opacity 0.3s;
|
||||||
|
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
}
|
5417
src/data/reactions.json
Normal file
5417
src/data/reactions.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@ import Link from 'next/link'
|
||||||
|
|
||||||
import LoadingIndicator from '../components/LoadingIndicator'
|
import LoadingIndicator from '../components/LoadingIndicator'
|
||||||
import Sleep from '../components/sleep'
|
import Sleep from '../components/sleep'
|
||||||
|
import NewsEntry from '../components/newsEntry'
|
||||||
import DbSelector from '../components/dbSelector.js'
|
import DbSelector from '../components/dbSelector.js'
|
||||||
|
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
|
@ -21,77 +22,67 @@ const links = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Index(props) {
|
function fetchNews() {
|
||||||
const [news, setNews] = useState(null)
|
return new Promise((resolve) => {
|
||||||
const [allQrSelector, setAllQrSelector] = useState(null)
|
|
||||||
const motd = props.globalData.motd
|
|
||||||
// const userSpecificMotd = props.globalData.userSpecificMotd
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.info('Fetching news.json')
|
|
||||||
fetch(`${constants.apiUrl}news.json`, {
|
fetch(`${constants.apiUrl}news.json`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
})
|
})
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
return resp.json()
|
return resp.json()
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((res) => {
|
||||||
setNews(data)
|
resolve(res)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Index({ globalData }) {
|
||||||
|
const userId = globalData.userId
|
||||||
|
const motd = globalData.motd
|
||||||
|
const [news, setNews] = useState(null)
|
||||||
|
const [allQrSelector, setAllQrSelector] = useState(null)
|
||||||
|
// const userSpecificMotd = props.globalData.userSpecificMotd
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.info('Fetching news.json')
|
||||||
|
fetchNews().then((res) => {
|
||||||
|
setNews(res)
|
||||||
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const renderQAItem = (newsItem, key) => {
|
|
||||||
return (
|
|
||||||
<div key={key} className={styles.itemContainer}>
|
|
||||||
<div className={styles.itemNumber}>{key} :</div>
|
|
||||||
<div
|
|
||||||
className={styles.question}
|
|
||||||
dangerouslySetInnerHTML={{ __html: newsItem.q }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
className={styles.answer}
|
|
||||||
dangerouslySetInnerHTML={{ __html: newsItem.a }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderNewsItem = (newsItem, key) => {
|
|
||||||
return (
|
|
||||||
<div key={key} className={styles.itemContainer}>
|
|
||||||
<div className={styles.itemNumber}>{key} :</div>
|
|
||||||
<div
|
|
||||||
className={styles.newsTitle}
|
|
||||||
dangerouslySetInnerHTML={{ __html: newsItem.title }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
className={styles.newsBody}
|
|
||||||
dangerouslySetInnerHTML={{ __html: newsItem.body }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderNews = () => {
|
const renderNews = () => {
|
||||||
if (news) {
|
if (news) {
|
||||||
let questions = Object.keys(news)
|
let newsItems = Object.keys(news)
|
||||||
.map((key) => {
|
.map((key) => {
|
||||||
let newsItem = news[key]
|
let newsEntryData = news[key]
|
||||||
if (newsItem.q) {
|
return (
|
||||||
return (
|
<NewsEntry
|
||||||
<div key={key}>
|
onReact={(reaction, isDelete) => {
|
||||||
{renderQAItem(newsItem, key)}
|
console.log(reaction, isDelete)
|
||||||
<hr />
|
fetch(constants.apiUrl + 'infos', {
|
||||||
</div>
|
method: 'POST',
|
||||||
)
|
credentials: 'include',
|
||||||
} else {
|
headers: {
|
||||||
return (
|
Accept: 'application/json',
|
||||||
<div key={key}>
|
'Content-Type': 'application/json',
|
||||||
{renderNewsItem(newsItem, key)}
|
},
|
||||||
<hr />
|
body: JSON.stringify({
|
||||||
</div>
|
react: reaction,
|
||||||
)
|
newsKey: key,
|
||||||
}
|
isDelete: isDelete,
|
||||||
|
}),
|
||||||
|
}).then((res) => {
|
||||||
|
fetchNews().then((res) => {
|
||||||
|
setNews(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
uid={userId}
|
||||||
|
key={key}
|
||||||
|
newsKey={key}
|
||||||
|
newsItem={newsEntryData}
|
||||||
|
/>
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.reverse()
|
.reverse()
|
||||||
|
|
||||||
|
@ -100,7 +91,7 @@ export default function Index(props) {
|
||||||
<div className={styles.title}>News</div>
|
<div className={styles.title}>News</div>
|
||||||
<hr />
|
<hr />
|
||||||
<hr />
|
<hr />
|
||||||
<div className={styles.questionscontainer}>{questions}</div>
|
<div>{newsItems}</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,20 +30,6 @@
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.itemContainer {
|
|
||||||
margin: 20px 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.itemContainer:hover {
|
|
||||||
background-color: var(--hoover-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.newsBody {
|
|
||||||
margin: 0px 5px;
|
|
||||||
font-size: 18px;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
color: #9999ff;
|
color: #9999ff;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
|
@ -56,12 +42,6 @@
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.newsTitle {
|
|
||||||
font-size: 28px;
|
|
||||||
color: var(--text-color);
|
|
||||||
margin: 0px 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.question {
|
.question {
|
||||||
font-weight: 'bold';
|
font-weight: 'bold';
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
@ -73,12 +53,6 @@
|
||||||
margin: 0px 5px;
|
margin: 0px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.itemNumber {
|
|
||||||
color: #fff;
|
|
||||||
margin: 0px 5px;
|
|
||||||
font-size: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.repos {
|
.repos {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue