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) {
|
||||
return new Promise((resolve) => {
|
||||
const promises = [
|
||||
const postText = (file) => {
|
||||
return new Promise((resolve) => {
|
||||
fetch(constants.apiUrl + 'postfeedback', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
|
@ -72,34 +72,44 @@ function postFeedback(content, file) {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
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) {
|
||||
console.log('FIEEEEEEEEEELE')
|
||||
const formData = new FormData() // eslint-disable-line
|
||||
formData.append('file', file)
|
||||
|
||||
promises.push(
|
||||
fetch(constants.apiUrl + 'postfeedbackfile', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: formData,
|
||||
}).then((res) => {
|
||||
fetch(constants.apiUrl + 'postfeedbackfile', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: formData,
|
||||
})
|
||||
.then((res) => {
|
||||
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)
|
||||
if (type === 'private') {
|
||||
postFeedback(content, file).then((res) => {
|
||||
console.log(res)
|
||||
postFeedback(content, file).then((/* { fileres, textres } */) => {
|
||||
alert('Privát visszajelzés elküldve!')
|
||||
})
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue