mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
added error display
This commit is contained in:
parent
b4d55a49ba
commit
7d09eb26f5
7 changed files with 45 additions and 4 deletions
|
@ -22,6 +22,7 @@ import { moveArrItem } from '~/utils/fn';
|
||||||
import { SortEnd } from 'react-sortable-hoc';
|
import { SortEnd } from 'react-sortable-hoc';
|
||||||
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
|
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
|
||||||
import { getRandomPhrase } from '~/constants/phrases';
|
import { getRandomPhrase } from '~/constants/phrases';
|
||||||
|
import { ERROR_LITERAL } from '~/constants/errors';
|
||||||
|
|
||||||
const mapStateToProps = (state: IState) => ({
|
const mapStateToProps = (state: IState) => ({
|
||||||
node: selectNode(state),
|
node: selectNode(state),
|
||||||
|
@ -237,6 +238,15 @@ const CommentFormUnconnected: FC<IProps> = memo(
|
||||||
const hasAudioAttaches = audios.length > 0 || locked_audios.length > 0;
|
const hasAudioAttaches = audios.length > 0 || locked_audios.length > 0;
|
||||||
const hasAttaches = hasImageAttaches || hasAudioAttaches;
|
const hasAttaches = hasImageAttaches || hasAudioAttaches;
|
||||||
|
|
||||||
|
const clearError = useCallback(() => nodeSetCommentData(id, { error: '' }), [
|
||||||
|
id,
|
||||||
|
nodeSetCommentData,
|
||||||
|
]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (comment.error) clearError();
|
||||||
|
}, [comment.files, comment.text]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={onSubmit} className={styles.wrap}>
|
<form onSubmit={onSubmit} className={styles.wrap}>
|
||||||
<div className={styles.input}>
|
<div className={styles.input}>
|
||||||
|
@ -248,6 +258,12 @@ const CommentFormUnconnected: FC<IProps> = memo(
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
minRows={2}
|
minRows={2}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{comment.error && (
|
||||||
|
<div className={styles.error} onClick={clearError}>
|
||||||
|
{ERROR_LITERAL[comment.error] || comment.error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{hasAttaches && (
|
{hasAttaches && (
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
@include outer_shadow();
|
@include outer_shadow();
|
||||||
|
position: relative;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: ($gap / 2) ($gap / 2 + 1px);
|
padding: ($gap / 2) ($gap / 2 + 1px);
|
||||||
}
|
}
|
||||||
|
@ -36,3 +36,17 @@
|
||||||
.attaches {
|
.attaches {
|
||||||
@include outer_shadow();
|
@include outer_shadow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 50%;
|
||||||
|
background: $red;
|
||||||
|
z-index: 10;
|
||||||
|
font: $font_12_regular;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 0 $gap;
|
||||||
|
border-radius: 4px 4px 0 0;
|
||||||
|
transform: translate(-50%, 0);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ export const nodeSetRelated = (related: INodeState['related']) => ({
|
||||||
type: NODE_ACTIONS.SET_RELATED,
|
type: NODE_ACTIONS.SET_RELATED,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const nodeSetCommentData = (id: number, comment: IComment) => ({
|
export const nodeSetCommentData = (id: number, comment: Partial<IComment>) => ({
|
||||||
id,
|
id,
|
||||||
comment,
|
comment,
|
||||||
type: NODE_ACTIONS.SET_COMMENT_DATA,
|
type: NODE_ACTIONS.SET_COMMENT_DATA,
|
||||||
|
|
|
@ -110,6 +110,7 @@ export const EMPTY_COMMENT: IComment = {
|
||||||
temp_ids: [],
|
temp_ids: [],
|
||||||
is_private: false,
|
is_private: false,
|
||||||
user: null,
|
user: null,
|
||||||
|
error: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NODE_EDITORS = {
|
export const NODE_EDITORS = {
|
||||||
|
|
|
@ -49,7 +49,16 @@ const setRelated = (state: INodeState, { related }: ReturnType<typeof nodeSetRel
|
||||||
const setCommentData = (
|
const setCommentData = (
|
||||||
state: INodeState,
|
state: INodeState,
|
||||||
{ id, comment }: ReturnType<typeof nodeSetCommentData>
|
{ id, comment }: ReturnType<typeof nodeSetCommentData>
|
||||||
) => assocPath(['comment_data', id], comment, state);
|
) => ({
|
||||||
|
...state,
|
||||||
|
comment_data: {
|
||||||
|
...state.comment_data,
|
||||||
|
[id]: {
|
||||||
|
...(state.comment_data[id] || {}),
|
||||||
|
...comment,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const setTags = (state: INodeState, { tags }: ReturnType<typeof nodeSetTags>) =>
|
const setTags = (state: INodeState, { tags }: ReturnType<typeof nodeSetTags>) =>
|
||||||
assocPath(['current', 'tags'], tags, state);
|
assocPath(['current', 'tags'], tags, state);
|
||||||
|
|
|
@ -207,7 +207,7 @@ function* onPostComment({ id }: ReturnType<typeof nodePostComment>) {
|
||||||
yield put(nodeSetSendingComment(false));
|
yield put(nodeSetSendingComment(false));
|
||||||
|
|
||||||
if (error || !comment) {
|
if (error || !comment) {
|
||||||
return yield put(nodeSetSaveErrors({ error: error || ERRORS.EMPTY_RESPONSE }));
|
return yield put(nodeSetCommentData(id, { error }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const { current: current_node } = yield select(selectNode);
|
const { current: current_node } = yield select(selectNode);
|
||||||
|
|
|
@ -146,6 +146,7 @@ export interface IComment {
|
||||||
files: IFile[];
|
files: IFile[];
|
||||||
is_private: boolean;
|
is_private: boolean;
|
||||||
user: IUser;
|
user: IUser;
|
||||||
|
error?: string;
|
||||||
|
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
update_at?: string;
|
update_at?: string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue