From 5b71fc6b27f5ff32aef717fe1a3222cdc608126b Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Tue, 8 Mar 2022 13:19:42 -0800 Subject: [PATCH] Better header loading --- .../components/document/document.module.css | 2 -- client/components/formatting-icons/index.tsx | 32 +++++++++++++++++-- client/components/header/index.tsx | 11 +------ client/components/preview/index.tsx | 3 +- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/client/components/document/document.module.css b/client/components/document/document.module.css index 273c29c..4ab0dab 100644 --- a/client/components/document/document.module.css +++ b/client/components/document/document.module.css @@ -3,8 +3,6 @@ } .descriptionContainer { - padding: var(--gap); - padding-top: 0; display: flex; flex-direction: column; min-height: 400px; diff --git a/client/components/formatting-icons/index.tsx b/client/components/formatting-icons/index.tsx index 67e2f9b..01a2f31 100644 --- a/client/components/formatting-icons/index.tsx +++ b/client/components/formatting-icons/index.tsx @@ -1,5 +1,5 @@ import { ButtonGroup, Button } from "@geist-ui/core" -import { Bold, Italic, Underline, Link } from '@geist-ui/icons' +import { Bold, Italic, Underline, Link, Image as ImageIcon } from '@geist-ui/icons' import { RefObject, useCallback, useMemo } from "react" // TODO: clean up @@ -72,6 +72,27 @@ const FormattingIcons = ({ textareaRef, setText }: { textareaRef?: RefObject { + if (textareaRef?.current && setText) { + const selectionStart = textareaRef.current.selectionStart + const selectionEnd = textareaRef.current.selectionEnd + const text = textareaRef.current.value + const before = text.substring(0, selectionStart) + const after = text.substring(selectionEnd) + const selectedText = text.substring(selectionStart, selectionEnd) + let formattedText = ''; + if (selectedText.includes('http')) { + formattedText = `![](${selectedText})` + } else { + formattedText = `![${selectedText}](https://)` + } + const newText = `${before}${formattedText}${after}` + setText(newText) + textareaRef.current.focus() + textareaRef.current.setSelectionRange(before.length + 1, before.length + 1 + selectedText.length) + } + }, [setText, textareaRef]) + const formattingActions = useMemo(() => [ { icon: , @@ -92,8 +113,13 @@ const FormattingIcons = ({ textareaRef, setText }: { textareaRef?: RefObject, name: 'hyperlink', action: handleLinkClick + }, + { + icon: , + name: 'image', + action: handleImageClick } - ], [handleBoldClick, handleItalicClick, handleLinkClick]) + ], [handleBoldClick, handleImageClick, handleItalicClick, handleLinkClick]) return (
@@ -102,7 +128,7 @@ const FormattingIcons = ({ textareaRef, setText }: { textareaRef?: RefObject {formattingActions.map(({ icon, name, action }) => ( -
diff --git a/client/components/header/index.tsx b/client/components/header/index.tsx index 617e4ce..29285a5 100644 --- a/client/components/header/index.tsx +++ b/client/components/header/index.tsx @@ -5,9 +5,6 @@ import { useEffect, useMemo, useState } from "react"; import styles from './header.module.css'; import { useRouter } from "next/router"; import useSignedIn from "../../lib/hooks/use-signed-in"; -import Mobile from "./controls"; -import Controls from "./controls"; -import NextLink from 'next/link' const Header = ({ changeTheme, theme }: DriftProps) => { const router = useRouter(); @@ -90,12 +87,6 @@ const Header = ({ changeTheme, theme }: DriftProps) => { })?.href) }, [pages, router, router.pathname]) - if (isLoading) { - return - - - } - return ( {!isMobile &&
@@ -114,7 +105,7 @@ const Header = ({ changeTheme, theme }: DriftProps) => { router.push(`${tab}`) } }}> - {pages.map((tab, index) => { + {!isLoading && pages.map((tab, index) => { if (tab.condition) return { - {/* remarkGfm is github flavored markdown support */ } + {/* remarkGfm is github flavored markdown support, a11yEmoji wraps emojis in accessible spans for screen readers */ } return (
{content || ""}
)