flotilla/src/app/components/ChannelCompose.svelte

64 lines
1.8 KiB
Svelte
Raw Normal View History

2024-08-19 21:22:16 +00:00
<script lang="ts">
2024-08-26 21:43:43 +00:00
import {onMount} from "svelte"
2025-01-02 18:04:28 +00:00
import {writable} from "svelte/store"
import {EditorContent} from "svelte-tiptap"
2024-11-15 23:16:06 +00:00
import {isMobile} from "@lib/html"
2024-08-26 21:43:43 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import {makeEditor} from "@app/editor"
2024-08-23 20:33:36 +00:00
export let onSubmit: any
2024-10-23 23:41:11 +00:00
export let content = ""
2025-01-02 18:04:28 +00:00
export const focus = () => $editor.chain().focus().run()
2025-01-02 18:04:28 +00:00
const uploading = writable(false)
2025-01-02 18:04:28 +00:00
const uploadFiles = () => $editor!.chain().selectFiles().run()
const submit = () => {
if ($uploading) return
2024-11-16 16:04:09 +00:00
2025-01-15 17:07:12 +00:00
const content = $editor!.getText({blockSeparator: "\n"}).trim()
const tags = $editor!.storage.nostr.getEditorTags()
if (!content) return
onSubmit({content, tags})
2024-08-23 20:33:36 +00:00
2025-01-02 18:04:28 +00:00
$editor!.chain().clearContent().run()
2024-08-22 23:16:35 +00:00
}
const editor = makeEditor({autofocus: !isMobile, submit, uploading, aggressive: true})
2025-01-02 18:04:28 +00:00
onMount(() => {
2025-01-02 18:04:28 +00:00
$editor!.chain().setContent(content).run()
2024-08-19 21:22:16 +00:00
})
</script>
2024-11-16 16:04:09 +00:00
<form
class="relative z-feature flex gap-2 p-2"
2025-01-02 18:04:28 +00:00
on:submit|preventDefault={$uploading ? undefined : submit}>
2024-08-26 21:43:43 +00:00
<Button
2024-09-11 22:21:25 +00:00
data-tip="Add an image"
2024-10-25 00:25:28 +00:00
class="center tooltip tooltip-right h-10 w-10 min-w-10 rounded-box bg-base-300 transition-colors hover:bg-base-200"
2025-01-02 18:04:28 +00:00
disabled={$uploading}
on:click={uploadFiles}>
{#if $uploading}
2024-08-22 23:16:35 +00:00
<span class="loading loading-spinner loading-xs"></span>
{:else}
<Icon icon="gallery-send" />
{/if}
</Button>
2024-09-23 20:58:01 +00:00
<div class="chat-editor flex-grow overflow-hidden">
<EditorContent editor={$editor} />
2024-08-22 23:16:35 +00:00
</div>
2025-01-15 17:07:12 +00:00
<Button
data-tip="{window.navigator.platform.includes('Mac') ? 'cmd' : 'ctrl'}+enter to send"
class="center tooltip tooltip-left absolute right-4 h-10 w-10 min-w-10 rounded-full"
disabled={$uploading}
on:click={submit}>
<Icon icon="plain" />
</Button>
2024-11-16 16:04:09 +00:00
</form>