mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
fixed message delete appearance
This commit is contained in:
parent
c2ebde069d
commit
3f3c1516c8
7 changed files with 69 additions and 8 deletions
|
@ -1,25 +1,61 @@
|
||||||
import React, { FC, useCallback } from 'react';
|
import React, { FC, useCallback } from 'react';
|
||||||
import { IMessage } from '~/redux/types';
|
import { IMessage } from '~/redux/types';
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
import { formatText, getURL, getPrettyDate } from '~/utils/dom';
|
import { formatText, getPrettyDate, getURL } from '~/utils/dom';
|
||||||
import { PRESETS } from '~/constants/urls';
|
import { PRESETS } from '~/constants/urls';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { CommentMenu } from '~/components/node/CommentMenu';
|
import { CommentMenu } from '~/components/node/CommentMenu';
|
||||||
import { MessageForm } from '~/components/profile/MessageForm';
|
import { MessageForm } from '~/components/profile/MessageForm';
|
||||||
|
import { Filler } from '~/components/containers/Filler';
|
||||||
|
import { Button } from '~/components/input/Button';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
message: IMessage;
|
message: IMessage;
|
||||||
incoming: boolean;
|
incoming: boolean;
|
||||||
onEdit: (id: number) => void;
|
onEdit: (id: number) => void;
|
||||||
onDelete: (id: number) => void;
|
onDelete: (id: number) => void;
|
||||||
|
onRestore: (id: number) => void;
|
||||||
onCancelEdit: () => void;
|
onCancelEdit: () => void;
|
||||||
isEditing: boolean;
|
isEditing: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Message: FC<IProps> = ({ message, incoming, onEdit, onDelete, isEditing, onCancelEdit }) => {
|
const Message: FC<IProps> = ({
|
||||||
const onEditClicked = useCallback(() => onEdit(message.id), [message.id]);
|
message,
|
||||||
const onDeleteClicked = useCallback(() => onDelete(message.id), [message.id]);
|
incoming,
|
||||||
|
onEdit,
|
||||||
|
onDelete,
|
||||||
|
isEditing,
|
||||||
|
onCancelEdit,
|
||||||
|
onRestore,
|
||||||
|
}) => {
|
||||||
|
const onEditClicked = useCallback(() => onEdit(message.id), [onEdit, message.id]);
|
||||||
|
const onDeleteClicked = useCallback(() => onDelete(message.id), [onDelete, message.id]);
|
||||||
|
const onRestoreClicked = useCallback(() => onRestore(message.id), [onRestore, message.id]);
|
||||||
|
|
||||||
|
if (message.deleted_at) {
|
||||||
|
return (
|
||||||
|
<div className={classNames(styles.message)}>
|
||||||
|
<Group className={styles.deleted} horizontal>
|
||||||
|
<Filler>Сообщение удалено</Filler>
|
||||||
|
<Button
|
||||||
|
size="mini"
|
||||||
|
onClick={onRestoreClicked}
|
||||||
|
color="link"
|
||||||
|
iconLeft="restore"
|
||||||
|
className={styles.restore}
|
||||||
|
>
|
||||||
|
Восстановить
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={styles.avatar}
|
||||||
|
style={{ backgroundImage: `url("${getURL(message.from.photo, PRESETS.avatar)}")` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(styles.message, { [styles.incoming]: incoming })}>
|
<div className={classNames(styles.message, { [styles.incoming]: incoming })}>
|
||||||
|
|
|
@ -87,3 +87,15 @@ $outgoing_color: $comment_bg;
|
||||||
padding: 2px $gap;
|
padding: 2px $gap;
|
||||||
border-radius: $radius;
|
border-radius: $radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.restore {
|
||||||
|
color: $red;
|
||||||
|
fill: $red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.deleted {
|
||||||
|
background: mix($red, $content_bg, 50%);
|
||||||
|
border-radius: $radius $radius $radius 0;
|
||||||
|
padding: $gap / 2;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ export const ERRORS = {
|
||||||
CANT_SAVE_USER: 'CantSaveUser',
|
CANT_SAVE_USER: 'CantSaveUser',
|
||||||
CANT_DELETE_COMMENT: 'CantDeleteComment',
|
CANT_DELETE_COMMENT: 'CantDeleteComment',
|
||||||
CANT_RESTORE_COMMENT: 'CantRestoreComment',
|
CANT_RESTORE_COMMENT: 'CantRestoreComment',
|
||||||
|
MESSAGE_NOT_FOUND: 'MessageNotFound',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ERROR_LITERAL = {
|
export const ERROR_LITERAL = {
|
||||||
|
@ -85,4 +86,5 @@ export const ERROR_LITERAL = {
|
||||||
[ERRORS.CANT_SAVE_USER]: 'Не удалось сохранить пользователя',
|
[ERRORS.CANT_SAVE_USER]: 'Не удалось сохранить пользователя',
|
||||||
[ERRORS.CANT_DELETE_COMMENT]: 'Не удалось удалить комментарий',
|
[ERRORS.CANT_DELETE_COMMENT]: 'Не удалось удалить комментарий',
|
||||||
[ERRORS.CANT_RESTORE_COMMENT]: 'Не удалось восстановить комментарий',
|
[ERRORS.CANT_RESTORE_COMMENT]: 'Не удалось восстановить комментарий',
|
||||||
|
[ERRORS.MESSAGE_NOT_FOUND]: 'Сообщение не найдено',
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,10 @@ const ProfileMessagesUnconnected: FC<IProps> = ({
|
||||||
|
|
||||||
const onEditMessage = useCallback((id: number) => setEditingMessageId(id), [setEditingMessageId]);
|
const onEditMessage = useCallback((id: number) => setEditingMessageId(id), [setEditingMessageId]);
|
||||||
const onCancelEdit = useCallback(() => setEditingMessageId(0), [setEditingMessageId]);
|
const onCancelEdit = useCallback(() => setEditingMessageId(0), [setEditingMessageId]);
|
||||||
const onDeleteMessage = useCallback((id: number) => messagesDeleteMessage(id), [
|
const onDeleteMessage = useCallback((id: number) => messagesDeleteMessage(id, true), [
|
||||||
|
messagesDeleteMessage,
|
||||||
|
]);
|
||||||
|
const onRestoreMessage = useCallback((id: number) => messagesDeleteMessage(id, false), [
|
||||||
messagesDeleteMessage,
|
messagesDeleteMessage,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -70,6 +73,7 @@ const ProfileMessagesUnconnected: FC<IProps> = ({
|
||||||
onDelete={onDeleteMessage}
|
onDelete={onDeleteMessage}
|
||||||
isEditing={editingMessageId === message.id}
|
isEditing={editingMessageId === message.id}
|
||||||
onCancelEdit={onCancelEdit}
|
onCancelEdit={onCancelEdit}
|
||||||
|
onRestore={onRestoreMessage}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,10 @@ export const messagesSendMessage = (message: Partial<IMessage>, onSuccess) => ({
|
||||||
onSuccess,
|
onSuccess,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const messagesDeleteMessage = (id: IMessage['id']) => ({
|
export const messagesDeleteMessage = (id: IMessage['id'], is_locked: boolean) => ({
|
||||||
type: MESSAGES_ACTIONS.DELETE_MESSAGE,
|
type: MESSAGES_ACTIONS.DELETE_MESSAGE,
|
||||||
id,
|
id,
|
||||||
|
is_locked,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const messagesSet = (messages: Partial<IMessagesState>) => ({
|
export const messagesSet = (messages: Partial<IMessagesState>) => ({
|
||||||
|
|
|
@ -25,12 +25,17 @@ export const apiMessagesDeleteMessage = ({
|
||||||
access,
|
access,
|
||||||
username,
|
username,
|
||||||
id,
|
id,
|
||||||
|
is_locked,
|
||||||
}: {
|
}: {
|
||||||
access: string;
|
access: string;
|
||||||
username: string;
|
username: string;
|
||||||
id: number;
|
id: number;
|
||||||
|
is_locked: boolean;
|
||||||
}): Promise<IResultWithStatus<{ message: IMessage }>> =>
|
}): Promise<IResultWithStatus<{ message: IMessage }>> =>
|
||||||
api
|
api
|
||||||
.delete(API.USER.MESSAGE_DELETE(username, id), configWithToken(access))
|
.delete(
|
||||||
|
API.USER.MESSAGE_DELETE(username, id),
|
||||||
|
configWithToken(access, { params: { is_locked } })
|
||||||
|
)
|
||||||
.then(resultMiddleware)
|
.then(resultMiddleware)
|
||||||
.catch(errorMiddleware);
|
.catch(errorMiddleware);
|
||||||
|
|
|
@ -120,7 +120,7 @@ function* sendMessage({ message, onSuccess }: ReturnType<typeof messagesSendMess
|
||||||
onSuccess();
|
onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
function* deleteMessage({ id }: ReturnType<typeof messagesDeleteMessage>) {
|
function* deleteMessage({ id, is_locked }: ReturnType<typeof messagesDeleteMessage>) {
|
||||||
const username: ReturnType<typeof selectAuthProfileUsername> = yield select(
|
const username: ReturnType<typeof selectAuthProfileUsername> = yield select(
|
||||||
selectAuthProfileUsername
|
selectAuthProfileUsername
|
||||||
);
|
);
|
||||||
|
@ -135,6 +135,7 @@ function* deleteMessage({ id }: ReturnType<typeof messagesDeleteMessage>) {
|
||||||
{
|
{
|
||||||
username,
|
username,
|
||||||
id,
|
id,
|
||||||
|
is_locked,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue