feat: multiple guest account support
This commit is contained in:
1 parent
e90d484755
commit
c172327923
7 files changed
+192
-90
No files matched your search
@@ -293,48 +293,17 @@
|
||||
</Menu>
|
||||
</div>
|
||||
{/each}
|
||||
<div class="flex flex-row gap-4 items-center py-4">
|
||||
<span class="font-bold flex flex-col">Guest</span>
|
||||
<div class="ml-auto" />
|
||||
|
||||
<Button
|
||||
aria-label={$currentProfile?.id != -1 ? 'Switch' : 'Current'}
|
||||
on:click={async () => {
|
||||
if ($currentProfile?.id != -1) setUserID(-1)
|
||||
}}
|
||||
size="square-md"
|
||||
color={$currentProfile?.id == -1 ? 'primary' : 'secondary'}
|
||||
>
|
||||
{#if $currentProfile?.id == -1}
|
||||
<Icon src={Check} mini size="16" />
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
</EditableList>
|
||||
<div class="mt-auto" />
|
||||
<div class="flex flex-row font-normal gap-2">
|
||||
<TextInput
|
||||
on:change={changeGuestInstance}
|
||||
placeholder="Instance URL"
|
||||
label="Guest instance"
|
||||
bind:value={newInstance}
|
||||
disabled={LINKED_INSTANCE_URL != undefined}
|
||||
size="sm"
|
||||
>
|
||||
<span slot="prefix">https://</span>
|
||||
</TextInput>
|
||||
<Button
|
||||
color="primary"
|
||||
{loading}
|
||||
disabled={loading || LINKED_INSTANCE_URL != undefined}
|
||||
class="self-end"
|
||||
>
|
||||
Change
|
||||
<div class="flex items-center gap-2">
|
||||
<Button href="/login" size="lg" class="flex-1">
|
||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||
Log In
|
||||
</Button>
|
||||
<Button href="/login/guest" size="lg">
|
||||
<Icon slot="prefix" src={Plus} size="16" mini />
|
||||
Add Guest
|
||||
</Button>
|
||||
</div>
|
||||
<Button href="/login" size="lg">
|
||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||
Log In
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -10,7 +10,12 @@
|
||||
validateInstance,
|
||||
} from '$lib/lemmy.js'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
import { Icon, Identification, QuestionMarkCircle } from 'svelte-hero-icons'
|
||||
import {
|
||||
Icon,
|
||||
Identification,
|
||||
QuestionMarkCircle,
|
||||
UserCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util.js'
|
||||
import { MINIMUM_VERSION } from '$lib/version.js'
|
||||
|
||||
@@ -137,6 +142,10 @@
|
||||
<Icon src={QuestionMarkCircle} mini size="16" />
|
||||
Forgot Password
|
||||
</Button>
|
||||
<Button color="tertiary" href="/login/guest">
|
||||
<Icon src={UserCircle} mini size="16" />
|
||||
Guest
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,95 @@
|
||||
<script lang="ts">
|
||||
import { site, validateInstance } from '$lib/lemmy.js'
|
||||
import { Button, Note, TextInput, toast } from 'mono-svelte'
|
||||
import { MINIMUM_VERSION } from '$lib/version'
|
||||
import { mayBeIncompatible } from '$lib/lemmy'
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util'
|
||||
import { profile, profileData, type Profile } from '$lib/auth'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
||||
|
||||
let form = {
|
||||
instance: '',
|
||||
username: 'Guest',
|
||||
loading: false,
|
||||
}
|
||||
|
||||
async function addGuest() {
|
||||
form.loading = true
|
||||
if (!(await validateInstance(form.instance))) {
|
||||
toast({ content: 'Failed to contact that instance URL.', type: 'error' })
|
||||
form.loading = false
|
||||
return
|
||||
}
|
||||
|
||||
profileData.update((pd) => {
|
||||
// too lazy to make a decent system
|
||||
const id = Math.floor(Math.random() * 100000)
|
||||
|
||||
const newProfile: Profile = {
|
||||
id: id,
|
||||
instance: form.instance,
|
||||
username: form.username,
|
||||
}
|
||||
|
||||
profile.set({
|
||||
...newProfile,
|
||||
})
|
||||
|
||||
return {
|
||||
profile: id,
|
||||
profiles: [newProfile, ...pd.profiles],
|
||||
}
|
||||
})
|
||||
|
||||
toast({ content: 'Added that account.', type: 'success' })
|
||||
|
||||
form.loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="max-w-xl w-full mx-auto h-max my-auto">
|
||||
<form on:submit|preventDefault={addGuest} class="flex flex-col gap-5">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h1 class="font-bold text-3xl">Add Guest</h1>
|
||||
{#if $site && mayBeIncompatible(MINIMUM_VERSION, $site.version.replace('v', ''))}
|
||||
<Note>
|
||||
This version of Photon supports instances running
|
||||
<span style="font-family: monospace;">
|
||||
v{MINIMUM_VERSION}
|
||||
</span>
|
||||
or higher.
|
||||
</Note>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="inline-flex items-center gap-2">
|
||||
<TextInput
|
||||
required
|
||||
label="Name"
|
||||
bind:value={form.username}
|
||||
placeholder="Guest 2"
|
||||
minlength={1}
|
||||
class="flex-1"
|
||||
></TextInput>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
<TextInput
|
||||
required
|
||||
label="Instance URL"
|
||||
bind:value={form.instance}
|
||||
pattern={DOMAIN_REGEX_FORMS}
|
||||
placeholder="example.com"
|
||||
class="flex-1"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<Button
|
||||
submit
|
||||
class="w-full"
|
||||
color="primary"
|
||||
size="lg"
|
||||
loading={form.loading}
|
||||
disabled={form.loading}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -1,5 +1,5 @@
|
||||
<div
|
||||
class="flex flex-col divide-y divide-zinc-800 [&>*]:py-3 first:p-0 last:py-0"
|
||||
class="flex flex-col divide-y divide-slate-200 dark:divide-zinc-800 [&>*]:py-3 first:p-0 last:py-0"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
Reference in new issue
Block a user