From 7e2590585dc53d258cb168d8278ab9ed510f34a6 Mon Sep 17 00:00:00 2001 From: James Xylight Date: Tue, 10 Jun 2025 11:46:48 -0700 Subject: [PATCH] impr: use modals for replies, close #466 --- .../components/lemmy/comment/Comment.svelte | 187 +++++++----------- .../lemmy/comment/CommentItem.svelte | 6 +- .../lemmy/community/CommunityLink.svelte | 3 +- src/lib/components/lemmy/post/Post.svelte | 2 +- src/lib/components/lemmy/post/PostMeta.svelte | 24 +-- .../components/markdown/MarkdownEditor.svelte | 25 ++- src/routes/search/+page.svelte | 5 +- 7 files changed, 112 insertions(+), 140 deletions(-) diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 1e0bb2ad..c68da992 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -1,32 +1,21 @@ -{#if editing} - +{#if editing || replying} + replying || editing, + v => { + replying = v + editing = v + } + } + > {#snippet customTitle()} - {$t('form.edit')} + {replying ? $t('comment.reply') : $t('form.edit')} {/snippet}
{ e.preventDefault() - save() + save(replying ? 'reply' : 'edit') }} class="contents" > - - + {#if replying} + { + node.children = [ + { + children: [], + comment_view: e.comment_view, + depth: node.depth + 1, + expanded: true, + }, + ...node.children, + ] + replying = false + }} + oncancel={() => (replying = false)} + /> + {:else if editing} + + + {/if}
{/if}
  • {#if meta} @@ -142,28 +153,6 @@ z-0 group relative" > {@render metaSuffix?.()} -
    -
    - {#if node.children.length > 0} - - {/if} - -
    -
    - {#if node.comment_view.comment.distinguished} -
    - {/if} -
    - -
    + {#if actions} {/if} - {#if replying} -
    -
    - { - node.children = [ - { - children: [], - comment_view: e.comment_view, - depth: node.depth + 1, - expanded: true, - }, - ...node.children, - ] - replying = false - }} - oncancel={() => (replying = false)} - /> -
    -
    - {/if}
    {@render children?.()}
    diff --git a/src/lib/components/lemmy/comment/CommentItem.svelte b/src/lib/components/lemmy/comment/CommentItem.svelte index 02b62100..a2e468f4 100644 --- a/src/lib/components/lemmy/comment/CommentItem.svelte +++ b/src/lib/components/lemmy/comment/CommentItem.svelte @@ -2,8 +2,8 @@ import Comment from '$lib/components/lemmy/comment/Comment.svelte' import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte' import { publishedToDate } from '$lib/components/util/date.js' - import { settings, type View } from '$lib/settings.svelte.js' import { t } from '$lib/i18n/translations' + import { settings, type View } from '$lib/settings.svelte.js' import type { CommentView } from 'lemmy-js-client' import { Button, Material } from 'mono-svelte' import { ArrowUturnUp, Icon } from 'svelte-hero-icons' @@ -29,9 +29,9 @@ {#if meta} diff --git a/src/lib/components/lemmy/community/CommunityLink.svelte b/src/lib/components/lemmy/community/CommunityLink.svelte index 847b4e04..5112ecfc 100644 --- a/src/lib/components/lemmy/community/CommunityLink.svelte +++ b/src/lib/components/lemmy/community/CommunityLink.svelte @@ -5,8 +5,9 @@ import { t } from '$lib/i18n/translations' import type { Community } from 'lemmy-js-client' import { ExclamationTriangle, Icon } from 'svelte-hero-icons' + import type { HTMLAnchorAttributes } from 'svelte/elements' - interface Props { + interface Props extends HTMLAnchorAttributes { community: Community avatar?: boolean name?: boolean diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index e8c3fd9b..b2c1e3d7 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -101,7 +101,7 @@
    (null) const shortcuts = { - KeyB: () => wrapSelection('**', '**'), - KeyI: () => wrapSelection('*', '*'), - KeyS: () => wrapSelection('~~', '~~'), - KeyH: () => wrapSelection('\n# ', ''), - KeyK: () => wrapSelection('[](', ')'), + b: () => wrapSelection('**', '**'), + i: () => wrapSelection('*', '*'), + s: () => wrapSelection('~~', '~~'), + h: () => wrapSelection('\n# ', ''), + k: () => wrapSelection('[](', ')'), } async function adjustHeight() { @@ -72,6 +72,18 @@ } } + function handleKeydown( + event: KeyboardEvent & { + currentTarget: EventTarget & HTMLTextAreaElement + }, + ) { + if (event.ctrlKey && event.key === 'Enter') { + event.preventDefault() + const form = textArea?.closest('form') + if (form) form.requestSubmit() // Automatically submits the form + } + } + interface Props extends TextAreaProps { images?: boolean value?: string @@ -255,8 +267,9 @@ overflow-hidden transition-colors {clazz}" onkeydown={e => { if (disabled) return if (e.ctrlKey || e.metaKey) { + handleKeydown(e) // @ts-expect-error yes it can - let shortcut = shortcuts[e.code] + let shortcut = shortcuts[e.key] if (shortcut) { e.preventDefault() shortcut?.(e) diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index fd9e3c14..a9ebf861 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -167,7 +167,10 @@
    {:then object} {#if object} -
    +
    {#if object.community}