impr: rewrite image upload handling
This commit is contained in:
11 files changed
+200
-286
No files matched your search
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import ImageUploadModal from '$lib/components/lemmy/modal/ImageUploadModal.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
@@ -23,6 +22,7 @@
|
||||
import { DocumentPlus, Icon, Plus } from 'svelte-hero-icons'
|
||||
import type { PageData } from './$types.js'
|
||||
import { errorMessage } from '$lib/lemmy/error.js'
|
||||
import ImageInputUpload from '$lib/components/form/ImageInputUpload.svelte'
|
||||
|
||||
interface Props {
|
||||
data: PageData
|
||||
@@ -108,66 +108,18 @@
|
||||
}
|
||||
label={$t('routes.legal.title')}
|
||||
/>
|
||||
<div class="flex flex-col gap-1">
|
||||
<Label>{$t('routes.admin.config.icon')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (uploading.icon = !uploading.icon)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.icon}
|
||||
<img src={formData.icon} alt="" class="rounded-md mx-auto h-full" />
|
||||
{:else}
|
||||
<Icon
|
||||
src={DocumentPlus}
|
||||
size="48"
|
||||
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
||||
/>
|
||||
{/if}
|
||||
</button>
|
||||
{#if uploading.icon}
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.icon}
|
||||
multiple={false}
|
||||
onupload={uploaded => {
|
||||
uploading.icon = false
|
||||
formData.icon = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<Label>{$t('routes.admin.config.banner')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (uploading.banner = !uploading.banner)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.banner}
|
||||
<img src={formData.banner} alt="" class="rounded-md mx-auto h-full" />
|
||||
{:else}
|
||||
<Icon
|
||||
src={DocumentPlus}
|
||||
size="48"
|
||||
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
||||
/>
|
||||
{/if}
|
||||
</button>
|
||||
{#if uploading.banner}
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.banner}
|
||||
multiple={false}
|
||||
onupload={uploaded => {
|
||||
uploading.banner = false
|
||||
formData.banner = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<Switch bind:checked={formData.enable_downvotes} defaultValue={true}>
|
||||
<ImageInputUpload
|
||||
label={$t('routes.admin.config.icon')}
|
||||
bind:imageUrl={formData.icon}
|
||||
/>
|
||||
<ImageInputUpload
|
||||
label={$t('routes.admin.config.banner')}
|
||||
bind:imageUrl={formData.banner}
|
||||
/>
|
||||
<Switch bind:checked={formData.enable_downvotes}>
|
||||
{$t('routes.admin.config.downvotesEnabled')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.enable_nsfw} defaultValue={true}>
|
||||
<Switch bind:checked={formData.enable_nsfw}>
|
||||
{$t('routes.admin.config.nsfwEnabled')}
|
||||
</Switch>
|
||||
<Select
|
||||
@@ -192,25 +144,16 @@
|
||||
bind:value={formData.application_question}
|
||||
/>
|
||||
{/if}
|
||||
<Switch
|
||||
bind:checked={formData.community_creation_admin_only}
|
||||
defaultValue={true}
|
||||
>
|
||||
<Switch bind:checked={formData.community_creation_admin_only}>
|
||||
{$t('routes.admin.config.adminCommunityOnly')}
|
||||
</Switch>
|
||||
<Switch
|
||||
bind:checked={formData.require_email_verification}
|
||||
defaultValue={true}
|
||||
>
|
||||
<Switch bind:checked={formData.require_email_verification}>
|
||||
{$t('routes.admin.config.requireVerifyEmail')}
|
||||
</Switch>
|
||||
<Switch
|
||||
bind:checked={formData.application_email_admins}
|
||||
defaultValue={true}
|
||||
>
|
||||
<Switch bind:checked={formData.application_email_admins}>
|
||||
{$t('routes.admin.config.emailAdminsOnApplication')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.reports_email_admins} defaultValue={true}>
|
||||
<Switch bind:checked={formData.reports_email_admins}>
|
||||
{$t('routes.admin.config.emailAdminsOnReport')}
|
||||
</Switch>
|
||||
<Select
|
||||
@@ -223,10 +166,10 @@
|
||||
{$t('routes.admin.config.listingType.local')}
|
||||
</Option>
|
||||
</Select>
|
||||
<Switch bind:checked={formData.private_instance} defaultValue={true}>
|
||||
<Switch bind:checked={formData.private_instance}>
|
||||
{$t('routes.admin.config.private')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.hide_modlog_mod_names} defaultValue={true}>
|
||||
<Switch bind:checked={formData.hide_modlog_mod_names}>
|
||||
{$t('routes.admin.config.hideModlogModNames')}
|
||||
</Switch>
|
||||
<TextInput
|
||||
@@ -234,13 +177,13 @@
|
||||
label={$t('routes.admin.config.slurFilter')}
|
||||
placeholder="(word1|word2)"
|
||||
/>
|
||||
<Switch bind:checked={formData.federation_enabled} defaultValue={true}>
|
||||
<Switch bind:checked={formData.federation_enabled}>
|
||||
{$t('routes.admin.config.federation')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.federation_debug} defaultValue={false}>
|
||||
<Switch bind:checked={formData.federation_debug}>
|
||||
{$t('routes.admin.config.federationDebug')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.captcha_enabled} defaultValue={false}>
|
||||
<Switch bind:checked={formData.captcha_enabled}>
|
||||
{$t('routes.admin.config.captcha.enabled')}
|
||||
</Switch>
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
@@ -22,6 +20,7 @@
|
||||
} from 'mono-svelte'
|
||||
import { Icon, Plus } from 'svelte-hero-icons'
|
||||
import type { PageData } from './$types'
|
||||
import ImageInputUpload from '$lib/components/form/ImageInputUpload.svelte'
|
||||
|
||||
interface Props {
|
||||
inline?: boolean
|
||||
@@ -37,35 +36,14 @@
|
||||
discussion_languages: data.my_user?.discussion_languages,
|
||||
})
|
||||
|
||||
let profileImage: FileList | undefined = $state()
|
||||
let bannerImage: FileList | undefined = $state()
|
||||
|
||||
async function save() {
|
||||
if (!formData || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
let pfp = profileImage
|
||||
? await uploadImage(
|
||||
profileImage[0],
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
let banner = bannerImage
|
||||
? await uploadImage(
|
||||
bannerImage[0],
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
await getClient().saveUserSettings({
|
||||
...formData,
|
||||
avatar: pfp,
|
||||
banner: banner,
|
||||
})
|
||||
|
||||
toast({
|
||||
@@ -84,9 +62,15 @@
|
||||
let loading = $state(false)
|
||||
</script>
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" onsubmit={preventDefault(save)}>
|
||||
<form
|
||||
class="flex flex-col gap-4 h-full"
|
||||
onsubmit={e => {
|
||||
e.preventDefault()
|
||||
save()
|
||||
}}
|
||||
>
|
||||
{#if !inline}
|
||||
<Header pageHeader>{$t('routes.profile.settings')}</Header>
|
||||
<Header pageHeader>{$t('routes.profile.edit')}</Header>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||
@@ -103,8 +87,14 @@
|
||||
previewButton
|
||||
/>
|
||||
<div class="flex gap-2 items-center *:flex-1">
|
||||
<ImageInput label={$t('form.profile.avatar')} bind:files={profileImage} />
|
||||
<ImageInput label={$t('form.profile.banner')} bind:files={bannerImage} />
|
||||
<ImageInputUpload
|
||||
label={$t('form.profile.avatar')}
|
||||
bind:imageUrl={formData.avatar}
|
||||
/>
|
||||
<ImageInputUpload
|
||||
label={$t('form.profile.banner')}
|
||||
bind:imageUrl={formData.banner}
|
||||
/>
|
||||
</div>
|
||||
<TextInput
|
||||
label={$t('form.profile.matrix')}
|
||||
@@ -114,18 +104,12 @@
|
||||
<Switch bind:checked={formData.show_nsfw}>
|
||||
{$t('form.profile.showNSFW')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_scores}>
|
||||
{$t('form.profile.scores')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.bot_account}>
|
||||
{$t('form.profile.bot')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_bot_accounts}>
|
||||
{$t('form.profile.showBots')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_read_posts}>
|
||||
{$t('form.profile.showRead')}
|
||||
</Switch>
|
||||
<div class="space-y-1">
|
||||
<SectionTitle id="languages">
|
||||
{$t('form.profile.languages.title')}
|
||||
|
||||
@@ -27,11 +27,10 @@
|
||||
<div class="flex flex-col gap-4 h-full z-0">
|
||||
<div class="flex flex-row justify-between">
|
||||
<Tabs
|
||||
class="overflow-auto"
|
||||
routes={[
|
||||
{
|
||||
href: '/profile',
|
||||
name: $t('routes.profile.overview'),
|
||||
name: $t('profile.profile'),
|
||||
},
|
||||
{
|
||||
href: '/profile/user',
|
||||
@@ -40,7 +39,7 @@
|
||||
|
||||
{
|
||||
href: '/profile/settings',
|
||||
name: $t('routes.profile.settings'),
|
||||
name: $t('routes.profile.edit'),
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
@@ -1,78 +1,8 @@
|
||||
<script lang="ts">
|
||||
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { communityLink } from '$lib/lemmy/generic.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
let { data } = $props()
|
||||
|
||||
let my_user = $derived(data.my_user!.local_user_view)
|
||||
</script>
|
||||
|
||||
<Header pageHeader>
|
||||
{$t('routes.profile.overview')}
|
||||
{$t('profile.profile')}
|
||||
</Header>
|
||||
|
||||
<EntityHeader
|
||||
avatar={my_user.person.avatar}
|
||||
name={my_user.person.display_name || my_user.person.name}
|
||||
banner={my_user.person.banner}
|
||||
bio={my_user.person.bio}
|
||||
stats={[
|
||||
{
|
||||
name: $t('content.posts'),
|
||||
value: my_user.counts.post_count.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('content.comments'),
|
||||
value: my_user.counts.comment_count.toString(),
|
||||
},
|
||||
{
|
||||
name: $t('stats.joined'),
|
||||
value: formatRelativeDate(publishedToDate(my_user.person.published), {
|
||||
style: 'short',
|
||||
}).toString(),
|
||||
format: false,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{#snippet nameDetail()}
|
||||
<span class="text-sm flex gap-0 items-center w-max">
|
||||
@
|
||||
<UserLink
|
||||
showInstance
|
||||
user={my_user.person}
|
||||
displayName={false}
|
||||
class="font-normal"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
{#if data.moderates && data.moderates.length > 0}
|
||||
<Expandable class="">
|
||||
{#snippet title()}
|
||||
{$t('routes.profile.moderates')}
|
||||
<hr class="flex-1 w-full border-slate-200 dark:border-zinc-800 mx-3" />
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={data.moderates.map(m => ({
|
||||
id: m.community.id,
|
||||
name: m.community.title,
|
||||
url: communityLink(m.community),
|
||||
avatar: m.community.icon,
|
||||
instance: new URL(m.community.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</EntityHeader>
|
||||
|
||||
{#if settings.debugInfo}
|
||||
<pre>
|
||||
{JSON.stringify(my_user, undefined, 4)}
|
||||
</pre>
|
||||
{/if}
|
||||
Reference in new issue
Block a user