feat: update signup page
This commit is contained in:
1 parent
a12f153dc1
commit
7f9ab04c11
19 files changed
+236
-84
No files matched your search
@@ -7,7 +7,7 @@
|
||||
import { Icon, XCircle } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
let type: 'community' = 'community'
|
||||
let type: 'community' | 'instance' = 'community'
|
||||
export let q: string = ''
|
||||
|
||||
export let jwt: string | undefined = undefined
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
|
||||
/**
|
||||
* The community ID to edit.
|
||||
@@ -39,9 +40,11 @@
|
||||
formData.submitting = true
|
||||
|
||||
try {
|
||||
let icon = formData.icon ? await uploadImage(formData.icon[0]) : undefined
|
||||
let icon = formData.icon
|
||||
? await uploadImage(formData.icon[0], $profile.instance, $profile.jwt)
|
||||
: undefined
|
||||
let banner = formData.banner
|
||||
? await uploadImage(formData.banner[0])
|
||||
? await uploadImage(formData.banner[0], $profile.instance, $profile.jwt)
|
||||
: undefined
|
||||
|
||||
const res = edit
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/lemmy.js'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const uploaded = await uploadImage(image[0])
|
||||
const uploaded = await uploadImage(
|
||||
image[0],
|
||||
$profile.instance,
|
||||
$profile.jwt
|
||||
)
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { Check, Icon, Photo } from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { placeholders } from '$lib/util.js'
|
||||
import { placeholders, uploadImage } from '$lib/util.js'
|
||||
import { Checkbox, TextInput } from 'mono-svelte'
|
||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||
@@ -121,7 +121,7 @@
|
||||
|
||||
dispatcher('submit', post.post_view)
|
||||
} else {
|
||||
let image = data.image ? await uploadImage(data.image[0]) : undefined
|
||||
let image = data.image ? await uploadImage(data.image[0], $profile.instance, $profile.jwt) : undefined
|
||||
data.url = image || data.url || undefined
|
||||
const post = await getClient().createPost({
|
||||
auth: $profile.jwt,
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/lemmy.js'
|
||||
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import {
|
||||
@@ -68,7 +68,11 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const uploaded = await uploadImage(image[0])
|
||||
const uploaded = await uploadImage(
|
||||
image[0],
|
||||
$profile.instance,
|
||||
$profile.jwt
|
||||
)
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
{title}
|
||||
loading="lazy"
|
||||
class="aspect-square object-cover overflow-hidden {$$props.class}"
|
||||
style="width: {width}px; height: {width}px;"
|
||||
class:rounded-full={circle}
|
||||
/>
|
||||
{:else}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="text-slate-700 dark:text-zinc-300 flex flex-col justify-center items-center gap-2"
|
||||
class="text-slate-700 dark:text-zinc-300 flex flex-col justify-center items-center gap-2 {$$props.class}"
|
||||
>
|
||||
{#if icon}
|
||||
<div
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
GlobeAlt,
|
||||
Home,
|
||||
Icon,
|
||||
Identification,
|
||||
ServerStack,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile, profileData } from '$lib/auth.js'
|
||||
@@ -80,14 +82,35 @@
|
||||
items={$profile.user.follows.map((i) => i.community)}
|
||||
/>
|
||||
{:else}
|
||||
<Button
|
||||
class="hover:bg-slate-200 {$userSettings.expandSidebar ? '' : '!p-1.5'}"
|
||||
href="/login"
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
title="Log In"
|
||||
>
|
||||
<Icon mini src={ArrowLeftOnRectangle} size="20" />
|
||||
<span class:hidden={!$userSettings.expandSidebar}>Log In</span>
|
||||
</Button>
|
||||
<Button
|
||||
class="hover:bg-slate-200 {$userSettings.expandSidebar ? '' : '!p-1.5'}"
|
||||
href="/signup"
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
title="Sign Up"
|
||||
>
|
||||
<Icon mini src={Identification} size="20" />
|
||||
<span class:hidden={!$userSettings.expandSidebar}>Sign Up</span>
|
||||
</Button>
|
||||
<Button
|
||||
class="hover:bg-slate-200 {$userSettings.expandSidebar ? '' : '!p-1.5'}"
|
||||
href="/accounts"
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
title="Change Instance"
|
||||
>
|
||||
<Icon mini src={ArrowLeftOnRectangle} size="20" />
|
||||
<span class:hidden={!$userSettings.expandSidebar}>Log in</span>
|
||||
<Icon mini src={ServerStack} size="20" />
|
||||
<span class:hidden={!$userSettings.expandSidebar}>Change instance</span>
|
||||
</Button>
|
||||
{/if}
|
||||
</nav>
|
||||
+1
-38
@@ -1,8 +1,7 @@
|
||||
import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||
import { instance } from '$lib/instance.js'
|
||||
|
||||
async function customFetch(
|
||||
func: (
|
||||
@@ -50,39 +49,3 @@ export async function validateInstance(instance: string): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function uploadImage(
|
||||
image: File | null | undefined
|
||||
): Promise<string | undefined> {
|
||||
if (!image || !get(profile)?.jwt) return
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('images[]', image)
|
||||
|
||||
const response = await fetch(
|
||||
`${
|
||||
window.location.origin
|
||||
}/cors/${getInstance()}/pictrs/image?${new URLSearchParams({
|
||||
auth: get(profile)!.jwt!,
|
||||
})}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
}
|
||||
)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
if (json.msg == 'ok') {
|
||||
return `https://${get(profile)?.instance}/pictrs/image/${
|
||||
json.files?.[0]?.file
|
||||
}`
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`${
|
||||
(await response.text().catch((_) => undefined)) ??
|
||||
'Failed to upload image'
|
||||
}: ${response.status}: ${response.statusText}`
|
||||
)
|
||||
}
|
||||
@@ -130,3 +130,39 @@ export const routes = {
|
||||
'/profile/settings': 'Profile Settings',
|
||||
'/profile/blocks': 'Blocks',
|
||||
}
|
||||
|
||||
export async function uploadImage(
|
||||
image: File | null | undefined,
|
||||
instance: string,
|
||||
jwt: string
|
||||
): Promise<string | undefined> {
|
||||
if (!image || jwt) return
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('images[]', image)
|
||||
|
||||
const response = await fetch(
|
||||
`${
|
||||
window.location.origin
|
||||
}/cors/${instance}/pictrs/image?${new URLSearchParams({
|
||||
auth: jwt,
|
||||
})}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
}
|
||||
)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
if (json.msg == 'ok') {
|
||||
return `https://${instance}/pictrs/image/${json.files?.[0]?.file}`
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`${
|
||||
(await response.text().catch((_) => undefined)) ??
|
||||
'Failed to upload image'
|
||||
}: ${response.status}: ${response.statusText}`
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user