From db0a94b581bdd7a9161614f6a2d97d09daeb5480 Mon Sep 17 00:00:00 2001 From: muerwre Date: Tue, 20 Aug 2019 10:58:34 +0700 Subject: [PATCH] fixed eslint again --- .eslintrc.js | 9 +++------ src/redux/types.ts | 5 ++++- src/redux/uploads/actions.ts | 10 +++++----- src/redux/uploads/api.ts | 12 ++++++------ src/redux/uploads/sagas.ts | 33 ++++++++++++++++++++++++--------- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4a82f923..dd724fe8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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, }, }; diff --git a/src/redux/types.ts b/src/redux/types.ts index b04ebb82..839a5156 100644 --- a/src/redux/types.ts +++ b/src/redux/types.ts @@ -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; diff --git a/src/redux/uploads/actions.ts b/src/redux/uploads/actions.ts index aa3e4419..75545669 100644 --- a/src/redux/uploads/actions.ts +++ b/src/redux/uploads/actions.ts @@ -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) => ({ 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) => ({ 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, }); diff --git a/src/redux/uploads/api.ts b/src/redux/uploads/api.ts index 42b12ee5..a5c7aa23 100644 --- a/src/redux/uploads/api.ts +++ b/src/redux/uploads/api.ts @@ -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', -}: { -access: string; -file: File; -target: string; -type: string; +}: IFileWithUUID & { + access: string; + onProgress: IUploadProgressHandler; }): Promise> => { const data = new FormData(); data.append('file', file); diff --git a/src/redux/uploads/sagas.ts b/src/redux/uploads/sagas.ts index 1c79ab6c..0d4a900e 100644 --- a/src/redux/uploads/sagas.ts +++ b/src/redux/uploads/sagas.ts @@ -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>(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