summaryrefslogtreecommitdiffstats
path: root/ui/src/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r--ui/src/utils.ts56
1 files changed, 38 insertions, 18 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index 48d2095d..2bede777 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -22,6 +22,9 @@ import 'moment/locale/tr';
import 'moment/locale/hu';
import 'moment/locale/uk';
import 'moment/locale/sq';
+import 'moment/locale/km';
+import 'moment/locale/ga';
+import 'moment/locale/sr';
import {
UserOperation,
@@ -48,11 +51,10 @@ import Tribute from 'tributejs/src/Tribute.js';
import markdown_it from 'markdown-it';
import markdownitEmoji from 'markdown-it-emoji/light';
import markdown_it_container from 'markdown-it-container';
-import twemoji from 'twemoji';
import emojiShortName from 'emoji-short-name';
import Toastify from 'toastify-js';
import tippy from 'tippy.js';
-import EmojiButton from '@joeattardi/emoji-button';
+import moment from 'moment';
export const repoUrl = 'https://github.com/LemmyNet/lemmy';
export const helpGuideUrl = '/docs/about_guide.html';
@@ -72,9 +74,11 @@ export const languages = [
{ code: 'eo', name: 'Esperanto' },
{ code: 'es', name: 'Español' },
{ code: 'de', name: 'Deutsch' },
+ { code: 'ga', name: 'Gaeilge' },
{ code: 'gl', name: 'Galego' },
{ code: 'hu', name: 'Magyar Nyelv' },
{ code: 'ka', name: 'ქართული ენა' },
+ { code: 'km', name: 'ភាសាខ្មែរ' },
{ code: 'hi', name: 'मानक हिन्दी' },
{ code: 'fa', name: 'فارسی' },
{ code: 'ja', name: '日本語' },
@@ -85,8 +89,9 @@ export const languages = [
{ code: 'fr', name: 'Français' },
{ code: 'sv', name: 'Svenska' },
{ code: 'sq', name: 'Shqip' },
+ { code: 'sr_Latn', name: 'srpski' },
{ code: 'tr', name: 'Türkçe' },
- { code: 'uk', name: 'українська мова' },
+ { code: 'uk', name: 'Українська Mова' },
{ code: 'ru', name: 'Русский' },
{ code: 'nl', name: 'Nederlands' },
{ code: 'it', name: 'Italiano' },
@@ -108,14 +113,6 @@ export const themes = [
'litely',
];
-export const emojiPicker = new EmojiButton({
- // Use the emojiShortName from native
- style: 'twemoji',
- theme: 'dark',
- position: 'auto-start',
- // TODO i18n
-});
-
const DEFAULT_ALPHABET =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -172,10 +169,6 @@ export const md = new markdown_it({
defs: objectFlip(emojiShortName),
});
-md.renderer.rules.emoji = function (token, idx) {
- return twemoji.parse(token[idx].content);
-};
-
export function hotRankComment(comment: Comment): number {
return hotRank(comment.score, comment.published);
}
@@ -418,6 +411,12 @@ export function getMomentLanguage(): string {
lang = 'uk';
} else if (lang.startsWith('sq')) {
lang = 'sq';
+ } else if (lang.startsWith('km')) {
+ lang = 'km';
+ } else if (lang.startsWith('ga')) {
+ lang = 'ga';
+ } else if (lang.startsWith('sr')) {
+ lang = 'sr';
} else {
lang = 'en';
}
@@ -489,6 +488,19 @@ export function showAvatars(): boolean {
);
}
+export function isCakeDay(published: string): boolean {
+ // moment(undefined) or moment.utc(undefined) returns the current date/time
+ // moment(null) or moment.utc(null) returns null
+ const userCreationDate = moment.utc(published || null).local();
+ const currentDate = moment(new Date());
+
+ return (
+ userCreationDate.date() === currentDate.date() &&
+ userCreationDate.month() === currentDate.month() &&
+ userCreationDate.year() !== currentDate.year()
+ );
+}
+
// Converts to image thumbnail
export function pictrsImage(hash: string, thumbnail: boolean = false): string {
let root = `/pictrs/image`;
@@ -578,8 +590,7 @@ export function setupTribute(): Tribute {
trigger: ':',
menuItemTemplate: (item: any) => {
let shortName = `:${item.original.key}:`;
- let twemojiIcon = twemoji.parse(item.original.val);
- return `${twemojiIcon} ${shortName}`;
+ return `${item.original.val} ${shortName}`;
},
selectTemplate: (item: any) => {
return `:${item.original.key}:`;
@@ -923,7 +934,7 @@ export function postSort(
+a.removed - +b.removed ||
+a.deleted - +b.deleted ||
(communityType && +b.stickied - +a.stickied) ||
- hotRankPost(b) - hotRankPost(a)
+ b.hot_rank - a.hot_rank
);
}
}
@@ -976,3 +987,12 @@ function canUseWebP() {
// // very old browser like IE 8, canvas not supported
// return false;
}
+
+export function validTitle(title?: string): boolean {
+ // Initial title is null, minimum length is taken care of by textarea's minLength={3}
+ if (title === null || title.length < 3) return true;
+
+ const regex = new RegExp(/.*\S.*/, 'g');
+
+ return regex.test(title);
+}