Skip to content

Commit

Permalink
reverted the TimeagoFactory.js.erb to a pure .js file without Rails m…
Browse files Browse the repository at this point in the history
…arkup
  • Loading branch information
briri committed May 21, 2024
1 parent df768fb commit 4cb7e5f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/javascript/src/answers/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import debounce from '../utils/debounce';
import { updateSectionProgress, getQuestionDiv } from '../utils/sectionUpdate';
import datePicker from '../utils/datePicker';
import TimeagoFactory from '../utils/timeagoFactory.js.erb';
import TimeagoFactory from '../utils/timeagoFactory';

$(() => {
if ($('form.form-answer').length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/src/notes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject, isString } from '../utils/isType';
import TimeagoFactory from '../utils/timeagoFactory.js.erb';
import TimeagoFactory from '../utils/timeagoFactory';

$(() => {
const defaultViewSelector = (questionId) => `#note_new${questionId}`;
Expand Down
25 changes: 25 additions & 0 deletions app/javascript/src/utils/timeagoFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import getConstant from './constants';
import { format, register } from 'timeago.js';

const TimeagoFactory = (() => {
const defaultLocale = 'en'

const convertTime = (currentLocale, el) => {
return format($(el).attr('datetime'), `${currentLocale}`);
};

return {
render: (el) => {
if (el.length > 1) {
// If we were passed an array of JQuery elements then handle each one
$(el).each((idx, e) => {
$(e).text(convertTime(defaultLocale, e));
});
} else {
$(el).text(convertTime(defaultLocale, el));
}
},
};
})();

export default TimeagoFactory;
46 changes: 0 additions & 46 deletions app/javascript/src/utils/timeagoFactory.js.erb

This file was deleted.

0 comments on commit 4cb7e5f

Please sign in to comment.