mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed eslint again
This commit is contained in:
parent
f922536ffa
commit
db0a94b581
5 changed files with 42 additions and 27 deletions
|
@ -1,6 +1,5 @@
|
|||
module.exports = {
|
||||
extends: ['airbnb', 'airbnb-base', 'prettier/@typescript-eslint', 'plugin:@typescript-eslint/recommended'],
|
||||
// "parser": "babel-eslint",
|
||||
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint', 'airbnb', 'airbnb-base'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
|
@ -11,15 +10,12 @@ module.exports = {
|
|||
plugins: ['@typescript-eslint', 'react', 'jsx-a11y', 'import', 'react-hooks'],
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
// node: {
|
||||
// extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
// },
|
||||
typescript: {},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-function-return-type': 0,
|
||||
'@typescript-eslint/indent': ['warn', 2],
|
||||
// '@typescript-eslint/indent': ['warn', 2],
|
||||
'comma-dangle': 0,
|
||||
'no-restricted-syntax': 1,
|
||||
'react/prop-types': 0,
|
||||
|
@ -63,5 +59,6 @@ module.exports = {
|
|||
window: false,
|
||||
HTMLInputElement: false,
|
||||
HTMLDivElement: false,
|
||||
FormData: false,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -68,7 +68,8 @@ export interface IFile {
|
|||
export interface IFileWithUUID {
|
||||
temp_id?: UUID;
|
||||
file: File;
|
||||
subject: string;
|
||||
target: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface IBlock {
|
||||
|
@ -107,3 +108,5 @@ export interface INode {
|
|||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export type IUploadProgressHandler = (current: number, total: number) => void;
|
||||
|
|
|
@ -4,27 +4,27 @@ import { IUploadStatus } from './reducer';
|
|||
|
||||
export const uploadUploadFiles = (files: IFileWithUUID[]) => ({
|
||||
files,
|
||||
type: UPLOAD_ACTIONS.UPLOAD_FILES
|
||||
type: UPLOAD_ACTIONS.UPLOAD_FILES,
|
||||
});
|
||||
|
||||
export const uploadAddStatus = (temp_id: UUID, status?: Partial<IUploadStatus>) => ({
|
||||
temp_id,
|
||||
status,
|
||||
type: UPLOAD_ACTIONS.ADD_STATUS
|
||||
type: UPLOAD_ACTIONS.ADD_STATUS,
|
||||
});
|
||||
|
||||
export const uploadAddFile = (file: IFile) => ({
|
||||
file,
|
||||
type: UPLOAD_ACTIONS.ADD_FILE
|
||||
type: UPLOAD_ACTIONS.ADD_FILE,
|
||||
});
|
||||
|
||||
export const uploadSetStatus = (temp_id: UUID, status?: Partial<IUploadStatus>) => ({
|
||||
temp_id,
|
||||
status,
|
||||
type: UPLOAD_ACTIONS.SET_STATUS
|
||||
type: UPLOAD_ACTIONS.SET_STATUS,
|
||||
});
|
||||
|
||||
export const uploadDropStatus = (temp_id: UUID) => ({
|
||||
temp_id,
|
||||
type: UPLOAD_ACTIONS.DROP_STATUS
|
||||
type: UPLOAD_ACTIONS.DROP_STATUS,
|
||||
});
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { IResultWithStatus, IFile } from '~/redux/types';
|
||||
import {
|
||||
IResultWithStatus, IFile, IUploadProgressHandler, IFileWithUUID,
|
||||
} from '~/redux/types';
|
||||
import { api, configWithToken } from '~/utils/api';
|
||||
import { API } from '~/constants/api';
|
||||
|
||||
|
@ -7,11 +9,9 @@ export const postUploadFile = ({
|
|||
file,
|
||||
target = 'others',
|
||||
type = 'image',
|
||||
}: {
|
||||
}: IFileWithUUID & {
|
||||
access: string;
|
||||
file: File;
|
||||
target: string;
|
||||
type: string;
|
||||
onProgress: IUploadProgressHandler;
|
||||
}): Promise<IResultWithStatus<IFile>> => {
|
||||
const data = new FormData();
|
||||
data.append('file', file);
|
||||
|
|
|
@ -8,12 +8,21 @@ import { reqWrapper } from '../auth/sagas';
|
|||
import { createUploader, uploadGetThumb, fakeUploader } from '~/utils/uploader';
|
||||
import { HTTP_RESPONSES } from '~/utils/api';
|
||||
import { VALIDATORS } from '~/utils/validators';
|
||||
import { UUID, IFileWithUUID, IFile } from '../types';
|
||||
import { UUID, IFileWithUUID, IFile, IUploadProgressHandler } from '../types';
|
||||
|
||||
|
||||
function* uploadCall({ temp_id, onProgress, file }) {
|
||||
function* uploadCall({ file, temp_id, target, type, onProgress }: IFileWithUUID & { onProgress: IUploadProgressHandler }) {
|
||||
// return yield call(reqWrapper, fakeUploader, { file: { url: 'some', error: 'cant do this boss' }, onProgress, mustSucceed: true });
|
||||
return yield call(reqWrapper, postUploadFile, { file: { url: 'some', error: 'cant do this boss' }, onProgress, mustSucceed: true });
|
||||
return yield call(
|
||||
reqWrapper,
|
||||
postUploadFile,
|
||||
{
|
||||
file,
|
||||
temp_id,
|
||||
type,
|
||||
target,
|
||||
onProgress,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function* onUploadProgress(chan) {
|
||||
|
@ -33,13 +42,19 @@ function* uploadCancelWorker(id) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function* uploadWorker(file: File, temp_id: UUID) {
|
||||
const [promise, chan] = createUploader<{ temp_id; file }, { temp_id }>(uploadCall, { temp_id });
|
||||
function* uploadWorker({
|
||||
file, temp_id, target, type,
|
||||
}: IFileWithUUID) {
|
||||
const [promise, chan] = createUploader<Partial<IFileWithUUID>, Partial<IFileWithUUID>>(uploadCall, { temp_id, target, type });
|
||||
|
||||
yield fork(onUploadProgress, chan);
|
||||
|
||||
return yield call(promise, { temp_id, file });
|
||||
return yield call(promise, {
|
||||
temp_id, file, target, type,
|
||||
});
|
||||
}
|
||||
function* uploadFile({ file, temp_id }: IFileWithUUID) {
|
||||
|
||||
function* uploadFile({ file, temp_id, type, target }: IFileWithUUID) {
|
||||
if (!file.type || !VALIDATORS.IS_IMAGE_MIME(file.type)) {
|
||||
return { error: 'File_Not_Image', status: HTTP_RESPONSES.BAD_REQUEST, data: {} };
|
||||
}
|
||||
|
@ -62,7 +77,7 @@ function* uploadFile({ file, temp_id }: IFileWithUUID) {
|
|||
const {
|
||||
result, cancel, cancel_editing, save_inventory,
|
||||
} = yield race({
|
||||
result: call(uploadWorker, file, temp_id),
|
||||
result: call(uploadWorker, { file, temp_id, target, type }),
|
||||
cancel: call(uploadCancelWorker, temp_id),
|
||||
// subject_cancel: call(uploadSubjectCancelWorker, subject)
|
||||
// add here CANCEL_UPLOADS worker, that will watch for subject
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue