mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Feedback now includes file name if one is uploaded
This commit is contained in:
parent
2e7317962e
commit
6a2c22f24a
1 changed files with 32 additions and 23 deletions
|
@ -61,8 +61,8 @@ function addPost(title, content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function postFeedback(content, file) {
|
function postFeedback(content, file) {
|
||||||
return new Promise((resolve) => {
|
const postText = (file) => {
|
||||||
const promises = [
|
return new Promise((resolve) => {
|
||||||
fetch(constants.apiUrl + 'postfeedback', {
|
fetch(constants.apiUrl + 'postfeedback', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
@ -72,34 +72,44 @@ function postFeedback(content, file) {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
content: content,
|
content: content,
|
||||||
|
file: file ? file.name : null,
|
||||||
}),
|
}),
|
||||||
}).then((res) => {
|
})
|
||||||
return res.json()
|
.then((res) => {
|
||||||
}),
|
return res.json()
|
||||||
]
|
})
|
||||||
|
.then((res) => {
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
if (file) {
|
if (file) {
|
||||||
console.log('FIEEEEEEEEEELE')
|
|
||||||
const formData = new FormData() // eslint-disable-line
|
const formData = new FormData() // eslint-disable-line
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
|
|
||||||
promises.push(
|
fetch(constants.apiUrl + 'postfeedbackfile', {
|
||||||
fetch(constants.apiUrl + 'postfeedbackfile', {
|
method: 'POST',
|
||||||
method: 'POST',
|
credentials: 'include',
|
||||||
credentials: 'include',
|
headers: {
|
||||||
headers: {
|
Accept: 'application/json',
|
||||||
Accept: 'application/json',
|
},
|
||||||
},
|
body: formData,
|
||||||
body: formData,
|
})
|
||||||
}).then((res) => {
|
.then((res) => {
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
)
|
.then((fileres) => {
|
||||||
|
postText(file).then((textres) => {
|
||||||
|
resolve({ fileres, textres })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
postText().then((res) => {
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then((res) => {
|
|
||||||
resolve(res)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,8 +262,7 @@ export default function Index({ globalData }) {
|
||||||
}
|
}
|
||||||
console.log(type, title, content, file)
|
console.log(type, title, content, file)
|
||||||
if (type === 'private') {
|
if (type === 'private') {
|
||||||
postFeedback(content, file).then((res) => {
|
postFeedback(content, file).then((/* { fileres, textres } */) => {
|
||||||
console.log(res)
|
|
||||||
alert('Privát visszajelzés elküldve!')
|
alert('Privát visszajelzés elküldve!')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue