From a08e89ca4d5554a809fb0a4c33d7cda9dad4ce6f Mon Sep 17 00:00:00 2001 From: Salihu Date: Tue, 11 Nov 2025 20:55:08 +0100 Subject: [PATCH] minor fixes --- app/actions/definitions/emojis.tsx | 4 +- app/components/EmojiCreateDialog.tsx | 40 ++++++++++++------- app/hooks/useSettingsConfig.ts | 4 +- app/models/Emoji.ts | 16 +++++++- app/scenes/Settings/CustomEmojis.tsx | 6 +-- .../Settings/components/EmojisTable.tsx | 7 +--- server/models/Emoji.ts | 21 ++++++++++ server/routes/api/emojis/emojis.ts | 7 +++- shared/i18n/locales/en_US/translation.json | 9 +++-- shared/validations.ts | 2 + 10 files changed, 81 insertions(+), 35 deletions(-) diff --git a/app/actions/definitions/emojis.tsx b/app/actions/definitions/emojis.tsx index 29a63c3444..0b18d6fa96 100644 --- a/app/actions/definitions/emojis.tsx +++ b/app/actions/definitions/emojis.tsx @@ -5,7 +5,7 @@ import stores from "~/stores"; import { EmojiCreateDialog } from "~/components/EmojiCreateDialog"; export const createEmoji = createAction({ - name: ({ t }) => `${t("Add emoji")}…`, + name: ({ t }) => `${t("New emoji")}…`, analyticsName: "Create emoji", icon: , keywords: "emoji custom upload image", @@ -14,7 +14,7 @@ export const createEmoji = createAction({ stores.policies.abilities(stores.auth.team?.id || "").createEmoji, perform: ({ t }) => { stores.dialogs.openModal({ - title: t("Add custom emoji"), + title: t("Upload emoji"), content: , }); }, diff --git a/app/components/EmojiCreateDialog.tsx b/app/components/EmojiCreateDialog.tsx index fc7a2ac152..62068f0805 100644 --- a/app/components/EmojiCreateDialog.tsx +++ b/app/components/EmojiCreateDialog.tsx @@ -13,6 +13,7 @@ import useStores from "~/hooks/useStores"; import { uploadFile } from "~/utils/files"; import { compressImage } from "~/utils/compressImage"; import Logger from "~/utils/Logger"; +import { EmojiValidation } from "@shared/validations"; type Props = { onSubmit: () => void; @@ -61,12 +62,12 @@ export function EmojiCreateDialog({ onSubmit }: Props) { preset: AttachmentPreset.DocumentAttachment, }); - await emojis.create({ + const emoji = await emojis.create({ name: name.trim(), url: attachment.url, }); - // to do: update with optimistic state + emojis.add(emoji); toast.success(t("Emoji created successfully")); onSubmit(); } catch (error) { @@ -78,14 +79,12 @@ export function EmojiCreateDialog({ onSubmit }: Props) { }; const handleNameChange = (event: React.ChangeEvent) => { - const value = event.target.value - .toLowerCase() - .replace(/[^a-z0-9_]/g, "") - .slice(0, 32); + const { value } = event.target; setName(value); }; - const isValid = name.trim().length > 0 && file; + const isValidName = EmojiValidation.allowedNameCharacters.test(name); + const isValid = name.trim().length > 0 && file && isValidName; return ( @@ -115,17 +121,19 @@ export function EmojiCreateDialog({ onSubmit }: Props) { {file ? ( <> - {file.name} - {t("Click or drag to replace")} + {file.name} + + {t("Click or drag to replace")} + ) : ( <> - + {isDragActive ? t("Drop the image here") : t("Click or drag an image here")} - + {t("PNG, JPG, GIF, or WebP up to 1MB")} @@ -133,10 +141,12 @@ export function EmojiCreateDialog({ onSubmit }: Props) { - {name && ( - - {t("This emoji will be available as")} :{name}: - + {name.trim() && isValidName && ( +
+ + {t("This emoji will be available as")} :{name}: + +
)}
); diff --git a/app/hooks/useSettingsConfig.ts b/app/hooks/useSettingsConfig.ts index c6d1213002..ca8ea82578 100644 --- a/app/hooks/useSettingsConfig.ts +++ b/app/hooks/useSettingsConfig.ts @@ -165,8 +165,8 @@ const useSettingsConfig = () => { icon: ShapesIcon, }, { - name: t("Custom Emojis"), - path: settingsPath("custom-emojis"), + name: t("Emojis"), + path: settingsPath("emojis"), component: CustomEmojis.Component, preload: CustomEmojis.preload, enabled: can.update, diff --git a/app/models/Emoji.ts b/app/models/Emoji.ts index 2fbabae3fa..e5f44200e7 100644 --- a/app/models/Emoji.ts +++ b/app/models/Emoji.ts @@ -1,4 +1,4 @@ -import { observable } from "mobx"; +import { computed, observable } from "mobx"; import User from "./User"; import Model from "./base/Model"; import Field from "./decorators/Field"; @@ -10,7 +10,7 @@ class Emoji extends Model { /** The name of the emoji */ @Field @observable - name: string; + private _name: string; /** The URL of the emoji image */ @Field @@ -26,6 +26,18 @@ class Emoji extends Model { @Field @observable createdById: string; + + /** + * emoji name + */ + @computed + get name() { + return this._name; + } + + set name(value: string) { + this._name = value; + } } export default Emoji; diff --git a/app/scenes/Settings/CustomEmojis.tsx b/app/scenes/Settings/CustomEmojis.tsx index c73ae41e63..3045281f42 100644 --- a/app/scenes/Settings/CustomEmojis.tsx +++ b/app/scenes/Settings/CustomEmojis.tsx @@ -37,7 +37,7 @@ function Emojis() { const reqParams = useMemo( () => ({ query: params.get("query") || undefined, - sort: params.get("sort") || "name", + sort: params.get("sort") || "createdAt", direction: (params.get("direction") || "asc").toUpperCase() as | "ASC" | "DESC", @@ -86,7 +86,7 @@ function Emojis() { useEffect(() => { if (error) { - toast.error(t("Could not load emojis")); + toast.error(t("Could not load emoji")); } }, [t, error]); @@ -112,7 +112,7 @@ function Emojis() { context={context} icon={} > - {t("Add emoji")}… + {t("New emoji")}… )} diff --git a/app/scenes/Settings/components/EmojisTable.tsx b/app/scenes/Settings/components/EmojisTable.tsx index 5b7d874ca7..7f77782331 100644 --- a/app/scenes/Settings/components/EmojisTable.tsx +++ b/app/scenes/Settings/components/EmojisTable.tsx @@ -33,7 +33,7 @@ const EmojisTable = observer(function EmojisTable({ compact([ { type: "data", - id: "emoji", + id: "name", header: t("Emoji"), accessor: (emoji) => emoji.url, component: (emoji) => ( @@ -67,10 +67,7 @@ const EmojisTable = observer(function EmojisTable({ id: "createdAt", header: t("Date added"), accessor: (emoji) => emoji.createdAt, - component: (emoji) => - emoji.createdAt ? ( -