flotilla/src/app/components/ChannelCompose.svelte

55 lines
1.5 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"
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"
2025-01-02 18:04:28 +00:00
import {getEditor} 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 let editor: ReturnType<typeof getEditor> | undefined = undefined
const uploading = writable(false)
let element: HTMLElement
const uploadFiles = () => $editor!.chain().selectFiles().run()
const submit = () => {
if ($uploading) return
2024-11-16 16:04:09 +00:00
2024-10-01 18:47:21 +00:00
onSubmit({
2025-01-02 18:04:28 +00:00
content: $editor!.getText({blockSeparator: "\n"}).trim(),
2025-01-02 23:57:51 +00:00
tags: $editor!.storage.nostr.getEditorTags(),
2024-08-22 23:16:35 +00:00
})
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
}
2024-08-19 21:22:16 +00:00
onMount(() => {
2025-01-02 18:04:28 +00:00
editor = getEditor({autofocus: !isMobile, aggressive: true, element, submit, uploading})
$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">
2025-01-02 18:04:28 +00:00
<div bind:this={element} />
2024-08-22 23:16:35 +00:00
</div>
2024-11-16 16:04:09 +00:00
</form>