feat: use state based auth instead of store based (#488)
* misc: switch to state for auth * fix: class based auth not working
This commit is contained in:
1 parent
8c6ff77fac
commit
5651ad475d
83 files changed
+395
-469
No files matched your search
@@ -52,7 +52,7 @@
|
||||
|
||||
{#if debugging}
|
||||
<DebugObject
|
||||
object={debugProfile?.id == $profile?.id ? $profile : debugProfile}
|
||||
object={debugProfile?.id == profile.data?.id ? profile : debugProfile}
|
||||
bind:open={debugging}
|
||||
>
|
||||
{#snippet title()}
|
||||
@@ -101,7 +101,7 @@
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
{#if $profileData.profiles.length == 0}
|
||||
{#if profileData.profiles.length == 0}
|
||||
<div class="h-max flex items-center justify-center my-auto">
|
||||
<div
|
||||
class="flex flex-col justify-center items-center py-8 gap-4
|
||||
@@ -158,29 +158,28 @@
|
||||
{/snippet}
|
||||
</Header>
|
||||
<div>
|
||||
{#each $profileData.profiles as profile, index (profile.id)}
|
||||
{#each profileData.profiles as profile, index}
|
||||
<div
|
||||
class="flex flex-row gap-2 items-center py-3"
|
||||
transition:fly={{ duration: 500, y: -12, easing: expoOut }}
|
||||
animate:flip={{ duration: 500, easing: expoOut }}
|
||||
>
|
||||
<Button
|
||||
title={profile.id == $currentProfile?.id ? 'Switch' : 'Current'}
|
||||
title={profile.id == currentProfile?.data.id ? 'Switch' : 'Current'}
|
||||
onclick={async () => {
|
||||
if (profile.id != $currentProfile?.id) {
|
||||
if (profile.id != currentProfile?.data.id) {
|
||||
switching = profile.id
|
||||
await setUserID(profile.id)
|
||||
switching = -69
|
||||
}
|
||||
}}
|
||||
size="square-md"
|
||||
color={profile.id == $currentProfile?.id ? 'primary' : 'ghost'}
|
||||
color={profile.id == currentProfile?.data.id ? 'primary' : 'ghost'}
|
||||
loading={switching == profile.id}
|
||||
disabled={switching == profile.id}
|
||||
rounding="pill"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
{#if profile.id == $currentProfile?.id}
|
||||
{#if profile.id == currentProfile?.data.id}
|
||||
<Icon src={Check} mini size="16" />
|
||||
{:else}
|
||||
<Icon src={ArrowsRightLeft} size="16" mini />
|
||||
@@ -191,7 +190,7 @@
|
||||
<ProfileAvatar
|
||||
{profile}
|
||||
{index}
|
||||
selected={$currentProfile?.id == profile.id}
|
||||
selected={currentProfile?.data.id == profile.id}
|
||||
size={24}
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
|
||||
@@ -4,8 +4,8 @@ import { getClient } from '$lib/lemmy.js'
|
||||
import { site as siteStore } from '$lib/lemmy'
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!get(profile)) return
|
||||
let { jwt } = get(profile)!
|
||||
if (!profile) return
|
||||
let { jwt } = profile!
|
||||
let site = get(siteStore)
|
||||
|
||||
if (!site) {
|
||||
|
||||
@@ -3,9 +3,9 @@ import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ data, fetch, url }) {
|
||||
if (!get(profile)) return
|
||||
if (!profile) return
|
||||
|
||||
const { jwt } = get(profile)!
|
||||
const { jwt } = profile.data!
|
||||
if (!jwt) return
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
let reviewing = $state(false)
|
||||
|
||||
async function review(approve: boolean) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
let registrationApplicationAnswer: ApproveRegistrationApplication = {
|
||||
approve: approve,
|
||||
@@ -61,7 +61,7 @@
|
||||
type: 'success',
|
||||
})
|
||||
application.creator_local_user.accepted_application = approve
|
||||
application.admin = $profile.user!.local_user_view.person
|
||||
application.admin = profile.data.user!.local_user_view.person
|
||||
application.registration_application.deny_reason = denyReason
|
||||
|
||||
$notifications.applications -= 1
|
||||
|
||||
@@ -38,10 +38,10 @@
|
||||
)
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
saving = true
|
||||
const { jwt } = $profile
|
||||
const { jwt } = profile.data
|
||||
|
||||
try {
|
||||
await getClient().editSite({
|
||||
@@ -242,8 +242,8 @@
|
||||
</Switch>
|
||||
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.languages.description')}</p>
|
||||
<SectionTitle>{$t('form.profile.data.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.data.languages.description')}</p>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if $site && formData.discussion_languages}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
if (instance == '') return
|
||||
await trycatch(async () => {
|
||||
if (
|
||||
!$profile?.jwt ||
|
||||
!profile.data?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked ||
|
||||
!data.federated_instances?.federated_instances?.allowed
|
||||
)
|
||||
@@ -87,7 +87,7 @@
|
||||
const save = async () => {
|
||||
const res = await trycatch(async () => {
|
||||
if (
|
||||
!$profile?.jwt ||
|
||||
!profile.data?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked
|
||||
)
|
||||
return
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
let saving = $state(false)
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
action: () => removeAdmin(id, true),
|
||||
})
|
||||
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
const result = await trycatch(() =>
|
||||
getClient().addAdmin({
|
||||
@@ -75,10 +75,14 @@
|
||||
class="flex flex-row items-center gap-2 mt-auto w-full"
|
||||
onsubmit={preventDefault(() => {
|
||||
trycatch(async () => {
|
||||
if (!$profile?.jwt || newAdmin == '') return
|
||||
if (!profile.data?.jwt || newAdmin == '') return
|
||||
adding = true
|
||||
|
||||
const r = await addAdmin(`${newAdmin}@${$instance}`, true, $profile.jwt)
|
||||
const r = await addAdmin(
|
||||
`${newAdmin}@${$instance}`,
|
||||
true,
|
||||
profile.data.jwt,
|
||||
)
|
||||
if (!r) return
|
||||
|
||||
toast({
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
})
|
||||
|
||||
async function addModerator() {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
formData.addingModerator = true
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
}
|
||||
|
||||
async function removeMod(id: number) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export function load({ params }) {
|
||||
// If you somehow got to /comment/instance, it likely means you passed in an ID, not an instance.
|
||||
redirect(302, `/comment/${getInstance()}/${params.instance}`)
|
||||
redirect(302, `/comment/${profile.data.instance}/${params.instance}`)
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
id: number | undefined = community?.community.id,
|
||||
subscribed: SubscribedType | undefined = community?.subscribed,
|
||||
) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
if (!id || !subscribed) return
|
||||
|
||||
subscribing = true
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
} = $props()
|
||||
|
||||
onMount(() => {
|
||||
if (!$profile?.jwt) {
|
||||
if (!profile.data?.jwt) {
|
||||
goto('/login')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
let markingAsRead = $state(false)
|
||||
|
||||
async function markAllAsRead() {
|
||||
if (!$profile?.user) {
|
||||
if (!profile.data?.user) {
|
||||
goto('/login')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { get } from 'svelte/store'
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const auth = get(profile)
|
||||
const auth = profile
|
||||
if (!auth?.jwt) return
|
||||
|
||||
const type: InboxFeedType =
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function markAsRead(isRead: boolean) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
}
|
||||
|
||||
item.read = isRead
|
||||
if ($profile.user) $notifications.inbox += isRead ? -1 : 1
|
||||
if (profile.data.user) $notifications.inbox += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
{:then data}
|
||||
{@const conversations = data.private_messages}
|
||||
{@const previews = conversationPreviews(conversations).filter(
|
||||
(c) => c.user.id != $profile?.user?.local_user_view.person.id,
|
||||
(c) => c.user.id != profile.data?.user?.local_user_view.person.id,
|
||||
)}
|
||||
|
||||
<ul
|
||||
|
||||
@@ -51,9 +51,6 @@
|
||||
|
||||
try {
|
||||
data.instance = data.instance.trim()
|
||||
// if (!(await validateInstance(data.instance))) {
|
||||
// throw new Error('Failed to contact that instance. Is it down?')
|
||||
// }
|
||||
|
||||
const response = await getClient(data.instance).login({
|
||||
username_or_email: data.username.trim(),
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
let form = $state({
|
||||
instance: '',
|
||||
username: `${$t('account.guest')} ${$profileData.profiles.filter((p) => p.jwt == undefined).length + 1}`,
|
||||
username: `${$t('account.guest')} ${profileData.profiles.filter((p) => p.jwt == undefined).length + 1}`,
|
||||
loading: false,
|
||||
})
|
||||
|
||||
@@ -33,21 +33,13 @@
|
||||
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,
|
||||
}
|
||||
|
||||
return {
|
||||
profile: id,
|
||||
profiles: [...pd.profiles, newProfile],
|
||||
}
|
||||
const id = Math.max(...profileData.profiles.map((i) => i.id)) + 1
|
||||
profileData.profiles.push({
|
||||
id: id,
|
||||
instance: form.instance,
|
||||
username: form.username,
|
||||
})
|
||||
profileData.profile = id
|
||||
|
||||
toast({ content: $t('toast.addAccount'), type: 'success' })
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function load({ url, fetch }) {
|
||||
const filter: ReportFilter =
|
||||
(url.searchParams.get('filter') as ReportFilter) || 'all'
|
||||
|
||||
const jwt = get(profile)?.jwt
|
||||
const jwt = profile.data?.jwt
|
||||
|
||||
if (!jwt) return { type: type, page: page }
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function load({ url, fetch }) {
|
||||
unresolved_only: type == 'unread',
|
||||
}
|
||||
|
||||
const admin = get(profile)?.user ? isAdmin(get(profile)!.user!) : false
|
||||
const admin = profile.data?.user ? isAdmin(profile!.user!) : false
|
||||
|
||||
const [posts, comments, messages] = await Promise.all([
|
||||
client.listPostReports({
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
let resolving = $state(false)
|
||||
async function resolve() {
|
||||
if (!$profile?.jwt || !$profile.user) return
|
||||
if (!profile.data?.jwt || !profile.data.user) return
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
<ObjectAutocomplete
|
||||
type="instance"
|
||||
placeholder="Filter by instance"
|
||||
jwt={$profile?.jwt}
|
||||
jwt={profile.data?.jwt}
|
||||
showWhenEmpty={true}
|
||||
label="Instance"
|
||||
class="flex-1"
|
||||
@@ -109,7 +109,7 @@
|
||||
/>
|
||||
<ObjectAutocomplete
|
||||
placeholder="Filter by community"
|
||||
jwt={$profile?.jwt}
|
||||
jwt={profile.data?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
label="Community"
|
||||
@@ -121,7 +121,7 @@
|
||||
<UserAutocomplete
|
||||
instance={page.url.searchParams.get('instance') || undefined}
|
||||
placeholder="Filter by user"
|
||||
jwt={$profile?.jwt}
|
||||
jwt={profile.data?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
@@ -132,10 +132,10 @@
|
||||
onselect={(e) =>
|
||||
searchParam(page.url, 'user', e?.id.toString() ?? '', 'page')}
|
||||
/>
|
||||
{#if $profile?.user && isAdmin($profile?.user)}
|
||||
{#if profile.data?.user && isAdmin(profile.data?.user)}
|
||||
<UserAutocomplete
|
||||
placeholder="Filter by moderator"
|
||||
jwt={$profile?.jwt}
|
||||
jwt={profile.data?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
|
||||
@@ -73,13 +73,13 @@
|
||||
{/if}
|
||||
<TextInput
|
||||
bind:value={password}
|
||||
label={$t('form.profile.newPassword')}
|
||||
label={$t('form.profile.data.newPassword')}
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={password_verify}
|
||||
label={$t('form.profile.verifyNewPassword')}
|
||||
label={$t('form.profile.data.verifyNewPassword')}
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { instance } from '$lib/instance.js'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { error, redirect } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -7,7 +6,7 @@ export function load({ params, url }) {
|
||||
if (Number(params.instance)) {
|
||||
const split = url.pathname.split('/')
|
||||
|
||||
split.splice(2, 0, `${getInstance()?.toLowerCase()}`)
|
||||
split.splice(2, 0, `${profile.data.instance?.toLowerCase()}`)
|
||||
|
||||
const newUrl = new URL(url)
|
||||
newUrl.pathname = split.join('/')
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
onMount(async () => {
|
||||
if (
|
||||
!(data.post.post_view.read && settings.markPostsAsRead) &&
|
||||
$profile?.jwt
|
||||
profile.data?.jwt
|
||||
) {
|
||||
getClient().markPostAsRead({
|
||||
read: settings.markPostsAsRead,
|
||||
@@ -237,12 +237,12 @@
|
||||
<span class="text-primary-900 dark:text-primary-100 font-bold">
|
||||
{$t('routes.post.remoteView')}
|
||||
</span>
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<Button
|
||||
class="ml-auto"
|
||||
onclick={() => {
|
||||
if ($profile?.jwt) {
|
||||
fetchOnHome($profile?.jwt)
|
||||
if (profile.data?.jwt) {
|
||||
fetchOnHome(profile.data?.jwt)
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
{#if !commenting}
|
||||
<EndPlaceholder class="">
|
||||
<Button color="primary" onclick={() => (commenting = true)}>
|
||||
@@ -89,8 +89,8 @@
|
||||
}}
|
||||
locked={(post.post_view.post.locked &&
|
||||
!(
|
||||
$profile?.user?.local_user_view.local_user.admin ||
|
||||
$profile?.user?.moderates
|
||||
profile.data?.user?.local_user_view.local_user.admin ||
|
||||
profile.data?.user?.moderates
|
||||
.map((c) => c.community.id)
|
||||
.includes(post.community_view.community.id)
|
||||
)) ||
|
||||
@@ -106,7 +106,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if commenting || !$profile.jwt}
|
||||
{#if commenting || !profile.data.jwt}
|
||||
<div class="gap-2 flex items-center">
|
||||
<Select size="md" bind:value={sort} onchange={onupdate}>
|
||||
<Option icon={Fire} value="Hot">{$t('filter.sort.hot')}</Option>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
let data = $state(pageData)
|
||||
|
||||
async function unblockUser(item: PersonBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
data.person_blocks.splice(
|
||||
data.person_blocks.findIndex((i) => i.target.id == item.target.id),
|
||||
@@ -51,7 +51,7 @@
|
||||
}
|
||||
|
||||
async function unblockCommunity(item: CommunityBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
data.community_blocks.splice(
|
||||
data.community_blocks.findIndex(
|
||||
@@ -70,7 +70,7 @@
|
||||
}
|
||||
|
||||
async function unblockInstances(item: InstanceBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
if (!data.my_user?.instance_blocks) return
|
||||
|
||||
data.my_user.instance_blocks.splice(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
url: '/profile/password',
|
||||
},
|
||||
{
|
||||
name: $t('form.profile.2fa.2fa'),
|
||||
name: $t('form.profile.data.2fa.2fa'),
|
||||
url: '/profile/password/2fa',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
>
|
||||
<Icon src={Key} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">{$t('form.profile.2fa.2fa')}</span>
|
||||
<span class="font-medium text-lg">{$t('form.profile.data.2fa.2fa')}</span>
|
||||
<span class="text-sm">
|
||||
{data.my_user?.local_user_view.local_user.totp_2fa_enabled
|
||||
? $t('common.enabled')
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
disabled
|
||||
type="password"
|
||||
value={totpLink}
|
||||
label={$t('form.profile.2fa.totp')}
|
||||
label={$t('form.profile.data.2fa.totp')}
|
||||
>
|
||||
{#snippet suffix()}
|
||||
<button
|
||||
@@ -73,7 +73,7 @@
|
||||
</button>
|
||||
{/snippet}
|
||||
<span class="font-normal text-xs">
|
||||
{$t('form.profile.2fa.paste')}
|
||||
{$t('form.profile.data.2fa.paste')}
|
||||
</span>
|
||||
</TextInput>
|
||||
{/if}
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
old_password: oldPassword,
|
||||
})
|
||||
if (res?.jwt) {
|
||||
const { instance, username } = $profile
|
||||
deleteProfile($profile.id)
|
||||
const { instance, username } = profile.data
|
||||
deleteProfile(profile.data.id)
|
||||
await setUser(res.jwt, instance, username!)
|
||||
$currentInstance = instance
|
||||
|
||||
@@ -47,21 +47,21 @@
|
||||
<form onsubmit={preventDefault(changePassword)} class="flex flex-col gap-4">
|
||||
<TextInput
|
||||
bind:value={oldPassword}
|
||||
label={$t('form.profile.currentPassword')}
|
||||
label={$t('form.profile.data.currentPassword')}
|
||||
type="password"
|
||||
minlength={10}
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={newPassword}
|
||||
label={$t('form.profile.newPassword')}
|
||||
label={$t('form.profile.data.newPassword')}
|
||||
type="password"
|
||||
minlength={10}
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={newPasswordVerify}
|
||||
label={$t('form.profile.verifyNewPassword')}
|
||||
label={$t('form.profile.data.verifyNewPassword')}
|
||||
type="password"
|
||||
minlength={10}
|
||||
required
|
||||
|
||||
@@ -70,14 +70,9 @@
|
||||
delete_content: deletion.deleteContent,
|
||||
})
|
||||
|
||||
profileData.update((pd) => {
|
||||
pd.profiles.splice(
|
||||
pd.profiles.findIndex((p) => pd.profile == p.id),
|
||||
1,
|
||||
)
|
||||
|
||||
return pd
|
||||
})
|
||||
profileData.profiles.splice(
|
||||
profileData.profiles.findIndex((p) => profileData.profile == p.id),
|
||||
)
|
||||
|
||||
setUserID(-1)
|
||||
toast({
|
||||
@@ -102,7 +97,7 @@
|
||||
onaction={() => deleteAccount(4)}
|
||||
>
|
||||
{#snippet customTitle()}
|
||||
<span>{$t('form.profile.deleteAccount.label')}</span>
|
||||
<span>{$t('form.profile.data.deleteAccount.label')}</span>
|
||||
{/snippet}
|
||||
<TextInput
|
||||
label={$t('form.password')}
|
||||
@@ -110,10 +105,10 @@
|
||||
bind:value={deletion.password}
|
||||
/>
|
||||
<Checkbox bind:checked={deletion.deleteContent}>
|
||||
{$t('form.profile.deleteAccount.deleteContent')}
|
||||
{$t('form.profile.data.deleteAccount.deleteContent')}
|
||||
{#snippet description()}
|
||||
<span>
|
||||
{$t('form.profile.deleteAccount.warning')}
|
||||
{$t('form.profile.data.deleteAccount.warning')}
|
||||
</span>
|
||||
{/snippet}
|
||||
</Checkbox>
|
||||
@@ -133,10 +128,10 @@
|
||||
{$t('routes.profile.delete.warning')}
|
||||
</p>
|
||||
<Switch bind:checked={deletion.deleteContent}>
|
||||
{$t('form.profile.deleteAccount.deleteContent')}
|
||||
{$t('form.profile.data.deleteAccount.deleteContent')}
|
||||
{#snippet description()}
|
||||
<span>
|
||||
{$t('form.profile.deleteAccount.warning')}
|
||||
{$t('form.profile.data.deleteAccount.warning')}
|
||||
</span>
|
||||
{/snippet}
|
||||
</Switch>
|
||||
|
||||
@@ -40,17 +40,25 @@
|
||||
let bannerImage: FileList | undefined = $state()
|
||||
|
||||
async function save() {
|
||||
if (!formData || !$profile?.jwt) return
|
||||
if (!formData || !profile.data?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
let pfp = profileImage
|
||||
? await uploadImage(profileImage[0], $profile.instance, $profile.jwt)
|
||||
? await uploadImage(
|
||||
profileImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
let banner = bannerImage
|
||||
? await uploadImage(bannerImage[0], $profile.instance, $profile.jwt)
|
||||
? await uploadImage(
|
||||
bannerImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
const res = await getClient().saveUserSettings({
|
||||
@@ -81,45 +89,54 @@
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||
<TextInput label={$t('form.profile.email')} bind:value={formData.email} />
|
||||
<TextInput
|
||||
label={$t('form.profile.displayName')}
|
||||
label={$t('form.profile.data.email')}
|
||||
bind:value={formData.email}
|
||||
/>
|
||||
<TextInput
|
||||
label={$t('form.profile.data.displayName')}
|
||||
bind:value={formData.display_name}
|
||||
placeholder="Optional"
|
||||
/>
|
||||
<MarkdownEditor
|
||||
images={false}
|
||||
bind:value={() => formData.bio ?? '', (v) => (formData.bio = v)}
|
||||
label={$t('form.profile.bio')}
|
||||
label={$t('form.profile.data.bio')}
|
||||
previewButton
|
||||
/>
|
||||
<div class="flex gap-2 items-center *:flex-1">
|
||||
<ImageInput label={$t('form.profile.avatar')} bind:files={profileImage} />
|
||||
<ImageInput label={$t('form.profile.banner')} bind:files={bannerImage} />
|
||||
<ImageInput
|
||||
label={$t('form.profile.data.avatar')}
|
||||
bind:files={profileImage}
|
||||
/>
|
||||
<ImageInput
|
||||
label={$t('form.profile.data.banner')}
|
||||
bind:files={bannerImage}
|
||||
/>
|
||||
</div>
|
||||
<TextInput
|
||||
label={$t('form.profile.matrix')}
|
||||
label={$t('form.profile.data.matrix')}
|
||||
bind:value={formData.matrix_user_id}
|
||||
placeholder="@user:example.com"
|
||||
/>
|
||||
<Switch bind:checked={formData.show_nsfw}>
|
||||
{$t('form.profile.showNSFW')}
|
||||
{$t('form.profile.data.showNSFW')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_scores}>
|
||||
{$t('form.profile.scores')}
|
||||
{$t('form.profile.data.scores')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.bot_account}>
|
||||
{$t('form.profile.bot')}
|
||||
{$t('form.profile.data.bot')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_bot_accounts}>
|
||||
{$t('form.profile.showBots')}
|
||||
{$t('form.profile.data.showBots')}
|
||||
</Switch>
|
||||
<Switch bind:checked={formData.show_read_posts}>
|
||||
{$t('form.profile.showRead')}
|
||||
{$t('form.profile.data.showRead')}
|
||||
</Switch>
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.languages.description')}</p>
|
||||
<SectionTitle>{$t('form.profile.data.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.data.languages.description')}</p>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if $site && formData.discussion_languages}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
|
||||
@@ -9,8 +9,8 @@ export let ssr = false
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const my_user =
|
||||
// get(profile)?.user ??
|
||||
(await client({ auth: get(profile)?.jwt, func: fetch }).getSite()).my_user
|
||||
// profile.data?.user ??
|
||||
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
||||
|
||||
return {
|
||||
my_user: my_user,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { error } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = get(profile)
|
||||
const { jwt } = profile.data
|
||||
|
||||
let page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function deleteImage(image: LocalImage) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
|
||||
try {
|
||||
loading = true
|
||||
|
||||
@@ -18,7 +18,7 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!get(profile)) return { posts: [], page: 0 }
|
||||
if (!profile) return { posts: [], page: 0 }
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<div transition:slide={{ axis: 'y', easing: expoOut }} class="max-w-sm">
|
||||
<ObjectAutocomplete
|
||||
label={$t('nav.create.community')}
|
||||
jwt={$profile?.jwt}
|
||||
jwt={profile.data?.jwt}
|
||||
listing_type={'All'}
|
||||
showWhenEmpty={true}
|
||||
onselect={(c) =>
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function load({ url, fetch }) {
|
||||
query: query,
|
||||
results: everything,
|
||||
streamed: {
|
||||
object: get(profile)?.jwt
|
||||
object: profile.data?.jwt
|
||||
? getClient(undefined, fetch).resolveObject({
|
||||
q: query,
|
||||
})
|
||||
|
||||
@@ -197,7 +197,7 @@
|
||||
class="flex flex-col *:py-2 divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
style="scroll-behavior: smooth;"
|
||||
>
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<Section open={false} id="account" title={$t('settings.account.title')}>
|
||||
<div>
|
||||
<Button
|
||||
|
||||
@@ -201,7 +201,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<Checkbox bind:checked={nsfw}>{$t('form.profile.showNSFW')}</Checkbox>
|
||||
<Checkbox bind:checked={nsfw}>{$t('form.profile.data.showNSFW')}</Checkbox>
|
||||
<input type="dn" name="honeypot" bind:value={honeypot} class="hidden" />
|
||||
<Button
|
||||
submit
|
||||
|
||||
@@ -51,11 +51,12 @@
|
||||
let blocking = false
|
||||
|
||||
async function blockUser(block: number) {
|
||||
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
||||
if (!profile.data?.user || !profile.data?.jwt)
|
||||
throw new Error('Unauthenticated')
|
||||
|
||||
blocking = true
|
||||
try {
|
||||
const blocked = isBlocked($profile.user, block)
|
||||
const blocked = isBlocked(profile.data.user, block)
|
||||
|
||||
await getClient().blockPerson({
|
||||
block: !blocked,
|
||||
@@ -63,10 +64,10 @@
|
||||
})
|
||||
|
||||
if (blocked) {
|
||||
const index = $profile.user.person_blocks
|
||||
const index = profile.data.user.person_blocks
|
||||
.map((p) => p.target.id)
|
||||
.indexOf(block)
|
||||
$profile.user.person_blocks.splice(index, 1)
|
||||
profile.data.user.person_blocks.splice(index, 1)
|
||||
}
|
||||
|
||||
toast({
|
||||
@@ -209,7 +210,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
{#snippet actions()}
|
||||
{#if $profile?.user && $profile.jwt && data.person_view.person.id != $profile.user.local_user_view.person.id}
|
||||
{#if profile.data?.user && profile.data.jwt && data.person_view.person.id != profile.data.user.local_user_view.person.id}
|
||||
<div class="flex items-center gap-2 w-full">
|
||||
<Button
|
||||
size="square-md"
|
||||
@@ -234,7 +235,7 @@
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if isAdmin($profile?.user)}
|
||||
{#if isAdmin(profile.data?.user)}
|
||||
<Menu class="ml-auto" placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button size="square-md">
|
||||
@@ -280,7 +281,7 @@
|
||||
{#snippet prefix()}
|
||||
<Icon mini size="16" src={NoSymbol} />
|
||||
{/snippet}
|
||||
{isBlocked($profile.user, data.person_view.person.id)
|
||||
{isBlocked(profile.data.user, data.person_view.person.id)
|
||||
? 'Unblock'
|
||||
: 'Block'}
|
||||
</MenuButton>
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
|
||||
let link = $state('')
|
||||
|
||||
let photonified
|
||||
run(() => {
|
||||
photonified = photonify(link)
|
||||
})
|
||||
let photonified = $derived(photonify(link))
|
||||
</script>
|
||||
|
||||
<h1 class="font-bold text-2xl">Photonify links</h1>
|
||||
@@ -21,5 +18,5 @@
|
||||
bind:value={link}
|
||||
placeholder="https://lemmy.world/post/1"
|
||||
/>
|
||||
<TextInput label="Output" bind:value={photonified} />
|
||||
<TextInput label="Output" value={photonified} />
|
||||
</div>
|
||||
Reference in new issue
Block a user