feat: closes #12123, allow setting hh:mm for pin expiry

use locale for pin expiry and use short form
This commit is contained in:
Barış Soner Uşaklı
2023-10-26 11:14:58 -04:00
parent 668a355afe
commit 1f8007476c
4 changed files with 20 additions and 15 deletions

View File

@@ -102,7 +102,7 @@
"nodebb-plugin-ntfy": "1.7.3", "nodebb-plugin-ntfy": "1.7.3",
"nodebb-plugin-spam-be-gone": "2.2.0", "nodebb-plugin-spam-be-gone": "2.2.0",
"nodebb-rewards-essentials": "1.0.0", "nodebb-rewards-essentials": "1.0.0",
"nodebb-theme-harmony": "1.1.90", "nodebb-theme-harmony": "1.1.91",
"nodebb-theme-lavender": "7.1.5", "nodebb-theme-lavender": "7.1.5",
"nodebb-theme-peace": "2.1.23", "nodebb-theme-peace": "2.1.23",
"nodebb-theme-persona": "13.2.42", "nodebb-theme-persona": "13.2.42",

View File

@@ -257,7 +257,6 @@ define('forum/topic/threadTools', [
title: '[[topic:thread-tools.pin]]', title: '[[topic:thread-tools.pin]]',
message: html, message: html,
onEscape: true, onEscape: true,
size: 'small',
buttons: { buttons: {
cancel: { cancel: {
label: '[[modules:bootbox.cancel]]', label: '[[modules:bootbox.cancel]]',
@@ -267,19 +266,19 @@ define('forum/topic/threadTools', [
label: '[[global:save]]', label: '[[global:save]]',
className: 'btn-primary', className: 'btn-primary',
callback: function () { callback: function () {
const expiryEl = modal.get(0).querySelector('#expiry'); const expiryDateEl = modal.get(0).querySelector('#expiry-date');
let expiry = expiryEl.value; const expiryTimeEl = modal.get(0).querySelector('#expiry-time');
let expiryDate = expiryDateEl.value;
let expiryTime = expiryTimeEl.value;
// No expiry set // No expiry set
if (expiry === '') { if (expiryDate === '' && expiryTime === '') {
return onSuccess(); return onSuccess();
} }
expiryDate = expiryDate || new Date().toDateString();
// Expiration date set expiryTime = expiryTime || new Date().toTimeString();
expiry = new Date(expiry); const date = new Date(`${expiryDate} ${expiryTime}`);
if (date.getTime() > Date.now()) {
if (expiry && expiry.getTime() > Date.now()) { body.expiry = date.getTime();
body.expiry = expiry.getTime();
onSuccess(); onSuccess();
} else { } else {
alerts.error('[[error:invalid-date]]'); alerts.error('[[error:invalid-date]]');

View File

@@ -343,8 +343,11 @@ module.exports = function (utils, Benchpress, relative_path) {
return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`;
} }
function isoTimeToLocaleString(isoTime) { function isoTimeToLocaleString(isoTime, locale = 'en-GB') {
return new Date(isoTime).toLocaleString().replace(/,/g, ','); return new Date(isoTime).toLocaleString([locale], {
dateStyle: 'short',
timeStyle: 'short',
}).replace(/,/g, ',');
} }
function shouldHideReplyContainer(post) { function shouldHideReplyContainer(post) {

View File

@@ -1,5 +1,8 @@
<div class="form-group"> <div class="form-group">
<label class="form-label" for="expiry">[[topic:pin-modal-expiry]]</label> <label class="form-label" for="expiry">[[topic:pin-modal-expiry]]</label>
<input id="expiry" type="date" class="form-control" /> <div class="d-flex gap-1">
<input id="expiry-date" type="date" class="form-control" />
<input id="expiry-time" type="time" class="form-control" />
</div>
<p class="form-text">[[topic:pin-modal-help]]</p> <p class="form-text">[[topic:pin-modal-help]]</p>
</div> </div>