feat: Allow changing instance URL when not logged in
This commit is contained in:
1 parent
f127b5f645
commit
fed5cc2263
11 files changed
+133
-76
No files matched your search
@@ -7,18 +7,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||
<h1 class="font-black text-3xl">{$page.status}</h1>
|
||||
<p class="mx-4 md:mx-8">
|
||||
Failed to fetch page. Most major lemmy instances are having quite a lot of
|
||||
issues right now, this might be on their end.
|
||||
</p>
|
||||
<p>
|
||||
This could be a CORS issue. The instance you're using must update to Lemmy
|
||||
1.18.1 to fix CORS.
|
||||
</p>
|
||||
<code class="bg-slate-100 dark:bg-zinc-800 px-2 py-1 rounded-md">
|
||||
{JSON.stringify($page.error)}
|
||||
</code>
|
||||
<h1 class="font-black text-5xl">{$page.status}</h1>
|
||||
<Link href={$page.url.toString()}>Retry</Link>
|
||||
<Button
|
||||
on:click={() => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import Loading from '$lib/components/ui/loader/Loading.svelte'
|
||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { authData, buildBaseUrl, getClient } from '$lib/lemmy.js'
|
||||
import { authData, buildBaseUrl, getClient, getInstance } from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
import { list } from 'postcss'
|
||||
@@ -37,7 +37,7 @@
|
||||
formData.append('images[]', image)
|
||||
|
||||
const response = await fetch(
|
||||
`${buildBaseUrl($authData.instance)}/pictrs/image?${new URLSearchParams({
|
||||
`${buildBaseUrl(getInstance())}/pictrs/image?${new URLSearchParams({
|
||||
auth: $authData.token,
|
||||
})}`,
|
||||
{
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<script>
|
||||
import Switch from '$lib/components/input/Switch.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { userSettings } from '$lib/settings'
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Experiments</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<h1 class="text-3xl font-bold">Experiments</h1>
|
||||
<Card class="flex flex-col gap-2 p-4 text-sm">
|
||||
<h1 class="text-lg font-bold">New comment design</h1>
|
||||
<span>Makes comment actions look slightly different.</span>
|
||||
<Switch bind:enabled={$userSettings.newComments} />
|
||||
</Card>
|
||||
</div>
|
||||
@@ -8,7 +8,12 @@
|
||||
addToast,
|
||||
toast,
|
||||
} from '$lib/components/ui/toasts/toasts.js'
|
||||
import { DEFAULT_INSTANCE_URL, authData, getClient } from '$lib/lemmy.js'
|
||||
import {
|
||||
DEFAULT_INSTANCE_URL,
|
||||
authData,
|
||||
getClient,
|
||||
validateInstance,
|
||||
} from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
|
||||
let data = {
|
||||
@@ -19,22 +24,10 @@
|
||||
loading: false,
|
||||
}
|
||||
|
||||
async function validateURL(instance: string): Promise<boolean> {
|
||||
if (instance == '') return false
|
||||
|
||||
try {
|
||||
await getClient(instance).getSite({})
|
||||
} catch (err) {
|
||||
throw new Error('Failed to contact that instance. Is it down?')
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async function logIn() {
|
||||
data.loading = true
|
||||
try {
|
||||
if (!(await validateURL(data.instance))) {
|
||||
if (!(await validateInstance(data.instance))) {
|
||||
throw new Error('Failed to contact that instance. Is it down?')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DEFAULT_INSTANCE_URL, authData } from '$lib/lemmy.js'
|
||||
import { instance } from '$lib/lemmy.js'
|
||||
import { error, redirect } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -6,7 +6,7 @@ export function load({ params, url }) {
|
||||
if (Number(params.instance)) {
|
||||
const split = url.pathname.split('/')
|
||||
|
||||
split.splice(2, 0, `${get(authData)?.instance ?? DEFAULT_INSTANCE_URL}`)
|
||||
split.splice(2, 0, `${get(instance)}`)
|
||||
|
||||
const newUrl = new URL(url)
|
||||
newUrl.pathname = split.join('/')
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<script lang="ts">
|
||||
import Switch from '$lib/components/input/Switch.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { authData, instance, user, validateInstance } from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
|
||||
let data = {
|
||||
newInstance: $instance,
|
||||
loading: false,
|
||||
}
|
||||
|
||||
async function changeInstance() {
|
||||
data.loading = true
|
||||
try {
|
||||
authData.set(undefined)
|
||||
user.set(undefined)
|
||||
if (typeof localStorage != 'undefined') {
|
||||
localStorage.removeItem('user')
|
||||
}
|
||||
|
||||
if (!(await validateInstance(data.newInstance))) {
|
||||
throw new Error('Failed to contact that instance URL')
|
||||
}
|
||||
|
||||
instance.set(data.newInstance)
|
||||
|
||||
$userSettings.instance = data.newInstance
|
||||
} catch (error) {
|
||||
toast({
|
||||
content: error as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
data.loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Settings</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<h1 class="text-3xl font-bold">Settings</h1>
|
||||
<Card class="flex flex-col gap-3 p-6 text-sm">
|
||||
<h1 class="font-bold">Instance</h1>
|
||||
<p>Changing this will log you out.</p>
|
||||
<div class="flex gap-2">
|
||||
<TextInput
|
||||
bind:value={data.newInstance}
|
||||
pattern={'(?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*.[A-Za-z]{2,6}'}
|
||||
class="flex-1"
|
||||
/>
|
||||
<div class="w-24">
|
||||
<Button
|
||||
color={Color.accent}
|
||||
large
|
||||
loading={data.loading}
|
||||
disabled={data.loading}
|
||||
on:click={changeInstance}
|
||||
>
|
||||
Change
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
Reference in new issue
Block a user