Multiple db handling, font size changes

This commit is contained in:
mrfry 2021-01-10 15:41:08 +01:00
parent a0d51266a0
commit 07b34762c3
8 changed files with 119 additions and 46 deletions

View file

@ -13,6 +13,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"eslint-plugin-react": "^7.22.0",
"next": "^9.3.1", "next": "^9.3.1",
"react": "^16.13.1", "react": "^16.13.1",
"react-dom": "^16.13.1", "react-dom": "^16.13.1",

View file

@ -1,5 +1,5 @@
.subjName { .subjName {
font-size: 24px; font-size: 18px;
background-color: #9999ff; background-color: #9999ff;
color: black; color: black;
padding: 10px; padding: 10px;

View file

@ -1,6 +1,5 @@
.questionInput { .questionInput {
flex-grow: 1; flex-grow: 1;
font-size: 22px;
background-color: var(--background-color); background-color: var(--background-color);
color: white; color: white;
border: none; border: none;
@ -20,7 +19,6 @@
.deleteButton { .deleteButton {
padding: 6px; padding: 6px;
font-size: 22px;
background-color: var(--background-color); background-color: var(--background-color);
color: white; color: white;
cursor: pointer; cursor: pointer;

View file

@ -4,7 +4,6 @@
color: white; color: white;
background-color: #212127; background-color: #212127;
border: none; border: none;
font-size: 18px;
flex-grow: 1; flex-grow: 1;
} }
@ -17,7 +16,6 @@
width: 80px; width: 80px;
background-color: var(--background-color); background-color: var(--background-color);
color: white; color: white;
font-size: 23px;
cursor: pointer; cursor: pointer;
border: none; border: none;
} }

View file

@ -1,4 +1,4 @@
{ {
"apiUrl": "https://api.frylabs.net/", "apiUrl": "http://localhost:8080/",
"maxQuestionsToRender": 250 "maxQuestionsToRender": 250
} }

View file

@ -16,7 +16,7 @@ a {
.link { .link {
margin: 20px; margin: 20px;
font-size: 20px; font-size: 16px;
} }
.sidebarLink { .sidebarLink {
@ -66,7 +66,7 @@ a {
} }
.sidebarheader { .sidebarheader {
font-size: 40px; font-size: 30px;
color: var(--bright-color); color: var(--bright-color);
display: flex; display: flex;
text-align: center; text-align: center;
@ -84,7 +84,7 @@ a {
.question { .question {
word-wrap: break-word; word-wrap: break-word;
font-weight: bold; font-weight: bold;
font-size: 17px; font-size: 15px;
color: #ffffff; color: #ffffff;
} }
@ -104,7 +104,7 @@ a {
vertical-align: middle; vertical-align: middle;
color: #fff; color: #fff;
font-size: 30px; font-size: 25px;
} }
.uquestioncontainer { .uquestioncontainer {
@ -121,7 +121,7 @@ a {
.uquestion { .uquestion {
font-weight: 'bold'; font-weight: 'bold';
font-size: 16px; font-size: 14px;
color: #fff; color: #fff;
margin: 5px; margin: 5px;
} }
@ -133,7 +133,7 @@ a {
.uquestionnumber { .uquestionnumber {
color: #fff; color: #fff;
margin: 5px; margin: 5px;
font-size: 20px; font-size: 16px;
} }
.link { .link {
@ -141,7 +141,7 @@ a {
} }
.subjItem { .subjItem {
font-size: 18px; font-size: 16px;
padding: 3px; padding: 3px;
cursor: pointer; cursor: pointer;
float: 1; float: 1;
@ -158,3 +158,26 @@ a {
background-color: #555; background-color: #555;
color: white; color: white;
} }
select {
cursor: pointer;
width: 100%;
max-width: 100%;
appearance: none;
border: 1px solid var(--background-color);
box-shadow: 0 1px 0 1px rgba(0, 0, 0, 0.04);
line-height: 35px;
border-radius: 3px;
background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E'),
linear-gradient(to bottom, #222426 0%, #222426 100%);
background-repeat: no-repeat, repeat;
background-position: right 0.7em top 50%, 0 0;
background-size: 0.65em auto, 100%;
color: white;
}
select:hover {
border: 1px solid #99f;
}

View file

@ -19,8 +19,10 @@ const views = {
// TODO: question.data editor // TODO: question.data editor
// TODO: edit \n-s in questions / answers // TODO: edit \n-s in questions / answers
export default function Index(props) { export default function Index() {
const [data, setData] = useState(null) const [data, setData] = useState(null)
const [qdbs, setQdbs] = useState(null)
const [selectedDb, setSelectedDb] = useState()
const [view, setView] = useState(views.welcome) const [view, setView] = useState(views.welcome)
const [sending, setSending] = useState(false) const [sending, setSending] = useState(false)
const [error, setError] = useState(null) const [error, setError] = useState(null)
@ -29,55 +31,69 @@ export default function Index(props) {
const [initialCount, setInitialCount] = useState({}) const [initialCount, setInitialCount] = useState({})
const getCount = (d) => { useEffect(() => {
if (selectedDb) {
loadData()
}
}, [selectedDb])
const getCount = (data) => {
return { return {
subjectCount: d.length, subjectCount: data.length,
questionCount: d.reduce((acc, subj) => { questionCount: data.reduce((acc, subj) => {
acc += subj.Questions.length acc += subj.Questions.length
return acc return acc
}, 0), }, 0),
} }
} }
const setIndexes = (d) => { const setIndexes = (data) => {
d.forEach((subj, i) => { data.forEach((subj, i) => {
subj.ind = i subj.ind = i
subj.Questions.forEach((question, j) => { subj.Questions.forEach((question, j) => {
question.ind = j question.ind = j
}) })
}) })
return d return data
} }
const LoadData = () => { const loadData = () => {
setData(null) setData(null)
const toFetch = `${constants.apiUrl}data.json` if (!selectedDb) {
alert('Válassz egy adatbázist!')
return
}
const toFetch = `${constants.apiUrl}${selectedDb.path}`
console.info('Fetching', toFetch) console.info('Fetching', toFetch)
fetch(toFetch, { fetch(toFetch, {
credentials: 'include', credentials: 'include',
}) })
.then((resp) => { .then((resp) => {
if (resp && resp.ok) { return resp.json()
return resp.json()
} else {
console.error('Error while fetching data')
setError('Error while fetching data')
}
}) })
.then((resp) => { .then((resp) => {
setData(setIndexes(resp)) setData(setIndexes(resp))
const count = getCount(resp) const count = getCount(resp)
setInitialCount(count) setInitialCount(count)
}) })
.catch((e) => { .catch((error) => {
console.error(e) console.error(error)
console.error('Error while fetching data') console.error('Error while fetching data')
setError('Error while fetching data') setError('Error while fetching data')
}) })
} }
useEffect(() => { useEffect(() => {
LoadData() fetch(`${constants.apiUrl}getdbs`, {
credentials: 'include',
})
.then((resp) => {
return resp.json()
})
.then((resp) => {
setQdbs(resp)
})
}, []) }, [])
if (error) { if (error) {
@ -138,7 +154,7 @@ export default function Index(props) {
if (resp.status === 'ok') { if (resp.status === 'ok') {
alert(`Sikeres feltöltés! thankx ${resp.user}!`) // eslint-disable-line alert(`Sikeres feltöltés! thankx ${resp.user}!`) // eslint-disable-line
console.log('OK') console.log('OK')
LoadData() loadData()
} else if (resp.status === 'invalidPass') { } else if (resp.status === 'invalidPass') {
alert('Hibás jelszó!') // eslint-disable-line alert('Hibás jelszó!') // eslint-disable-line
console.log('invalidPass') console.log('invalidPass')
@ -150,15 +166,15 @@ export default function Index(props) {
console.error(resp.message) console.error(resp.message)
} }
}) })
.catch((e) => { .catch((error) => {
setSending(false) setSending(false)
alert('Hiba feltöltés közben! (kliens oldalon)! Több adat konzolban') // eslint-disable-line alert('Hiba feltöltés közben! (kliens oldalon)! Több adat konzolban') // eslint-disable-line
console.error('Error posting data', e) console.error('Error posting data', error)
}) })
} catch (e) { } catch (error) {
setSending(false) setSending(false)
alert('Hiba feltöltés közben! (kliens oldalon)! Több adat konzolban') // eslint-disable-line alert('Hiba feltöltés közben! (kliens oldalon)! Több adat konzolban') // eslint-disable-line
console.error('Error posting data', e) console.error('Error posting data', error)
} }
} }
@ -188,7 +204,7 @@ export default function Index(props) {
{initialCount.subjectCount || '...'} tárgy {initialCount.subjectCount || '...'} tárgy
<p /> <p />
Itt az éles adatbázis kérdései jelennek meg, amiket tudsz Itt az éles adatbázis kérdései jelennek meg, amiket tudsz
szerkeszteni. A kérdésekhez tartozó '.data' prop-ot még nem tudod szerkeszteni. A kérdésekhez tartozó .data prop-ot még nem tudod
rendesen szerkeszteni, az később lesz implementálva. A Tárgy / Kérdés rendesen szerkeszteni, az később lesz implementálva. A Tárgy / Kérdés
nézet között tudsz válogatni. nézet között tudsz válogatni.
<br /> <br />
@ -204,12 +220,42 @@ export default function Index(props) {
} }
} }
const renderDbSelector = () => {
return (
<>
<select
style={{ margin: '10px 0px' }}
defaultValue={-1}
onChange={(event) => {
setSelectedDb(qdbs[event.target.value])
}}
>
<option disabled value={-1}>
{' -- Válassz egy kérdés adatbázist -- '}
</option>
{qdbs.map((qdb, i) => {
return (
<option value={i} key={qdb.name}>
{qdb.name}
</option>
)
})}
</select>
</>
)
}
if (!qdbs) {
return <LoadingIndicator />
}
return ( return (
<div> <div>
{renderDbSelector()}
<div className={styles.optionsButtonContainer}> <div className={styles.optionsButtonContainer}>
<span <span
onClick={() => { onClick={() => {
LoadData() loadData()
}} }}
> >
Újratöltés Újratöltés
@ -219,8 +265,8 @@ export default function Index(props) {
placeholder="Jelszó feltöltéshez" placeholder="Jelszó feltöltéshez"
type="text" type="text"
value={password} value={password}
onChange={(e) => { onChange={(event) => {
setPassword(e.target.value) setPassword(event.target.value)
}} }}
/> />
</span> </span>
@ -239,14 +285,22 @@ export default function Index(props) {
<div className={styles.viewButtonContainer}> <div className={styles.viewButtonContainer}>
<span <span
onClick={() => { onClick={() => {
setView(views.question) if (selectedDb) {
setView(views.question)
} else {
alert('Válassz egy adatbázist!')
}
}} }}
> >
Kérdés nézet Kérdés nézet
</span> </span>
<span <span
onClick={() => { onClick={() => {
setView(views.subject) if (selectedDb) {
setView(views.subject)
} else {
alert('Válassz egy adatbázist!')
}
}} }}
> >
Tárgy nézet Tárgy nézet

View file

@ -2,9 +2,8 @@
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
margin: 5px; margin: 5px;
padding: 5px; padding: 10px;
height: 45px; font-size: 18px;
font-size: 30px;
width: 25%; width: 25%;
text-align: center; text-align: center;
border-color: var(--background-color); border-color: var(--background-color);
@ -53,6 +52,6 @@
.welcome { .welcome {
text-align: center; text-align: center;
font-size: 20px; font-size: 18px;
color: white; color: white;
} }