refactor: get rid of dayjs, flatpickr use native datetime-local

This commit is contained in:
Barış Soner Uşaklı 2024-05-17 12:39:39 -04:00
parent 4e556c338b
commit 696c6443f9
9 changed files with 2254 additions and 1786 deletions

3973
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -29,8 +29,8 @@
"compatibility": "^3.2.0"
},
"devDependencies": {
"eslint": "^7.31.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.4"
"eslint": "8.57.0",
"eslint-config-nodebb": "0.2.1",
"eslint-plugin-import": "2.29.1"
}
}

View file

@ -35,10 +35,7 @@
],
"modules": {
"../admin/plugins/poll.js": "public/js/admin.js",
"poll/serializer.js": "public/js/poll/serializer.js",
"dayjs.js": "vendor/dayjs.min.js",
"flatpickr.js": "vendor/flatpickr.min.js",
"flatpickr.i10n.js": "vendor/flatpickr.l10n.js"
"poll/serializer.js": "public/js/poll/serializer.js"
},
"css": [
"vendor/flatpickr.min.css"

View file

@ -124,7 +124,7 @@
return Poll.alertError('Editing not implemented');
}

require(['flatpickr', 'flatpickr.i10n', 'bootbox', 'dayjs', 'translator'], function (flatpickr, flatpickrI10N, bootbox, dayjs, Translator) {
require(['bootbox'], function (bootbox) {
app.parseAndTranslate('poll/creator', { poll: poll, config: config, isRedactor: !!$.Redactor }, function (html) {
// Initialise modal
var modal = bootbox.dialog({
@ -156,12 +156,9 @@
return error('[[poll:error.no_options]]');
}

if (obj.settings.end && !dayjs(new Date(obj.settings.end)).isValid()) {
return error('[[poll:error.valid_date]]');
} else if (obj.settings.end) {
obj.settings.end = dayjs(new Date(obj.settings.end)).valueOf();
if (obj.settings.end) {
obj.settings.end = new Date(obj.settings.end).getTime();
}

callback(obj);
return true;
},
@ -191,23 +188,9 @@
}
});

var currentLocale = Translator.getLanguage();
var flatpickrInstance = flatpickr('.flatpickr', {
enableTime: true,
altFormat: 'F j, Y h:i K',
time_24hr: false,
wrap: true,
locale: getFlatpickrLocale(currentLocale, flatpickrI10N.default),
onOpen: function () {
modal.removeAttr('tabindex');
},
onClose: function () {
modal.attr('tabindex', -1);
},
});

if (poll.settings && poll.settings.end) {
flatpickrInstance.setDate(poll.settings.end);

// flatpickrInstance.setDate(poll.settings.end);
}
});
});
@ -241,13 +224,6 @@
return result;
}

function getFlatpickrLocale(nodebbLocale, flatpickrLocales = {}) {
if (Object.keys(flatpickrLocales).includes(nodebbLocale.toLowerCase())) {
return flatpickrLocales[nodebbLocale];
}
return flatpickrLocales.default;
}

Poll.creator = Creator;

init();

View file

@ -35,9 +35,8 @@

<div class="mb-3">
<label class="form-label" for="pollInputEnd">[[poll:auto_end_title]]</label>
<div class="input-group date flatpickr">
<input id="pollInputEnd" placeholder="[[poll:auto_end_placeholder]]" name="settings.end" class="form-control" value="{poll.settings.end}" data-input>
<a class="input-group-text" data-toggle><i class="fa fa-calendar"></i></a>
<div class="input-group date">
<input id="pollInputEnd" placeholder="[[poll:auto_end_placeholder]]" name="settings.end" class="form-control" value="{poll.settings.end}" type="datetime-local">
</div>
<p class="form-text">[[poll:auto_end_help]]</p>
</div>

1
vendor/dayjs.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long