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