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}`
|
||||
)
|
||||
}
|
||||
@@ -94,10 +94,10 @@
|
||||
<Sidebar />
|
||||
<div
|
||||
class="w-full min-w-0 border-t sm:border-l border-slate-200 dark:border-zinc-900
|
||||
sm:rounded-xl bg-slate-25 dark:bg-zinc-950"
|
||||
sm:rounded-xl bg-slate-25 dark:bg-zinc-950 min-h-full"
|
||||
>
|
||||
<main
|
||||
class="p-3 sm:p-6 min-w-0 w-full flex-[3] sm:rounded-tl-lg mx-auto
|
||||
class="p-3 sm:p-6 min-w-0 w-full flex-[3] sm:rounded-tl-lg mx-auto flex flex-col min-h-full
|
||||
"
|
||||
class:max-w-6xl={$userSettings.newWidth}
|
||||
id="main"
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
ChevronUp,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
Identification,
|
||||
PaintBrush,
|
||||
Plus,
|
||||
Trash,
|
||||
@@ -92,18 +93,25 @@
|
||||
{/if}
|
||||
|
||||
{#if $profileData.profiles.length == 0}
|
||||
<div class="h-full flex items-center justify-center">
|
||||
<div class="h-max flex items-center justify-center my-auto">
|
||||
<div
|
||||
class="text-slate-600 dark:text-zinc-400 flex flex-col justify-center items-center py-8 gap-4"
|
||||
class="flex flex-col justify-center items-center py-8 gap-4
|
||||
my-auto"
|
||||
>
|
||||
<div class="flex flex-col items-center">
|
||||
<Icon src={ArrowLeftOnRectangle} size="48" solid />
|
||||
<h1 class="font-bold text-3xl">No accounts</h1>
|
||||
</div>
|
||||
<Button href="/login" size="lg">
|
||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||
Log in
|
||||
</Button>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<Button href="/login" size="lg">
|
||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||
Log in
|
||||
</Button>
|
||||
<Button href="/signup" size="lg">
|
||||
<Icon slot="prefix" src={Identification} size="16" mini />
|
||||
Sign up
|
||||
</Button>
|
||||
</div>
|
||||
<div class="flex flex-row font-normal gap-2">
|
||||
<TextInput
|
||||
label="Guest instance"
|
||||
|
||||
@@ -95,15 +95,13 @@
|
||||
<option value="messages">Messages</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="flex flex-col gap-4 list-none my-4 flex-1">
|
||||
<div class="flex flex-col gap-4 list-none my-4 flex-1 h-full">
|
||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||
<div class="mt-auto">
|
||||
<Placeholder
|
||||
icon={Inbox}
|
||||
title="No new notifications"
|
||||
description="Messages, replies, and mentions will appear here."
|
||||
/>
|
||||
</div>
|
||||
<Placeholder
|
||||
icon={Inbox}
|
||||
title="No new notifications"
|
||||
description="Messages, replies, and mentions will appear here."
|
||||
/>
|
||||
{:else}
|
||||
{#each data.data as item}
|
||||
<div in:fly={{ duration: 500, y: -6, opacity: 0 }}>
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
||||
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { SaveUserSettings } from 'lemmy-js-client'
|
||||
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -22,7 +23,9 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
let pfp = profileImage ? await uploadImage(profileImage[0]) : undefined
|
||||
let pfp = profileImage
|
||||
? await uploadImage(profileImage[0], $profile.instance, $profile.jwt)
|
||||
: undefined
|
||||
const res = await getClient().saveUserSettings({
|
||||
auth: $profile.jwt,
|
||||
...formData,
|
||||
|
||||
+115
-12
@@ -1,29 +1,132 @@
|
||||
<script context="module" lang="ts">
|
||||
export interface Instance {
|
||||
baseurl: string
|
||||
name: string
|
||||
desc: string
|
||||
fed: boolean
|
||||
downvotes: boolean
|
||||
icon: string
|
||||
banner: string
|
||||
langs?: string[]
|
||||
tags?: string[]
|
||||
score: number
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { Badge, Material, Spinner, toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { validateInstance } from '$lib/lemmy.js'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
|
||||
let instance: string = ''
|
||||
let selectedInstance: string = ''
|
||||
let validating: boolean = false
|
||||
let placeholder = DEFAULT_INSTANCE_URL
|
||||
|
||||
let instances: Instance[] | undefined = undefined
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const res: Instance[] = (
|
||||
await fetch(`https://data.lemmyverse.net/data/instance.full.json`).then(
|
||||
(r) => r.json()
|
||||
)
|
||||
)
|
||||
.filter((i: Instance) => i.fed)
|
||||
.sort((a: Instance, b: Instance) => b.score - a.score)
|
||||
.slice(0, 100)
|
||||
|
||||
instances = res
|
||||
|
||||
let placeholderIndex = 0
|
||||
setInterval(() => {
|
||||
if (!instances) return
|
||||
if (placeholderIndex >= instances.length) placeholderIndex = 0
|
||||
placeholder = instances?.[placeholderIndex].baseurl
|
||||
placeholderIndex++
|
||||
}, 2000)
|
||||
|
||||
// instances = [
|
||||
// {
|
||||
// banner: '',
|
||||
// baseurl: 'fart.net',
|
||||
// desc: 'a instance',
|
||||
// downvotes: false,
|
||||
// fed: true,
|
||||
// icon: '',
|
||||
// langs: [''],
|
||||
// name: 'fart',
|
||||
// tags: ['okay'],
|
||||
// },
|
||||
// ]
|
||||
} catch (e) {
|
||||
toast({
|
||||
content: 'Failed to fetch available instances.',
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
let heights: number[] = []
|
||||
|
||||
const addHeight = (node: HTMLButtonElement, index: number) => {
|
||||
heights.splice(index, 0, node.clientHeight)
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Sign up | Choose Instance</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="mx-auto max-w-xl flex flex-col gap-4">
|
||||
<h1 class="font-bold text-2xl">Sign Up</h1>
|
||||
<h2 class="font-bold text-xl">Choose an instance</h2>
|
||||
<div class="mx-auto max-w-xl flex flex-col gap-4 my-auto h-max w-full">
|
||||
<h1 class="font-bold text-4xl">Sign Up</h1>
|
||||
<p>Choose an instance that interests you, or type the URL manually.</p>
|
||||
<p>
|
||||
An instance is the server that your account will be hosted on, but you can
|
||||
still access and interact with content from other instances.
|
||||
</p>
|
||||
<Material color="distinct" class="h-64 overflow-auto">
|
||||
<div
|
||||
class="flex flex-col h-full divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if instances}
|
||||
{#each instances as instance}
|
||||
<button
|
||||
on:click={() => (selectedInstance = instance.baseurl ?? '')}
|
||||
class="flex flex-row gap-2 text-left py-2 first:pt-0 last:pb-0 items-center"
|
||||
>
|
||||
<Avatar
|
||||
width={32}
|
||||
url={instance.icon}
|
||||
alt={instance.name}
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="font-medium text-base">
|
||||
{instance.name}
|
||||
</span>
|
||||
<span>{instance.desc}</span>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="mx-auto my-auto self-center justify-self-center">
|
||||
<Spinner width={32} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Material>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
on:submit|preventDefault={async () => {
|
||||
if (instance != '') {
|
||||
if (selectedInstance != '') {
|
||||
validating = true
|
||||
|
||||
if (await validateInstance(instance.trim())) {
|
||||
goto(`/signup/${instance}`)
|
||||
if (await validateInstance(selectedInstance.trim())) {
|
||||
goto(`/signup/${selectedInstance}`)
|
||||
} else {
|
||||
toast({
|
||||
content: 'Could not contact that instance URL',
|
||||
@@ -36,12 +139,12 @@
|
||||
}}
|
||||
>
|
||||
<TextInput
|
||||
bind:value={instance}
|
||||
label="Instance URL"
|
||||
bind:value={selectedInstance}
|
||||
label="Choose an instance"
|
||||
required
|
||||
placeholder={DEFAULT_INSTANCE_URL}
|
||||
{placeholder}
|
||||
on:input={() => {
|
||||
instance = instance.toLowerCase().replaceAll(' ', '')
|
||||
selectedInstance = selectedInstance.toLowerCase().replaceAll(' ', '')
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
|
||||
Whitespace-only changes.
@@ -92,7 +92,7 @@
|
||||
</svelte:head>
|
||||
|
||||
<form
|
||||
class="flex flex-col gap-4 max-w-2xl mx-auto h-full"
|
||||
class="flex flex-col gap-4 max-w-2xl mx-auto h-full w-full"
|
||||
on:submit|preventDefault={submit}
|
||||
>
|
||||
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto">
|
||||
|
||||
Reference in new issue
Block a user