Alheimsins / bigfive-web

Website for taking personality tests
MIT License
213 stars 86 forks source link

How to get a variable for the endtime of the timer function? #163

Closed jfrcom closed 5 years ago

jfrcom commented 5 years ago

Hello,

I would like to have a variable, that I can use after submitting the test like the data._id. Thanks for your great program!

maccyber commented 5 years ago

The latest (untested) commit adds timeElapsed and dateStamp to the database. Could do a git pull and try again?

jfrcom commented 5 years ago

I would still like to know how to achieve this. Could you help me?

zrrrzzt commented 5 years ago

@bluecomjona Could you try to explain your use case?

The update of #163 should make timeElapsed and dateStamp available the same way as data._Id (data.timeElapsed and data.dateStamp)

jfrcom commented 5 years ago

I can't find data.timeElapse. Where is it?

zrrrzzt commented 5 years ago

The data is submitted here in the code: https://github.com/Alheimsins/bigfive-web/blob/master/pages/test.js#L124

jfrcom commented 5 years ago

I think we misunderstand.. I want to have a variable which I can use after someone submitted the test like the data._id.

zrrrzzt commented 5 years ago

I think I understand what you want :-)

@maccyber added timeElapsed and dateStamp to the saved data. I pointed to one place in the code where these values are available as data.timeElapsed and data.dateStamp. The other option is here: https://github.com/Alheimsins/bigfive-web/blob/master/pages/showResult.js#L23

If you want to use timeElapsed and dateStamp you'll have to extract the values from the given points in the code. A quick example from here https://github.com/Alheimsins/bigfive-web/blob/master/pages/test.js#L124

If you change the code to something like this:

const { data } = await httpInstance.post('/api/save', result)
setItem('result', data._id)
Router.pushRoute('showResult', { id: data._id, timeElapsed: data.timeElapsed, dateStamp: data.dateStamp })

The url for the redirect will be http://someaddress.somedomain/result/someId?timeElapsed=someValue&dateStamp=someOtherValue

So the data is available but you'll have to change your code to make use of it.

jfrcom commented 5 years ago

Thank's a lot, but it doesn't work for me. alert (const { data } = await httpInstance.post('/api/save', result) setItem('result', data._id) Router.pushRoute('showResult', { id: data._id, timeElapsed: data.timeElapsed, dateStamp: data.dateStamp }) alert (data.timeElapsed)

I tried it like that, but it doesn't work for me.

jfrcom commented 5 years ago

It's working now, thank's!