diff --git a/src/components/Editor/components/Error.tsx b/src/components/Editor/components/Error.tsx index bcfcb97b..e53d2abe 100644 --- a/src/components/Editor/components/Error.tsx +++ b/src/components/Editor/components/Error.tsx @@ -24,7 +24,7 @@ const InvalidState = (props: { title: string }) => { const onClick = () => ctrl.clean() return ( -
@@ -48,12 +48,12 @@ const Other = () => { const onClick = () => ctrl.discard() const getMessage = () => { - const err = (store.error.props as any).error - return typeof err === 'string' ? err : err.message + const { error } = store.error.props as any + return typeof error === 'string' ? error : error.message } return ( -
diff --git a/src/components/Editor/components/ProseMirror.tsx b/src/components/Editor/components/ProseMirror.tsx index 632055c0..f384a2ed 100644 --- a/src/components/Editor/components/ProseMirror.tsx +++ b/src/components/Editor/components/ProseMirror.tsx @@ -59,13 +59,5 @@ export const ProseMirror = (props: Props) => { [props.text, props.extensions] ) - return ( - - ) + return } diff --git a/src/components/Editor/components/Sidebar.tsx b/src/components/Editor/components/Sidebar.tsx index 7966d4a6..f980f7c1 100644 --- a/src/components/Editor/components/Sidebar.tsx +++ b/src/components/Editor/components/Sidebar.tsx @@ -1,9 +1,14 @@ -import { Show, createEffect, createSignal, onCleanup } from 'solid-js' +import { Show, createEffect, createSignal, onCleanup, For } from 'solid-js' import { unwrap } from 'solid-js/store' import { undo, redo } from 'prosemirror-history' import { useState } from '../store' import type { Styled } from './Layout' + import '../styles/Sidebar.scss' +import { router } from '../../../stores/router' +import { t } from '../../../utils/intl' +import { isEmpty } from '../prosemirror/helpers' +import type { EditorState } from 'prosemirror-state' const Off = (props) => +@@ -24,8 +29,19 @@ const Link = ( ) +const mod = 'Ctrl' +const Keys = (props) => ( +{(k: string) => {k}} + +) + +interface SidebarProps { + error?: string +} + // eslint-disable-next-line sonarjs/cognitive-complexity -export const Sidebar = (props) => { +export const Sidebar = (_props: SidebarProps) => { const [store, ctrl] = useState() const [lastAction, setLastAction] = createSignal() const toggleTheme = () => { @@ -47,7 +63,11 @@ export const Sidebar = (props) => { const onNew = () => ctrl.newFile() const onDiscard = () => ctrl.discard() const [isHidden, setIsHidden] = createSignal () - + // eslint-disable-next-line unicorn/consistent-function-scoping + const onHistory = () => { + console.log('[editor.sidebar] implement history handling') + router.open('/create/settings') + } const toggleSidebar = () => setIsHidden(!isHidden()) toggleSidebar() @@ -67,14 +87,22 @@ export const Sidebar = (props) => { }, 1000) onCleanup(() => clearTimeout(id)) }) - + const discardText = () => { + if (store.path) { + return 'Close' + } else if (store.drafts.length > 0 && isEmpty(store.text as EditorState)) { + return 'Delete ⚠️' + } else { + return 'Clear' + } + } return (