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