From b2b849695bd826f86b79405cf3065624c5cee972 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sun, 13 Feb 2022 00:53:36 -0600 Subject: [PATCH] fix drop target --- .../components/file-drop-target.scss | 12 +++-- .../sections/send-message.scss | 4 +- .../elements/components/file-drop-target.tsx | 8 ++- .../elements/contexts/context-menu-image.tsx | 26 +++++++--- .../webapp/elements/require/react-helper.tsx | 13 ++++- .../webapp/elements/sections/send-message.tsx | 51 ++++++++++++++++--- src/client/webapp/index.html | 2 - 7 files changed, 92 insertions(+), 24 deletions(-) diff --git a/src/client/webapp/elements-styles/components/file-drop-target.scss b/src/client/webapp/elements-styles/components/file-drop-target.scss index 0038578..96cac36 100644 --- a/src/client/webapp/elements-styles/components/file-drop-target.scss +++ b/src/client/webapp/elements-styles/components/file-drop-target.scss @@ -15,7 +15,7 @@ // TODO: make this nicer color: theme.$text-normal; background-color: theme.$background-primary; - padding: 16px; + padding: 32px; border-radius: 8px; display: flex; @@ -28,9 +28,15 @@ margin-right: 16px; } - .drop-message { - font-size: 2em; + .drop-description { color: theme.$header-primary; + .drop-title { + font-size: 2em; + font-weight: 600; + } + .drop-message { + font-size: 1.5em; + } } } } diff --git a/src/client/webapp/elements-styles/sections/send-message.scss b/src/client/webapp/elements-styles/sections/send-message.scss index 968f70f..23db4b9 100644 --- a/src/client/webapp/elements-styles/sections/send-message.scss +++ b/src/client/webapp/elements-styles/sections/send-message.scss @@ -26,7 +26,7 @@ $borderRadius: 8px; .attachment-preview { position: relative; margin: 16px 16px 0 16px; - padding: 8px; + padding: 12px; border-radius: 8px; box-sizing: border-box; max-width: calc(100% - 32px); @@ -40,6 +40,8 @@ $borderRadius: 8px; } .name { + color: theme.$interactive-hover; + /* font-weight: 600; */ line-height: 1; overflow: hidden; white-space: nowrap; diff --git a/src/client/webapp/elements/components/file-drop-target.tsx b/src/client/webapp/elements/components/file-drop-target.tsx index feb45b0..cc4d238 100644 --- a/src/client/webapp/elements/components/file-drop-target.tsx +++ b/src/client/webapp/elements/components/file-drop-target.tsx @@ -6,6 +6,7 @@ const LOG = Logger.create(__filename, electronConsole); import React, { Dispatch, DragEvent, FC, SetStateAction, useCallback, useRef } from 'react'; export interface FileDropTargetProps { + title: string; message: string; setBuff: Dispatch>; setName: Dispatch>; @@ -13,7 +14,7 @@ export interface FileDropTargetProps { } const FileDropTarget: FC = (props: FileDropTargetProps) => { - const { setBuff, setName, close, message } = props; + const { setBuff, setName, close, title, message } = props; const rootRef = useRef(null); @@ -64,7 +65,10 @@ const FileDropTarget: FC = (props: FileDropTargetProps) =>
file -
{message}
+
+
{title}
+
{message}
+
); diff --git a/src/client/webapp/elements/contexts/context-menu-image.tsx b/src/client/webapp/elements/contexts/context-menu-image.tsx index 87b66b0..c146c1b 100644 --- a/src/client/webapp/elements/contexts/context-menu-image.tsx +++ b/src/client/webapp/elements/contexts/context-menu-image.tsx @@ -21,7 +21,7 @@ export interface ImageContextMenuProps { const ImageContextMenu: FC = (props: ImageContextMenuProps) => { const { relativeToPos, close, resourceName, resourceBuff, isPreview } = props; - const previewText = isPreview ? ' Preview' : ''; + const previewText = isPreview ? ' Preview' : ' Image'; // TODO: Integrate shaking @@ -44,23 +44,33 @@ const ImageContextMenu: FC = (props: ImageContextMenuProp }, [resourceBuff], { - start: 'Copy Image' + previewText, + start: 'Copy ' + previewText, pending: 'Copying' + previewText, error: 'Copy Failed. Click to Try Again', done: 'Copied to Clipboard', }, ); - const [saveCallable, saveText, _saveShaking] = useDownloadButton(resourceName + (isPreview ? '-preview.jpg' : ''), async () => resourceBuff, [resourceBuff], { - start: 'Save Image' + previewText, - pendingSave: 'Saving' + previewText + '...', - errorSave: 'Save Failed. Click to Try Again', - }); + const [saveCallable, saveText, _saveShaking] = useDownloadButton( + resourceName + (isPreview ? '-preview.jpg' : ''), + async () => resourceBuff, + [resourceBuff], + { + start: 'Save ' + previewText, + pendingSave: 'Saving' + previewText + '...', + errorSave: 'Save Failed. Click to Try Again', + }, + ); const alignment = useMemo(() => ({ top: 'centerY', left: 'centerX' }), []); return ( - +
{copyText} diff --git a/src/client/webapp/elements/require/react-helper.tsx b/src/client/webapp/elements/require/react-helper.tsx index ffeb26e..4486b6b 100644 --- a/src/client/webapp/elements/require/react-helper.tsx +++ b/src/client/webapp/elements/require/react-helper.tsx @@ -573,6 +573,7 @@ export function useContextHover( /** creates a drop target element that will appear when you drag a file over the document */ export function useDocumentDropTarget( + title: string, message: string, setBuff: Dispatch>, setName: Dispatch>, @@ -599,8 +600,16 @@ export function useDocumentDropTarget( const dropTarget = useMemo(() => { if (!dragEnabled) return null; - return ; - }, [closeDragOverlay, dragEnabled, message, setBuff, setName]); + return ( + + ); + }, [closeDragOverlay, dragEnabled, title, message, setBuff, setName]); return [dropTarget]; } diff --git a/src/client/webapp/elements/sections/send-message.tsx b/src/client/webapp/elements/sections/send-message.tsx index 62e5c22..c6a0307 100644 --- a/src/client/webapp/elements/sections/send-message.tsx +++ b/src/client/webapp/elements/sections/send-message.tsx @@ -1,8 +1,23 @@ -import React, { ClipboardEvent, FC, FormEvent, KeyboardEvent, RefObject, useCallback, useMemo, useRef, useState } from 'react'; +import React, { + ClipboardEvent, + FC, + FormEvent, + KeyboardEvent, + RefObject, + useCallback, + useMemo, + useRef, + useState, +} from 'react'; import { Channel } from '../../data-types'; import CombinedGuild from '../../guild-combined'; import BaseElements from '../require/base-elements'; -import { useAsyncVoidCallback, useDocumentDropTarget, useIsMountedRef, useOneTimeAsyncAction } from '../require/react-helper'; +import { + useAsyncVoidCallback, + useDocumentDropTarget, + useIsMountedRef, + useOneTimeAsyncAction, +} from '../require/react-helper'; import * as FileType from 'file-type'; import ElementsUtil from '../require/elements-util'; import FileInput from '../components/input-file'; @@ -66,7 +81,12 @@ const SendMessage: FC = (props: SendMessageProps) => { // TODO: Deal with errors (toasts are probably the best way) if (attachmentBuff && attachmentName) { - await guild.requestSendMessageWithResource(channel.id, text === '' ? null : text, attachmentBuff, attachmentName); + await guild.requestSendMessageWithResource( + channel.id, + text === '' ? null : text, + attachmentBuff, + attachmentName, + ); if (!isMounted.current) return; setAttachmentBuff(null); setAttachmentName(null); @@ -122,11 +142,22 @@ const SendMessage: FC = (props: SendMessageProps) => { setAttachmentName(null); }, []); - const [attachmentDropTarget] = useDocumentDropTarget('Upload to #' + channel.name, setAttachmentBuff, setAttachmentName); + const [attachmentDropTarget] = useDocumentDropTarget( + 'Drop to Attach', + '#' + channel.name, + setAttachmentBuff, + setAttachmentName, + ); const attachmentPreview = useMemo(() => { if (!attachmentBuff || !attachmentName) return null; - return ; + return ( + + ); }, [attachmentBuff, attachmentName, removeAttachment]); // WARNING: The types on this are funky because of react's lack of explicit support for 'plaintext-only' @@ -149,7 +180,15 @@ const SendMessage: FC = (props: SendMessageProps) => { {BaseElements.SEND_MESSAGE_ATTACH}
-
+
{attachmentDropTarget} diff --git a/src/client/webapp/index.html b/src/client/webapp/index.html index 703e750..c21d14b 100644 --- a/src/client/webapp/index.html +++ b/src/client/webapp/index.html @@ -9,7 +9,5 @@
- -