This commit is contained in:
Tyler Brown Cifu Shuster 2020-12-02 07:09:12 -08:00
parent e5ea163bfa
commit 489a3351c4
4 changed files with 18 additions and 14 deletions

View File

@ -90,7 +90,7 @@ export function useFileDrag(dragged: (f: FileList | File[], e: DragEvent) => voi
return () => { return () => {
document.body.removeEventListener('mouseout', mouseleave); document.body.removeEventListener('mouseout', mouseleave);
} }
}, [setDragging]); }, []);
const bind = { const bind = {
onDragLeave, onDragLeave,

View File

@ -1,6 +1,7 @@
import { useCallback, useMemo, useEffect, useRef, useState } from "react"; import { useCallback, useMemo, useEffect, useRef, useState } from "react";
import { S3State } from "../../types/s3-update"; import { S3State } from "../../types/s3-update";
import S3 from "aws-sdk/clients/s3"; import S3 from "aws-sdk/clients/s3";
import { dateToDa, deSig } from "./util";
export interface IuseS3 { export interface IuseS3 {
canUpload: boolean; canUpload: boolean;
@ -37,9 +38,14 @@ const useS3 = (s3: S3State, { accept = '*' } = { accept: '*' }): IuseS3 => {
throw new Error("S3 not ready"); throw new Error("S3 not ready");
} }
const fileParts = file.name.split('.');
const fileName = fileParts.slice(0, -1);
const fileExtension = fileParts.pop();
const timestamp = deSig(dateToDa(new Date()));
const params = { const params = {
Bucket: bucket, Bucket: bucket,
Key: file.name, Key: `${window.ship}/${timestamp}-${fileName}.${fileExtension}`,
Body: file, Body: file,
ACL: "public-read", ACL: "public-read",
ContentType: file.type, ContentType: file.type,
@ -61,7 +67,7 @@ const useS3 = (s3: S3State, { accept = '*' } = { accept: '*' }): IuseS3 => {
throw new Error("current bucket not set"); throw new Error("current bucket not set");
} }
return upload(file, s3.configuration.currentBucket); return upload(file, s3.configuration.currentBucket);
}, []); }, [s3]);
const promptUpload = useCallback( const promptUpload = useCallback(
() => { () => {

View File

@ -87,7 +87,7 @@ const LinkSubmit = (props: LinkSubmitProps) => {
}; };
const onFileDrag = useCallback( const onFileDrag = useCallback(
async (files: FileList | File[], e: DragEvent) => { (files: FileList | File[], e: DragEvent): void => {
if (!canUpload) { if (!canUpload) {
return; return;
} }
@ -117,17 +117,15 @@ const LinkSubmit = (props: LinkSubmitProps) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
uploadDefault(event.clipboardData.files[0]).then(setLinkValue); uploadDefault(event.clipboardData.files[0]).then(setLinkValue);
}, [setLinkValue] }, [setLinkValue, uploadDefault]
); );
const onKeyPress = useCallback( const onKeyPress = (e) => {
(e) => { if (e.key === 'Enter') {
if (e.key === 'Enter') { e.preventDefault();
e.preventDefault(); doPost();
doPost(); }
} };
}, []
);
const placeholder = <Text const placeholder = <Text
gray gray

View File

@ -98,7 +98,7 @@ export function MarkdownEditor(
return ( return (
<Box <Box
height="100%" height="100%"
position="static" position="relative"
className="publish" className="publish"
p={1} p={1}
border={1} border={1}