Extend time on button click

Hi all, I need your help! I have a user submission form that members choose from a dropdown how long they want their post to stay live on my site, this works fine but what I’d like to do is give the member submitting a post the opportunity to allow anyone viewing it to extend it by a specific time. The member submitting the post chooses from another dropdown on the submission form how long they want their post to be extended and I have an ‘extend’ button on the dynamic page which displays the post.

I’ve created the dropdown on the user submission and it saves to my collection as a text field in the format of HH:MM. I’ve also added an ‘extend’ button on the dynamic page.

What I’m struggling with is how to call the time that the post should expire from my collection (this is a date & time field), the extend time, add them together and update the date & time field with the new extended end time.

I hope this makes sense what I’m trying to do! And someone in this great community can help.

I’m not sure why you’re saving this extension to the collection and not just update the expiration time based on the input.

it’s so that people viewing the post can extend it if they like it, if not the post just expires at the time the member has selected.

@ibateman37 It doesn’t answer my question.
You don’t need to keep the extension itself in a separate field.
If a user selected an extension, you can update the expiration time itself.

@jonatandor35 I thought I’d need to save the time extension as this is controlled by the member creating the post. But if someone clicks the extend button in the dynamic page of the post it would need to call the time the the member was happy for it to be extended by then add it to the original post time expiry

@ibateman37 Does each user have a different expiration time based on his/her choice?

@jonatandor35 Yes, when the member posts, they select a time from a dropdown from when they submit that post until a specific time in the future - from 30 mins to 7 days so all post have different expiry times which is saved in a date and time field in the collection called “dateTimer”. The dropdown for extending the posts has the same timescales so if a post was due to expire at say 12.30 and the member was happy for the post to be extended by, for example 30mins, when the extend button was clicked it would reset the expiry to 1.00, if it was clicked again expiry would be 1.30, etc.

@ibateman37 So save it as a new expiration time for this user -

let originalTime  = itemData.expiration//put here the original time extracted from the database
originalTime = new Date(originalTime).getTime();
let newExpiration = $w("#doprdown").value.split(":");
newExpiration = Number(newExpiration[0]) * 3600000 + Number(newExpiration[1]) * 60000;
itemData.newExpiration = new Date(originalTime + newExpiration );
wixData.update("newExpiration", itemData)
.then((res) => {
})

@jonatandor35 Thanks JD but that won’t work for how I need it to. If I walk you through a scenario maybe I’ll be a bit clearer on how I need this to work:

Lets say it 1.00am. A member fills a submission form for a post, they select how long they want the post to be on the site for - they choose 30 mins from the dropdown so their post will delete at 1.30am. They also decide that they are happy for their post to be extended by anyone that views it and chooses 1 hour extensions from the second dropdown. They submit the post and it appears on the site. Someone sees the post and clicks the repeater image which opens the dynamic page and displays the full post. As the member has chose that they are happy for the post to be extended, an ‘extend post’ button is visible on the dynamic page. The person viewing the post likes it and clicks the extend post button, this then updates the expiry time by a further hour so the post will now be visible for 1 hour 30 mins instead of the original 30 mins post time and expire at 2.30am, someone else views the post and likes it as well so clicks the extend post so it adds a further hour to the expiry time, the post would then expire at 3.30am.

This is why I think I need to somehow save the hours and minutes from the extensions dropdown in my collection and then have an onClick event on the dynamic page that updates the expiry time with the new expiry time - basically adding the extension hours and/or minutes to the original expiry time.

@ibateman37 Yet, I don’t see a reason to store as you suggested.
If I got you correctly, each user can extend the “shelf-life” of a post for all the users.
Right? So how exactly to do it depends on what you’d like to happen in the edge cases. For example:

  1. Time is 00:00, two different users click “extend by 30 minutes” at the very same time - what’s the expected new timeout?

  2. Time is 00:00, one user clicks “extend by 30 minutes”, the other clicks “extend by 1 hour”

  3. Time is 00:00 one user clicks “extend by 1 hour”; time is 00:02, a second user who hasn’t noticed the extension clicks “extend by 30 minutes”

Let me know what you’d like to happen in this cases.