mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
removed upload redux store
This commit is contained in:
parent
140e36b6b7
commit
95b92b643f
38 changed files with 398 additions and 691 deletions
|
@ -1,23 +1,26 @@
|
|||
import React, { ChangeEvent, FC, useCallback, useEffect } from 'react';
|
||||
import styles from './styles.module.scss';
|
||||
import { UPLOAD_SUBJECTS, UPLOAD_TARGETS, UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
import { path } from 'ramda';
|
||||
import { UploadSubject, UploadTarget, UploadType } from '~/constants/uploads';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
import { IEditorComponentProps } from '~/types/node';
|
||||
import { useFileUploader } from '~/hooks/data/useFileUploader';
|
||||
import { useNodeFormContext } from '~/hooks/node/useNodeFormFormik';
|
||||
import { getFileType } from '~/utils/uploader';
|
||||
import { useUploader } from '~/hooks/data/useUploader';
|
||||
|
||||
type IProps = IEditorComponentProps & {};
|
||||
|
||||
const EditorUploadCoverButton: FC<IProps> = ({}) => {
|
||||
const { values, setFieldValue } = useNodeFormContext();
|
||||
const { uploadFiles, files } = useFileUploader(UPLOAD_SUBJECTS.EDITOR, UPLOAD_TARGETS.NODES, []);
|
||||
const { uploadFiles, files, pendingImages } = useUploader(
|
||||
UploadSubject.Editor,
|
||||
UploadTarget.Nodes,
|
||||
[]
|
||||
);
|
||||
|
||||
const background = values.cover ? getURL(values.cover, PRESETS['300']) : null;
|
||||
const preview = status && path(['preview'], status);
|
||||
const preview = pendingImages?.[0]?.thumbnail || '';
|
||||
|
||||
const onDropCover = useCallback(() => {
|
||||
setFieldValue('cover', null);
|
||||
|
@ -26,7 +29,7 @@ const EditorUploadCoverButton: FC<IProps> = ({}) => {
|
|||
const onInputChange = useCallback(
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
const files = Array.from(event.target.files || [])
|
||||
.filter(file => getFileType(file) === UPLOAD_TYPES.IMAGE)
|
||||
.filter(file => getFileType(file) === UploadType.Image)
|
||||
.slice(0, 1);
|
||||
|
||||
uploadFiles(files);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue