impr: improve post creation
This commit is contained in:
1 parent
4c7ae5d781
commit
190b28a331
4 files changed
+142
-70
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string
|
||||
export let required: boolean = false
|
||||
|
||||
let textarea: HTMLTextAreaElement
|
||||
|
||||
function adjustHeight() {
|
||||
textarea.style.height = 'auto' // Reset height to auto to calculate new height
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
{#if label}
|
||||
<div class="text-sm font-medium">
|
||||
{label}
|
||||
{#if required}
|
||||
<span class="text-red-600 font-bold">*</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
on:input={adjustHeight}
|
||||
bind:value
|
||||
{required}
|
||||
{...$$restProps}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-none w-full bg-transparent resize-none {$$props.class}"
|
||||
/>
|
||||
</label>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { client, site } from '$lib/lemmy.js'
|
||||
import type { Community, Language, Post, PostView } from 'lemmy-js-client'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
import { Select, Spinner, Switch, toast } from 'mono-svelte'
|
||||
import {
|
||||
Check,
|
||||
@@ -13,6 +13,8 @@
|
||||
ChatBubbleBottomCenterText,
|
||||
EllipsisHorizontal,
|
||||
Plus,
|
||||
Language,
|
||||
Link,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
@@ -30,6 +32,7 @@
|
||||
pushError,
|
||||
} from '$lib/components/error/ErrorContainer.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
@@ -61,6 +64,7 @@
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
}
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
@@ -78,7 +82,7 @@
|
||||
data.nsfw = editingPost.nsfw
|
||||
data.alt_text = editingPost.alt_text
|
||||
data.thumbnail = editingPost.thumbnail_url
|
||||
data.language_id = editingPost.language_id
|
||||
data.language_id = editingPost.language_id.toString()
|
||||
}
|
||||
|
||||
if (passedCommunity) {
|
||||
@@ -293,93 +297,121 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<TextInput
|
||||
<FreeTextInput
|
||||
type="text"
|
||||
required
|
||||
label={$t('form.post.title')}
|
||||
bind:value={data.title}
|
||||
placeholder={placeholders.get('post')}
|
||||
label={$t('form.post.title')}
|
||||
/>
|
||||
<div class="flex flex-col gap-2">
|
||||
<TextInput
|
||||
label={$t('form.post.url')}
|
||||
bind:value={data.url}
|
||||
placeholder={placeholders.get('url')}
|
||||
class="w-full"
|
||||
/>
|
||||
<div class="flex items-center gap-2 actions">
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
</div>
|
||||
{#if data.url}
|
||||
<MarkdownEditor
|
||||
label={$t('form.post.body')}
|
||||
bind:value={data.body}
|
||||
placeholder={placeholders.get('post')}
|
||||
previewButton
|
||||
/>
|
||||
{#if data.url !== undefined}
|
||||
<div class="flex flex-col gap-2">
|
||||
<TextInput
|
||||
label={$t('form.post.url')}
|
||||
bind:value={data.url}
|
||||
placeholder={placeholders.get('url')}
|
||||
class="w-full"
|
||||
/>
|
||||
<div class="flex items-center gap-2 actions">
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
</div>
|
||||
{#if data.url}
|
||||
<Button
|
||||
on:click={() => (addAltText = !addAltText)}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => (addAltText = !addAltText)}
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if generation.generatable}
|
||||
<Button
|
||||
on:click={() => generateTitle(data.url)}
|
||||
loading={generation.loading}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex flex-row gap-2 flex-wrap">
|
||||
{#if data.url === undefined}
|
||||
<Button on:click={() => (data.url = '')} size="lg">
|
||||
<Icon src={Link} size="16" micro />
|
||||
{$t('form.post.addUrl')}
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
on:click={() => {
|
||||
data.url = ''
|
||||
uploadingImage = true
|
||||
}}
|
||||
size="lg"
|
||||
>
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
<Icon src={Photo} size="16" micro />
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
<Button
|
||||
on:click={() => generateTitle(data.url)}
|
||||
loading={generation.loading}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if data.language_id === undefined}
|
||||
<Button size="lg" on:click={() => (data.language_id = 0)}>
|
||||
<Icon src={Language} size="16" micro />
|
||||
{$t('form.post.setLanguage')}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{#if addAltText}
|
||||
<div transition:slide={{ axis: 'y', duration: 150 }} class="w-full">
|
||||
<TextInput label={$t('form.post.altText')} bind:value={data.alt_text} />
|
||||
</div>
|
||||
{/if}
|
||||
<MarkdownEditor
|
||||
rows={8}
|
||||
label={$t('form.post.body')}
|
||||
bind:value={data.body}
|
||||
placeholder={placeholders.get('post')}
|
||||
previewButton
|
||||
/>
|
||||
<Switch bind:checked={data.nsfw}>{$t('form.post.nsfw')}</Switch>
|
||||
{#if $site}
|
||||
<Select
|
||||
class="w-max"
|
||||
label={$t('settings.app.lang.title')}
|
||||
bind:value={data.language_id}
|
||||
>
|
||||
{#each $site?.all_languages as language}
|
||||
<option value={language.id.toString()}>{language.name}</option>
|
||||
{/each}
|
||||
</Select>
|
||||
{:else}
|
||||
<div style="height: 58px;">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{#if data.language_id !== undefined}
|
||||
{#if $site}
|
||||
<Select
|
||||
class="w-max"
|
||||
label={$t('settings.app.lang.title')}
|
||||
bind:value={data.language_id}
|
||||
>
|
||||
{#each $site?.all_languages as language}
|
||||
<option value={language.id.toString()}>{language.name}</option>
|
||||
{/each}
|
||||
</Select>
|
||||
{:else}
|
||||
<div style="height: 58px;">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="mt-auto" />
|
||||
<div class="flex flex-row items-center gap-2 w-full">
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
export let previewButton: boolean = true
|
||||
export let tools: boolean = true
|
||||
export let disabled: boolean = false
|
||||
export let rows: number = 4
|
||||
export let rows: number = 2
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
@@ -83,6 +83,11 @@
|
||||
e.target.form.dispatchEvent(newEvent)
|
||||
},
|
||||
}
|
||||
|
||||
function adjustHeight() {
|
||||
textArea.style.height = 'auto' // Reset height to auto to calculate new height
|
||||
textArea.style.height = `${textArea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if uploadingImage && images}
|
||||
@@ -227,7 +232,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
{/if}
|
||||
<!--Actual text area-->
|
||||
<TextArea
|
||||
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none"
|
||||
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none resize-none"
|
||||
bind:value
|
||||
bind:element={textArea}
|
||||
on:keydown={(e) => {
|
||||
@@ -241,6 +246,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
}
|
||||
}
|
||||
}}
|
||||
on:input={adjustHeight}
|
||||
on:focus
|
||||
on:paste={(e) => {
|
||||
if (!e.clipboardData?.files) return
|
||||
|
||||
@@ -136,7 +136,9 @@
|
||||
"generateTitle": "Generate Title",
|
||||
"uploadImage": "Upload Image",
|
||||
"selectFile": "Select a file",
|
||||
"altText": "Alt Text"
|
||||
"altText": "Alt Text",
|
||||
"addUrl": "Add URL",
|
||||
"setLanguage": "Set language"
|
||||
},
|
||||
"profile": {
|
||||
"displayName": "Display name",
|
||||
|
||||
Reference in new issue
Block a user