Files
TheGame/packages/web/lib/hooks/useDropFiles.tsx
vidvidvid ec8182d7da Role Onboarding using Quest Chains (#1150)
* feat: set up quests dashboard

move quest explorer to /quests/general

* feat: prepare containers for path-of-the-engaged and initiation quests

* chore(release): 0.2.0

* feat: add metacollab and web 3 onboarding categories

* feat: move initiation quests from notion -> metaOS

awyiss it's happening

* chore: lint quickfix

* feat: add descriptions, objectives, checkbox, collapse/expand

* add Dockerfile to .gitignore

* go

* quick fix

* upload proof modal

* config and install

* upload proof works

* show status of quests (pending, etc..)

* remove initiation & update engaged quests

* fix quest categories

add bridgebuilders, builders, patrons, fix icons

* typecheck fix

* fix address for bridgebuilders quests

* design of chain progress + small fix

* minor fixes

* using latest version of quest-chains sdk

* basic UI for quests

* using children for react-markdown

* better styling for quest tiles

* completed quest chain styling

* fixed toasts

* fixed imageLink

* added link to quest chains

* minor fixes

* added back to onboarding paths link

* fixed external link icon as absolute pos

* reduce gaps for mobile

Co-authored-by: Vid <vid@meisterlabs.com>
Co-authored-by: dan13ram <dan13ram@gmail.com>
2022-10-08 19:05:42 +01:00

79 lines
1.9 KiB
TypeScript

import { BoxProps } from '@metafam/ds';
import { useCallback, useState } from 'react';
import { DropzoneInputProps, DropzoneProps, useDropzone } from 'react-dropzone';
export type DropFilesType = {
onOpenFilesInput: () => void;
onResetFiles: () => void;
dropzoneProps: { className: string } & BoxProps;
inputProps: DropzoneInputProps;
onRemoveFile: (file: File) => void;
files: File[];
};
export const useDropFiles = (options: DropzoneProps = {}): DropFilesType => {
const [files, setFiles] = useState<File[]>([]);
const onResetFiles = useCallback(() => setFiles([]), []);
const onDrop = useCallback(
(acceptedFiles: File[]) =>
setFiles((oldFiles) => [...oldFiles, ...acceptedFiles]),
[],
);
const onRemoveFile = useCallback(
(file: File) =>
setFiles((oldFiles) => {
const newFiles = [...oldFiles];
newFiles.splice(newFiles.indexOf(file), 1);
return newFiles;
}),
[],
);
const { getRootProps, getInputProps, open } = useDropzone({
// Disable click and keydown behavior
noClick: true,
noKeyboard: true,
onDrop,
...options,
});
return {
dropzoneProps: getRootProps({ className: 'dropzone' }),
inputProps: getInputProps(),
files,
onRemoveFile,
onResetFiles,
onOpenFilesInput: open,
};
};
export type DropImageType = {
onOpenImageInput: () => void;
onResetImage: () => void;
dropzoneProps: { className: string } & BoxProps;
inputProps: DropzoneInputProps;
imageFile: File | null;
};
export const useDropImage = (options: DropzoneProps = {}): DropImageType => {
const { files, dropzoneProps, inputProps, onResetFiles, onOpenFilesInput } =
useDropFiles({
multiple: false,
accept: {
'image/*': ['.jpeg', '.png', '.jpg', '.gif'],
},
...options,
});
return {
imageFile: files[0] ?? null,
dropzoneProps,
inputProps,
onResetImage: onResetFiles,
onOpenImageInput: onOpenFilesInput,
};
};