feat: update signup page
This commit is contained in:
1 parent
a12f153dc1
commit
7f9ab04c11
19 files changed
+236
-84
No files matched your search
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.12.1",
|
"version": "1.12.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
"svelte": "^4.2.0",
|
"svelte": "^4.2.0",
|
||||||
"svelte-check": "^3.0.1",
|
"svelte-check": "^3.0.1",
|
||||||
"svelte-hero-icons": "^5.0.0",
|
"svelte-hero-icons": "^5.0.0",
|
||||||
|
"svelte-tiny-virtual-list": "^2.0.5",
|
||||||
"tailwindcss": "^3.3.2",
|
"tailwindcss": "^3.3.2",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import { Icon, XCircle } from 'svelte-hero-icons'
|
import { Icon, XCircle } from 'svelte-hero-icons'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
let type: 'community' = 'community'
|
let type: 'community' | 'instance' = 'community'
|
||||||
export let q: string = ''
|
export let q: string = ''
|
||||||
|
|
||||||
export let jwt: string | undefined = undefined
|
export let jwt: string | undefined = undefined
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
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'
|
||||||
import { ImageInput, toast } from 'mono-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 { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||||
|
import { uploadImage } from '$lib/util.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The community ID to edit.
|
* The community ID to edit.
|
||||||
@@ -39,9 +40,11 @@
|
|||||||
formData.submitting = true
|
formData.submitting = true
|
||||||
|
|
||||||
try {
|
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
|
let banner = formData.banner
|
||||||
? await uploadImage(formData.banner[0])
|
? await uploadImage(formData.banner[0], $profile.instance, $profile.jwt)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const res = edit
|
const res = edit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { uploadImage } from '$lib/util.js'
|
||||||
import { ImageInput, toast } from 'mono-svelte'
|
import { ImageInput, toast } from 'mono-svelte'
|
||||||
import { uploadImage } from '$lib/lemmy.js'
|
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
@@ -17,7 +17,11 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
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')
|
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
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 type { Community, Post, PostView } from 'lemmy-js-client'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { Check, Icon, Photo } from 'svelte-hero-icons'
|
import { Check, Icon, Photo } 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'
|
||||||
import { placeholders } from '$lib/util.js'
|
import { placeholders, uploadImage } from '$lib/util.js'
|
||||||
import { Checkbox, TextInput } from 'mono-svelte'
|
import { Checkbox, TextInput } from 'mono-svelte'
|
||||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
|
|
||||||
dispatcher('submit', post.post_view)
|
dispatcher('submit', post.post_view)
|
||||||
} else {
|
} 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
|
data.url = image || data.url || undefined
|
||||||
const post = await getClient().createPost({
|
const post = await getClient().createPost({
|
||||||
auth: $profile.jwt,
|
auth: $profile.jwt,
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
import { uploadImage } from '$lib/util.js'
|
||||||
import { ImageInput, toast } from 'mono-svelte'
|
import { ImageInput, toast } from 'mono-svelte'
|
||||||
import { uploadImage } from '$lib/lemmy.js'
|
|
||||||
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import {
|
import {
|
||||||
@@ -68,7 +68,11 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
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')
|
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
{title}
|
{title}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="aspect-square object-cover overflow-hidden {$$props.class}"
|
class="aspect-square object-cover overflow-hidden {$$props.class}"
|
||||||
|
style="width: {width}px; height: {width}px;"
|
||||||
class:rounded-full={circle}
|
class:rounded-full={circle}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<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}
|
{#if icon}
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
GlobeAlt,
|
GlobeAlt,
|
||||||
Home,
|
Home,
|
||||||
Icon,
|
Icon,
|
||||||
|
Identification,
|
||||||
|
ServerStack,
|
||||||
UserGroup,
|
UserGroup,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { profile, profileData } from '$lib/auth.js'
|
import { profile, profileData } from '$lib/auth.js'
|
||||||
@@ -80,14 +82,35 @@
|
|||||||
items={$profile.user.follows.map((i) => i.community)}
|
items={$profile.user.follows.map((i) => i.community)}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{: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
|
<Button
|
||||||
class="hover:bg-slate-200 {$userSettings.expandSidebar ? '' : '!p-1.5'}"
|
class="hover:bg-slate-200 {$userSettings.expandSidebar ? '' : '!p-1.5'}"
|
||||||
href="/accounts"
|
href="/accounts"
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
alignment="left"
|
alignment="left"
|
||||||
|
title="Change Instance"
|
||||||
>
|
>
|
||||||
<Icon mini src={ArrowLeftOnRectangle} size="20" />
|
<Icon mini src={ServerStack} size="20" />
|
||||||
<span class:hidden={!$userSettings.expandSidebar}>Log in</span>
|
<span class:hidden={!$userSettings.expandSidebar}>Change instance</span>
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
+1
-38
@@ -1,8 +1,7 @@
|
|||||||
import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
|
import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import { profile } from '$lib/auth.js'
|
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
|
import { instance } from '$lib/instance.js'
|
||||||
|
|
||||||
async function customFetch(
|
async function customFetch(
|
||||||
func: (
|
func: (
|
||||||
@@ -50,39 +49,3 @@ export async function validateInstance(instance: string): Promise<boolean> {
|
|||||||
return false
|
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/settings': 'Profile Settings',
|
||||||
'/profile/blocks': 'Blocks',
|
'/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 />
|
<Sidebar />
|
||||||
<div
|
<div
|
||||||
class="w-full min-w-0 border-t sm:border-l border-slate-200 dark:border-zinc-900
|
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
|
<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}
|
class:max-w-6xl={$userSettings.newWidth}
|
||||||
id="main"
|
id="main"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
ChevronUp,
|
ChevronUp,
|
||||||
EllipsisHorizontal,
|
EllipsisHorizontal,
|
||||||
Icon,
|
Icon,
|
||||||
|
Identification,
|
||||||
PaintBrush,
|
PaintBrush,
|
||||||
Plus,
|
Plus,
|
||||||
Trash,
|
Trash,
|
||||||
@@ -92,18 +93,25 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $profileData.profiles.length == 0}
|
{#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
|
<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">
|
<div class="flex flex-col items-center">
|
||||||
<Icon src={ArrowLeftOnRectangle} size="48" solid />
|
<Icon src={ArrowLeftOnRectangle} size="48" solid />
|
||||||
<h1 class="font-bold text-3xl">No accounts</h1>
|
<h1 class="font-bold text-3xl">No accounts</h1>
|
||||||
</div>
|
</div>
|
||||||
<Button href="/login" size="lg">
|
<div class="flex flex-row items-center gap-2">
|
||||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
<Button href="/login" size="lg">
|
||||||
Log in
|
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||||
</Button>
|
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">
|
<div class="flex flex-row font-normal gap-2">
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Guest instance"
|
label="Guest instance"
|
||||||
|
|||||||
@@ -95,15 +95,13 @@
|
|||||||
<option value="messages">Messages</option>
|
<option value="messages">Messages</option>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</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}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
<div class="mt-auto">
|
<Placeholder
|
||||||
<Placeholder
|
icon={Inbox}
|
||||||
icon={Inbox}
|
title="No new notifications"
|
||||||
title="No new notifications"
|
description="Messages, replies, and mentions will appear here."
|
||||||
description="Messages, replies, and mentions will appear here."
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{:else}
|
{:else}
|
||||||
{#each data.data as item}
|
{#each data.data as item}
|
||||||
<div in:fly={{ duration: 500, y: -6, opacity: 0 }}>
|
<div in:fly={{ duration: 500, y: -6, opacity: 0 }}>
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { ImageInput, Material, removeToast, toast } from 'mono-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 type { SaveUserSettings } from 'lemmy-js-client'
|
||||||
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
|
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
|
||||||
|
import { uploadImage } from '$lib/util.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -22,7 +23,9 @@
|
|||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
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({
|
const res = await getClient().saveUserSettings({
|
||||||
auth: $profile.jwt,
|
auth: $profile.jwt,
|
||||||
...formData,
|
...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">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
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 { DEFAULT_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { validateInstance } from '$lib/lemmy.js'
|
import { validateInstance } from '$lib/lemmy.js'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
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 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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Sign up | Choose Instance</title>
|
<title>Sign up | Choose Instance</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="mx-auto max-w-xl flex flex-col gap-4">
|
<div class="mx-auto max-w-xl flex flex-col gap-4 my-auto h-max w-full">
|
||||||
<h1 class="font-bold text-2xl">Sign Up</h1>
|
<h1 class="font-bold text-4xl">Sign Up</h1>
|
||||||
<h2 class="font-bold text-xl">Choose an instance</h2>
|
<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
|
<form
|
||||||
class="flex flex-col gap-4"
|
class="flex flex-col gap-4"
|
||||||
on:submit|preventDefault={async () => {
|
on:submit|preventDefault={async () => {
|
||||||
if (instance != '') {
|
if (selectedInstance != '') {
|
||||||
validating = true
|
validating = true
|
||||||
|
|
||||||
if (await validateInstance(instance.trim())) {
|
if (await validateInstance(selectedInstance.trim())) {
|
||||||
goto(`/signup/${instance}`)
|
goto(`/signup/${selectedInstance}`)
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
content: 'Could not contact that instance URL',
|
content: 'Could not contact that instance URL',
|
||||||
@@ -36,12 +139,12 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={instance}
|
bind:value={selectedInstance}
|
||||||
label="Instance URL"
|
label="Choose an instance"
|
||||||
required
|
required
|
||||||
placeholder={DEFAULT_INSTANCE_URL}
|
{placeholder}
|
||||||
on:input={() => {
|
on:input={() => {
|
||||||
instance = instance.toLowerCase().replaceAll(' ', '')
|
selectedInstance = selectedInstance.toLowerCase().replaceAll(' ', '')
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Whitespace-only changes.
@@ -92,7 +92,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<form
|
<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}
|
on:submit|preventDefault={submit}
|
||||||
>
|
>
|
||||||
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto">
|
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto">
|
||||||
|
|||||||
@@ -3807,6 +3807,11 @@ svelte-preprocess@^5.0.4:
|
|||||||
sorcery "^0.11.0"
|
sorcery "^0.11.0"
|
||||||
strip-indent "^3.0.0"
|
strip-indent "^3.0.0"
|
||||||
|
|
||||||
|
svelte-tiny-virtual-list@^2.0.5:
|
||||||
|
version "2.0.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/svelte-tiny-virtual-list/-/svelte-tiny-virtual-list-2.0.5.tgz#5a88b14f2041eedc060dc799a2f146ee0355073f"
|
||||||
|
integrity sha512-xg9ckb8UeeIme4/5qlwCrl2QNmUZ8SCQYZn3Ji83cUsoASqRNy3KWjpmNmzYvPDqCHSZjruBBsoB7t5hwuzw5g==
|
||||||
|
|
||||||
svelte@^4.2.0:
|
svelte@^4.2.0:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/svelte/-/svelte-4.2.0.tgz#0e4304c15524450b22fba02516eb72efbd8847b6"
|
resolved "https://registry.yarnpkg.com/svelte/-/svelte-4.2.0.tgz#0e4304c15524450b22fba02516eb72efbd8847b6"
|
||||||
|
|||||||
Reference in new issue
Block a user