minor fixes

This commit is contained in:
Salihu committed 2025-11-11 20:55:08 +01:00
1 parent af8174eec8
commit a08e89ca4d
10 files changed
+81 -35

No files matched your search

+2 -2
View File
@@ -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: <PlusIcon />,
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: <EmojiCreateDialog onSubmit={stores.dialogs.closeAllModals} />,
});
},
+25 -15
View File
@@ -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<HTMLInputElement>) => {
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 (
<ConfirmationDialog
@@ -107,6 +106,13 @@ export function EmojiCreateDialog({ onSubmit }: Props) {
placeholder="my_custom_emoji"
autoFocus
required
error={
!isValidName
? t(
"name can only should lowercase letters, numbers, and underscores."
)
: undefined
}
/>
<DropZone {...getRootProps()}>
@@ -115,17 +121,19 @@ export function EmojiCreateDialog({ onSubmit }: Props) {
{file ? (
<>
<PreviewImage src={URL.createObjectURL(file)} alt="Preview" />
<Text>{file.name}</Text>
<Text type="secondary">{t("Click or drag to replace")}</Text>
<Text size="medium">{file.name}</Text>
<Text size="medium" type="secondary">
{t("Click or drag to replace")}
</Text>
</>
) : (
<>
<Text>
<Text size="medium">
{isDragActive
? t("Drop the image here")
: t("Click or drag an image here")}
</Text>
<Text type="secondary">
<Text size="medium" type="secondary">
{t("PNG, JPG, GIF, or WebP up to 1MB")}
</Text>
</>
@@ -133,10 +141,12 @@ export function EmojiCreateDialog({ onSubmit }: Props) {
</Flex>
</DropZone>
{name && (
<Text type="secondary">
{t("This emoji will be available as")} <code>:{name}:</code>
</Text>
{name.trim() && isValidName && (
<div style={{ marginTop: "8px" }}>
<Text type="secondary">
{t("This emoji will be available as")} <code>:{name}:</code>
</Text>
</div>
)}
</ConfirmationDialog>
);
+2 -2
View File
@@ -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,
+14 -2
View File
@@ -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;
+3 -3
View File
@@ -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={<PlusIcon />}
>
{t("Add emoji")}…
{t("New emoji")}…
</Button>
</Action>
)}
@@ -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 ? (
<Time dateTime={emoji.createdAt} addSuffix />
) : null,
component: (emoji) => <Time dateTime={emoji.createdAt} addSuffix />,
width: "1fr",
},
// to do: emoji menu
+21
View File
@@ -5,6 +5,7 @@ import {
} from "sequelize";
import {
BeforeCreate,
BeforeDestroy,
BelongsTo,
Column,
DataType,
@@ -19,6 +20,9 @@ import IdModel from "./base/IdModel";
import Fix from "./decorators/Fix";
import IsUrlOrRelativePath from "./validators/IsUrlOrRelativePath";
import Length from "./validators/Length";
import { Matches } from "class-validator";
import FileStorage from "@server/storage/files";
import Attachment from "./Attachment";
@Table({ tableName: "emojis", modelName: "emoji" })
@Fix
@@ -30,6 +34,10 @@ class Emoji extends IdModel<
max: EmojiValidation.maxNameLength,
msg: `emoji name must be less than ${EmojiValidation.maxNameLength} characters`,
})
@Matches(EmojiValidation.allowedNameCharacters, {
message:
"emoji name can only contain lowercase letters, numbers, and underscores",
})
@Column(DataType.STRING)
name: string;
@@ -70,6 +78,19 @@ class Emoji extends IdModel<
throw ValidationError(`Emoji with name "${model.name}" already exists.`);
}
}
@BeforeDestroy
static async deleteAttachmentFromS3(model: Emoji) {
const attachment = await Attachment.findOne({
where: {
key: model.url,
},
});
if (attachment) {
await FileStorage.deleteFile(attachment.key);
}
}
}
export default Emoji;
+5 -2
View File
@@ -122,10 +122,11 @@ router.post(
createdById: user.id,
createdBy: user,
});
emoji.createdBy = user;
ctx.body = {
data: presentEmoji(emoji!),
policies: presentPolicies(user, [emoji!]),
data: presentEmoji(emoji),
policies: presentPolicies(user, [emoji]),
};
}
);
@@ -138,10 +139,12 @@ router.post(
async (ctx: APIContext<T.EmojisDeleteReq>) => {
const { id } = ctx.input.body;
const { user } = ctx.state.auth;
const { transaction } = ctx.state;
const emoji = await Emoji.findByPk(id, {
transaction: ctx.state.transaction,
rejectOnEmpty: true,
lock: transaction.LOCK.UPDATE,
});
authorize(user, "delete", emoji);
+5 -4
View File
@@ -113,8 +113,8 @@
"You have left the shared document": "You have left the shared document",
"Could not leave document": "Could not leave document",
"Apply template": "Apply template",
"Add emoji": "Add emoji",
"Add custom emoji": "Add custom emoji",
"New emoji": "New emoji",
"Upload emoji": "Upload emoji",
"Disconnect analytics": "Disconnect analytics",
"Home": "Home",
"Drafts": "Drafts",
@@ -263,8 +263,10 @@
"Emoji created successfully": "Emoji created successfully",
"Failed to create emoji": "Failed to create emoji",
"Uploading": "Uploading",
"Add emoji": "Add emoji",
"Upload an image to create a custom emoji. The name should be unique and contain only lowercase letters, numbers, and underscores.": "Upload an image to create a custom emoji. The name should be unique and contain only lowercase letters, numbers, and underscores.",
"Emoji name": "Emoji name",
"name can only should lowercase letters, numbers, and underscores.": "name can only should lowercase letters, numbers, and underscores.",
"Click or drag to replace": "Click or drag to replace",
"Drop the image here": "Drop the image here",
"Click or drag an image here": "Click or drag an image here",
@@ -599,7 +601,6 @@
"Security": "Security",
"Features": "Features",
"Members": "Members",
"Custom Emojis": "Custom Emojis",
"API Keys": "API Keys",
"Applications": "Applications",
"Shared Links": "Shared Links",
@@ -1071,7 +1072,7 @@
"Editors": "Editors",
"All status": "All status",
"Active": "Active",
"Could not load emojis": "Could not load emojis",
"Could not load emoji": "Could not load emoji",
"Custom emojis can be used throughout your workspace in documents, comments, and reactions.": "Custom emojis can be used throughout your workspace in documents, comments, and reactions.",
"Left": "Left",
"Right": "Right",
+2
View File
@@ -133,4 +133,6 @@ export const WebhookSubscriptionValidation = {
export const EmojiValidation = {
/** The maximum length of the emoji name */
maxNameLength: 25,
/* the allow characters in the name */
allowedNameCharacters: /^[a-z0-9_]*$/,
};