diff --git a/package.json b/package.json
index 44b51c25..b5b0228d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
- "version": "1.12.1",
+ "version": "1.12.2",
"private": true,
"scripts": {
"dev": "vite dev",
@@ -30,6 +30,7 @@
"svelte": "^4.2.0",
"svelte-check": "^3.0.1",
"svelte-hero-icons": "^5.0.0",
+ "svelte-tiny-virtual-list": "^2.0.5",
"tailwindcss": "^3.3.2",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte
index e89e71ae..7d497666 100644
--- a/src/lib/components/lemmy/ObjectAutocomplete.svelte
+++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte
@@ -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
diff --git a/src/lib/components/lemmy/community/CommunityForm.svelte b/src/lib/components/lemmy/community/CommunityForm.svelte
index 3a42dfb3..c02d86c8 100644
--- a/src/lib/components/lemmy/community/CommunityForm.svelte
+++ b/src/lib/components/lemmy/community/CommunityForm.svelte
@@ -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
diff --git a/src/lib/components/lemmy/modal/ImageUploadModal.svelte b/src/lib/components/lemmy/modal/ImageUploadModal.svelte
index 80b04b68..9b88babc 100644
--- a/src/lib/components/lemmy/modal/ImageUploadModal.svelte
+++ b/src/lib/components/lemmy/modal/ImageUploadModal.svelte
@@ -1,7 +1,7 @@
{#if icon}
i.community)}
/>
{:else}
+
+
{/if}
diff --git a/src/lib/lemmy.ts b/src/lib/lemmy.ts
index 0d28943a..1126fb28 100644
--- a/src/lib/lemmy.ts
+++ b/src/lib/lemmy.ts
@@ -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
{
return false
}
}
-
-export async function uploadImage(
- image: File | null | undefined
-): Promise {
- 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}`
- )
-}
diff --git a/src/lib/util.ts b/src/lib/util.ts
index 60eab99f..76458901 100644
--- a/src/lib/util.ts
+++ b/src/lib/util.ts
@@ -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 {
+ 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}`
+ )
+}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index c6227e85..76900525 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -94,10 +94,10 @@
+
No accounts
-
+
+
+
+
Messages
-
+
{#if !data.data || (data.data?.length ?? 0) == 0}
-
+
{:else}
{#each data.data as item}
diff --git a/src/routes/profile/(local_user)/settings/+page.svelte b/src/routes/profile/(local_user)/settings/+page.svelte
index aee38e0b..767ec9da 100644
--- a/src/routes/profile/(local_user)/settings/+page.svelte
+++ b/src/routes/profile/(local_user)/settings/+page.svelte
@@ -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,
diff --git a/src/routes/signup/+page.svelte b/src/routes/signup/+page.svelte
index 974085da..20655ef5 100644
--- a/src/routes/signup/+page.svelte
+++ b/src/routes/signup/+page.svelte
@@ -1,29 +1,132 @@
+
+
Sign up | Choose Instance
-
-
Sign Up
-
Choose an instance
+
+
Sign Up
+
Choose an instance that interests you, or type the URL manually.
+
+ An instance is the server that your account will be hosted on, but you can
+ still access and interact with content from other instances.
+
+
+
+ {#if instances}
+ {#each instances as instance}
+
+ {/each}
+ {:else}
+
+
+
+ {/if}
+
+