mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
refactored component errors
This commit is contained in:
parent
7031084b09
commit
d4c2e7ee09
79 changed files with 573 additions and 462 deletions
|
@ -15,9 +15,9 @@ export const UPLOAD_ACTIONS = {
|
|||
};
|
||||
|
||||
export const EMPTY_FILE: IFile = {
|
||||
id: null,
|
||||
user_id: null,
|
||||
node_id: null,
|
||||
id: undefined,
|
||||
user_id: undefined,
|
||||
node_id: undefined,
|
||||
|
||||
name: '',
|
||||
orig_name: '',
|
||||
|
@ -25,21 +25,21 @@ export const EMPTY_FILE: IFile = {
|
|||
full_path: '',
|
||||
url: '',
|
||||
size: 0,
|
||||
type: null,
|
||||
type: undefined,
|
||||
mime: '',
|
||||
};
|
||||
|
||||
export const EMPTY_UPLOAD_STATUS: IUploadStatus = {
|
||||
is_uploading: false,
|
||||
preview: null,
|
||||
error: null,
|
||||
uuid: null,
|
||||
url: null,
|
||||
preview: '',
|
||||
error: '',
|
||||
uuid: 0,
|
||||
url: '',
|
||||
progress: 0,
|
||||
thumbnail_url: null,
|
||||
type: null,
|
||||
temp_id: null,
|
||||
name: null,
|
||||
thumbnail_url: '',
|
||||
type: '',
|
||||
temp_id: '',
|
||||
name: '',
|
||||
};
|
||||
|
||||
// for targeted cancellation
|
||||
|
|
|
@ -2,38 +2,41 @@ import { assocPath } from 'ramda';
|
|||
import { omit } from 'ramda';
|
||||
|
||||
import { UPLOAD_ACTIONS, EMPTY_UPLOAD_STATUS } from './constants';
|
||||
import {
|
||||
uploadAddStatus, uploadDropStatus, uploadSetStatus, uploadAddFile
|
||||
} from './actions';
|
||||
import { uploadAddStatus, uploadDropStatus, uploadSetStatus, uploadAddFile } from './actions';
|
||||
import { IUploadState } from './reducer';
|
||||
|
||||
const addStatus = (
|
||||
state: IUploadState,
|
||||
{ temp_id, status, }: ReturnType<typeof uploadAddStatus>
|
||||
): IUploadState => assocPath(
|
||||
['statuses'],
|
||||
{ ...state.statuses, [temp_id]: { ...EMPTY_UPLOAD_STATUS, ...status, }, },
|
||||
state
|
||||
);
|
||||
{ temp_id, status }: ReturnType<typeof uploadAddStatus>
|
||||
): IUploadState =>
|
||||
assocPath(
|
||||
['statuses'],
|
||||
{ ...state.statuses, [temp_id]: { ...EMPTY_UPLOAD_STATUS, ...status } },
|
||||
state
|
||||
);
|
||||
|
||||
const dropStatus = (
|
||||
state: IUploadState,
|
||||
{ temp_id, }: ReturnType<typeof uploadDropStatus>
|
||||
{ temp_id }: ReturnType<typeof uploadDropStatus>
|
||||
): IUploadState => assocPath(['statuses'], omit([temp_id], state.statuses), state);
|
||||
|
||||
const setStatus = (
|
||||
state: IUploadState,
|
||||
{ temp_id, status, }: ReturnType<typeof uploadSetStatus>
|
||||
): IUploadState => assocPath(
|
||||
['statuses'],
|
||||
{
|
||||
...state.statuses,
|
||||
[temp_id]: { ...(state.statuses[temp_id] || EMPTY_UPLOAD_STATUS), ...status, },
|
||||
},
|
||||
state
|
||||
);
|
||||
{ temp_id, status }: ReturnType<typeof uploadSetStatus>
|
||||
): IUploadState =>
|
||||
assocPath(
|
||||
['statuses'],
|
||||
{
|
||||
...state.statuses,
|
||||
[temp_id]: { ...(state.statuses[temp_id] || EMPTY_UPLOAD_STATUS), ...status },
|
||||
},
|
||||
state
|
||||
);
|
||||
|
||||
const addFile = (state: IUploadState, { file, }: ReturnType<typeof uploadAddFile>): IUploadState => assocPath(['files'], { ...state.files, [file.id]: file, }, state);
|
||||
const addFile = (state: IUploadState, { file }: ReturnType<typeof uploadAddFile>): IUploadState => {
|
||||
if (!file.id) return state;
|
||||
return assocPath(['files', file.id], file, state);
|
||||
};
|
||||
|
||||
export const UPLOAD_HANDLERS = {
|
||||
[UPLOAD_ACTIONS.ADD_STATUS]: addStatus,
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
import uuid from 'uuid4';
|
||||
import { IResultWithStatus, IFile, UUID } from '../types';
|
||||
import { HTTP_RESPONSES } from '~/utils/api';
|
||||
import { EMPTY_FILE } from './constants';
|
||||
|
||||
export const uploadMock = ({ temp_id, file }: { temp_id: UUID; file: File }): Promise<IResultWithStatus<IFile>> => (
|
||||
Promise.resolve({
|
||||
status: HTTP_RESPONSES.CREATED,
|
||||
data: {
|
||||
...EMPTY_FILE,
|
||||
id: uuid(),
|
||||
temp_id,
|
||||
},
|
||||
error: null,
|
||||
}));
|
|
@ -73,7 +73,7 @@ function* uploadFile({ file, temp_id, type, target, onSuccess, onFail }: IFileWi
|
|||
if (!temp_id) return;
|
||||
|
||||
try {
|
||||
if (!file.type || !FILE_MIMES[type] || !FILE_MIMES[type].includes(file.type)) {
|
||||
if (!file.type || !type || !FILE_MIMES[type] || !FILE_MIMES[type].includes(file.type)) {
|
||||
return {
|
||||
error: 'File_Not_Image',
|
||||
status: HTTP_RESPONSES.BAD_REQUEST,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue