auth: rename profile.data -> profile.current
This commit is contained in:
76 files changed
+233
-224
No files matched your search
+20
-19
@@ -92,27 +92,27 @@ export const profileData = $state<ProfileData>(
|
||||
)
|
||||
|
||||
class CurrentProfile {
|
||||
#data = $derived(
|
||||
#current = $derived(
|
||||
profileData.profiles.find(i => i.id == profileData.profile) ??
|
||||
getDefaultProfile(),
|
||||
)
|
||||
|
||||
get data() {
|
||||
return this.#data
|
||||
get current() {
|
||||
return this.#current
|
||||
}
|
||||
set data(value) {
|
||||
set current(value) {
|
||||
if (!value) return
|
||||
const index = profileData.profiles.findIndex(i => i.id == value?.id)
|
||||
profileData.profiles[index] = value
|
||||
}
|
||||
|
||||
async fetchUserData() {
|
||||
const startId = this.#data.id
|
||||
if (this.#data.jwt) {
|
||||
const startId = this.#current.id
|
||||
if (this.#current.jwt) {
|
||||
site.data = undefined
|
||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||
|
||||
const res = await userFromJwt(this.#data.jwt, this.#data.instance)
|
||||
const res = await userFromJwt(this.#current.jwt, this.#current.instance)
|
||||
if (!res?.user)
|
||||
toast({
|
||||
content:
|
||||
@@ -121,21 +121,21 @@ class CurrentProfile {
|
||||
})
|
||||
|
||||
// TODO update authentication handling to not be this dynamic
|
||||
if (this.#data.id != startId) {
|
||||
if (this.#current.id != startId) {
|
||||
console.error('profile was switched too fast, ID mismatch')
|
||||
return
|
||||
}
|
||||
|
||||
site.data = res?.site
|
||||
this.#data.user = res?.user
|
||||
if (profile.data.user) {
|
||||
this.#data.avatar = res?.user?.local_user_view.person.avatar
|
||||
this.#data.username = res?.user?.local_user_view.person.name
|
||||
this.#current.user = res?.user
|
||||
if (profile.current.user) {
|
||||
this.#current.avatar = res?.user?.local_user_view.person.avatar
|
||||
this.#current.username = res?.user?.local_user_view.person.name
|
||||
}
|
||||
} else {
|
||||
if (browser) {
|
||||
site.data = undefined
|
||||
client({ instanceURL: this.#data.instance })
|
||||
client({ instanceURL: this.#current.instance })
|
||||
.getSite()
|
||||
.then(res => (site.data = res))
|
||||
}
|
||||
@@ -174,7 +174,7 @@ $effect.root(() => {
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (profile.data.id || profileData)
|
||||
if (profile.current.id || profileData)
|
||||
profile.fetchUserData().then(() => {
|
||||
checkInbox()
|
||||
})
|
||||
@@ -358,7 +358,7 @@ async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
|
||||
}
|
||||
|
||||
async function checkInbox() {
|
||||
const { user, jwt } = profile.data
|
||||
const { user, jwt } = profile.current
|
||||
if (!jwt || !user) return
|
||||
|
||||
const notifs = await getNotificationCount(
|
||||
@@ -380,10 +380,11 @@ async function init() {
|
||||
// hacky way to check donation status
|
||||
setTimeout(() => {
|
||||
if (
|
||||
profile.data.user?.local_user_view.local_user.last_donation_notification
|
||||
profile.current.user?.local_user_view.local_user
|
||||
.last_donation_notification
|
||||
) {
|
||||
const donationDate = publishedToDate(
|
||||
profile.data.user?.local_user_view.local_user
|
||||
profile.current.user?.local_user_view.local_user
|
||||
.last_donation_notification,
|
||||
)
|
||||
if (Date.now() - donationDate.getTime() > 365 * 24 * 60 * 60 * 1000) {
|
||||
@@ -395,11 +396,11 @@ async function init() {
|
||||
|
||||
// lemmy js client donation dialog is broken
|
||||
fetch(
|
||||
`${instanceToURL(profile.data.instance)}/api/v3/user/donation_dialog_shown`,
|
||||
`${instanceToURL(profile.current.instance)}/api/v3/user/donation_dialog_shown`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${profile.data.jwt}`,
|
||||
authorization: `Bearer ${profile.current.jwt}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function deleteImage(image: LocalImage) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
try {
|
||||
loading = true
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
let editingLoad = $state(false)
|
||||
|
||||
async function save(type: 'reply' | 'edit') {
|
||||
if (!profile.data?.jwt || newComment.length <= 0) return
|
||||
if (!profile.current?.jwt || newComment.length <= 0) return
|
||||
|
||||
editingLoad = true
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||
<span class="text-xs">{$t('comment.reply')}</span>
|
||||
</Button>
|
||||
{#if profile.data?.user && (amMod(profile.data?.user, comment.community) || isAdmin(profile.data.user))}
|
||||
{#if profile.current?.user && (amMod(profile.current?.user, comment.community) || isAdmin(profile.current.user))}
|
||||
<CommentModerationMenu bind:item={comment} />
|
||||
{/if}
|
||||
<Menu placement="bottom">
|
||||
@@ -90,8 +90,8 @@
|
||||
<Icon src={Square2Stack} mini size="16" />
|
||||
<div>{$t('post.actions.more.share')}</div>
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if comment.creator.id == profile.data.user?.local_user_view.person.id}
|
||||
{#if profile.current?.jwt}
|
||||
{#if comment.creator.id == profile.current.user?.local_user_view.person.id}
|
||||
<MenuButton onclick={() => onedit?.(comment)}>
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
<span>{$t('post.actions.more.edit')}</span>
|
||||
@@ -99,7 +99,7 @@
|
||||
{/if}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
comment.saved = await save(comment, !comment.saved)
|
||||
}}
|
||||
>
|
||||
@@ -108,11 +108,11 @@
|
||||
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
</span>
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.jwt && profile.data.user.local_user_view.person.id == comment.creator.id}
|
||||
{#if profile.current?.user && profile.current.jwt && profile.current.user.local_user_view.person.id == comment.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
comment.comment.deleted = await deleteItem(
|
||||
comment,
|
||||
!comment.comment.deleted,
|
||||
@@ -127,7 +127,7 @@
|
||||
</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id}
|
||||
{#if profile.current.jwt && profile.current.user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton onclick={() => report(comment)} color="danger-subtle">
|
||||
<Icon src={Flag} mini size="16" />
|
||||
<span>{$t('moderation.report')}</span>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
let language: number | undefined = $state()
|
||||
|
||||
async function submit() {
|
||||
if (!profile.data?.user || !profile.data?.jwt || value == '') return
|
||||
if (!profile.current?.user || !profile.current?.jwt || value == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
}: Props = $props()
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
})
|
||||
|
||||
async function subscribe() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
loading.subscribing = true
|
||||
const subscribed =
|
||||
community_view.subscribed == 'Subscribed' ||
|
||||
@@ -227,7 +227,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-row items-center gap-1 sticky bottom-0 w-full">
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
disabled={loading.subscribing}
|
||||
loading={loading.subscribing}
|
||||
@@ -252,7 +252,7 @@
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
|
||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||
<Button
|
||||
href="/c/{fullCommunityName(
|
||||
community_view.community.name,
|
||||
@@ -278,7 +278,7 @@
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -292,7 +292,7 @@
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -304,7 +304,7 @@
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
let formData = $state(passedFormData)
|
||||
|
||||
async function submit() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||
|
||||
formData.submitting = true
|
||||
@@ -99,23 +99,23 @@
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
if (profile.data.user) {
|
||||
const c = profile.data.user.moderates
|
||||
if (profile.current.user) {
|
||||
const c = profile.current.user.moderates
|
||||
.map(m => m.community.id)
|
||||
.indexOf(res.community_view.community.id)
|
||||
if (c != -1) {
|
||||
profile.data.user.moderates[c] = {
|
||||
profile.current.user.moderates[c] = {
|
||||
community: res.community_view.community,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
moderator: profile.current.user.local_user_view.person,
|
||||
}
|
||||
} else {
|
||||
profile.data.user = {
|
||||
...profile.data.user,
|
||||
profile.current.user = {
|
||||
...profile.current.user,
|
||||
moderates: [
|
||||
...profile.data.user.moderates,
|
||||
...profile.current.user.moderates,
|
||||
{
|
||||
community: res.community_view.community,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
moderator: profile.current.user.local_user_view.person,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
<div class="flex items-center gap-2 h-max w-max">
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Subscribe
|
||||
community={{
|
||||
community: community,
|
||||
@@ -153,7 +153,7 @@
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.user && profile.data.user.moderates
|
||||
{#if profile.current?.user && profile.current.user.moderates
|
||||
.map(c => c.community.id)
|
||||
.includes(community.id)}
|
||||
<Button
|
||||
@@ -181,7 +181,7 @@
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if profile.data.user && amMod(profile.data.user, community)}
|
||||
{#if profile.current.user && amMod(profile.current.user, community)}
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
href="/moderation?community={community.id}"
|
||||
@@ -190,7 +190,7 @@
|
||||
{$t('routes.moderation.feed')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -203,7 +203,7 @@
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
@@ -215,7 +215,7 @@
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<Subscribe {community}>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing || !profile.data?.jwt}
|
||||
disabled={subscribing || !profile.current?.jwt}
|
||||
loading={subscribing}
|
||||
onclick={async () => {
|
||||
const res = await subscribe()
|
||||
|
||||
@@ -51,14 +51,14 @@
|
||||
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
|
||||
<Option
|
||||
value="Subscribed"
|
||||
disabled={profile.data?.jwt == undefined}
|
||||
disabled={profile.current?.jwt == undefined}
|
||||
icon={Newspaper}
|
||||
>
|
||||
{$t('filter.location.subscribed')}
|
||||
</Option>
|
||||
<Option
|
||||
value="ModeratorView"
|
||||
disabled={!profile.data?.jwt || !amModOfAny(profile.data?.user)}
|
||||
disabled={!profile.current?.jwt || !amModOfAny(profile.current?.user)}
|
||||
icon={ShieldCheck}
|
||||
>
|
||||
{$t('filter.location.moderator')}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
avatar
|
||||
avatarSize={20}
|
||||
/>
|
||||
{#if profile.data?.user?.local_user_view.person.id != message.recipient.id}
|
||||
{#if profile.current?.user?.local_user_view.person.id != message.recipient.id}
|
||||
to
|
||||
<UserLink
|
||||
showInstance={false}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
)
|
||||
|
||||
async function upload() {
|
||||
if (!profile.data?.jwt || image == null) return
|
||||
if (!profile.current?.jwt || image == null) return
|
||||
|
||||
progress = 0
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
const uploaded = (
|
||||
await Promise.all(
|
||||
Array.from(image).map(i =>
|
||||
uploadImage(i, profile.data.instance, profile.data.jwt!)
|
||||
uploadImage(i, profile.current.instance, profile.current.jwt!)
|
||||
.then(uploaded => {
|
||||
progress += 1 / (image?.length ?? 0)
|
||||
return uploaded
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function sendMessage() {
|
||||
if (!profile.data?.jwt || message == '') return
|
||||
if (!profile.current?.jwt || message == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !profile.data?.user || !profile.data?.jwt) return
|
||||
if (!item || !profile.current?.user || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -52,7 +52,7 @@
|
||||
: $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.current?.user && profile.current.user?.local_user_view.person.id != item.creator.id}
|
||||
<!--Comment made by someone else-->
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
@@ -71,12 +71,12 @@
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
onclick={async () => {
|
||||
if (!profile.data.jwt) return
|
||||
if (!profile.current.jwt) return
|
||||
item.comment = (
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
profile.data.jwt,
|
||||
profile.current.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
@@ -104,7 +104,7 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
{#snippet prefix()}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
let acting = $derived(locking || pinning)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
locking = true
|
||||
|
||||
try {
|
||||
@@ -53,7 +53,7 @@
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
|
||||
pinning = true
|
||||
|
||||
@@ -88,9 +88,9 @@
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -124,7 +124,7 @@
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
{#if isAdmin(profile.data.user)}
|
||||
{#if isAdmin(profile.current.user)}
|
||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -139,7 +139,7 @@
|
||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.current?.user && profile.current.user.local_user_view.person.id != item.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
@@ -164,7 +164,7 @@
|
||||
{$t('moderation.votes')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
if (!profile.data?.jwt) throw new Error('Unauthenticated')
|
||||
if (!profile.current?.jwt) throw new Error('Unauthenticated')
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -216,7 +216,7 @@
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))}
|
||||
{#if !removed && profile.current?.user && (amMod(profile.current.user, item.community) || (isAdmin(profile.current.user) && item.community.local))}
|
||||
<Switch bind:checked={commentReason}>
|
||||
{$t('moderation.removeSubmission.withReason')}
|
||||
</Switch>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !profile.data?.jwt || reason == '') return
|
||||
if (!item || !profile.current?.jwt || reason == '') return
|
||||
loading = true
|
||||
|
||||
try {
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
user={post.creator}
|
||||
published={publishedToDate(post.post.published)}
|
||||
{badges}
|
||||
subscribed={profile.data?.user?.follows
|
||||
subscribed={profile.current?.user?.follows
|
||||
.map(c => c.community.id)
|
||||
.includes(post.community.id)
|
||||
? 'Subscribed'
|
||||
|
||||
@@ -117,8 +117,8 @@
|
||||
score={post.counts.score}
|
||||
upvotes={post.counts.upvotes}
|
||||
downvotes={post.counts.downvotes}
|
||||
showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ??
|
||||
true}
|
||||
showCounts={profile.current?.user?.local_user_view?.local_user
|
||||
?.show_scores ?? true}
|
||||
/>
|
||||
|
||||
<Button
|
||||
@@ -160,7 +160,7 @@
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if profile.data?.user && (amMod(profile.data.user, post.community) || isAdmin(profile.data.user))}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
<ModerationMenu
|
||||
size="custom"
|
||||
color="ghost"
|
||||
@@ -171,10 +171,10 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Button
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
saving = true
|
||||
post.saved = await save(post, !post.saved)
|
||||
saving = false
|
||||
@@ -228,7 +228,7 @@
|
||||
<MenuDivider>
|
||||
{$t('post.actions.more.actions')}
|
||||
</MenuDivider>
|
||||
{#if profile.data?.user && profile.data?.jwt && profile.data.user.local_user_view.person.id == post.creator.id}
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
@@ -236,10 +236,10 @@
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
>
|
||||
@@ -297,7 +297,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
setSessionStorage('postDraft', {
|
||||
@@ -326,10 +326,10 @@
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.data.user && post.creator.id == profile.data.user.local_user_view.person.id}
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
if (profile.current?.jwt)
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
@@ -342,15 +342,15 @@
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if profile.current.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if feature('hidePosts', site.data?.version)}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
profile.data?.jwt,
|
||||
profile.current?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) onhide?.(hidden)
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!data.title || !profile.data?.jwt) return
|
||||
if (!data.title || !profile.current?.jwt) return
|
||||
if (data.url && data.url != '') {
|
||||
try {
|
||||
new URL(data.url)
|
||||
@@ -275,7 +275,7 @@
|
||||
<ObjectAutocomplete
|
||||
bind:q={communitySearch}
|
||||
items={communities}
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
label={$t('form.post.community')}
|
||||
required
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
).users.map(c => c.person)
|
||||
|
||||
if (hideOwnUser) {
|
||||
const myself = profile.data.user?.local_user_view.person.id
|
||||
const myself = profile.current.user?.local_user_view.person.id
|
||||
return users.filter(c => c.id != myself)
|
||||
}
|
||||
return users
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
style="border-radius: inherit;"
|
||||
>
|
||||
<div class="ml-auto"></div>
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<NavButton
|
||||
href="/admin"
|
||||
label={$t('nav.admin')}
|
||||
@@ -95,7 +95,7 @@
|
||||
isSelectedFilter={path => path.startsWith('/admin')}
|
||||
/>
|
||||
{/if}
|
||||
{#if amModOfAny(profile.data?.user)}
|
||||
{#if amModOfAny(profile.current?.user)}
|
||||
<NavButton
|
||||
href="/moderation"
|
||||
label={$t('nav.moderation')}
|
||||
@@ -109,10 +109,10 @@
|
||||
icon={GlobeAlt}
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
{@const linkOnly =
|
||||
!profile.data.user ||
|
||||
!(isAdmin(profile.data.user) || amModOfAny(profile.data.user))}
|
||||
!profile.current.user ||
|
||||
!(isAdmin(profile.current.user) || amModOfAny(profile.current.user))}
|
||||
<Menu manual={linkOnly} placement="top">
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
@@ -136,7 +136,7 @@
|
||||
{@render notifBadge($notifications.inbox)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{#if amModOfAny(profile.data.user)}
|
||||
{#if amModOfAny(profile.current.user)}
|
||||
<MenuButton href="/moderation" icon={ShieldCheck}>
|
||||
{$t('routes.moderation.feed')}
|
||||
{#snippet suffix()}
|
||||
@@ -144,7 +144,7 @@
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.data.user && isAdmin(profile.data.user)}
|
||||
{#if profile.current.user && isAdmin(profile.current.user)}
|
||||
<MenuButton href="/admin/applications" icon={ServerStack}>
|
||||
{$t('routes.admin.applications.title')}
|
||||
{#snippet suffix()}
|
||||
@@ -156,7 +156,7 @@
|
||||
{/if}
|
||||
<Menu
|
||||
manual={site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!(profile.data.user && isAdmin(profile.data.user))}
|
||||
!(profile.current.user && isAdmin(profile.current.user))}
|
||||
placement="top"
|
||||
>
|
||||
{#snippet target()}
|
||||
@@ -166,13 +166,13 @@
|
||||
icon={Plus}
|
||||
adaptive={false}
|
||||
href={site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!(profile.data.user && isAdmin(profile.data.user))
|
||||
!(profile.current.user && isAdmin(profile.current.user))
|
||||
? '/create/post'
|
||||
: undefined}
|
||||
/>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||
<MenuButton link href="/create/post" disabled={!profile.data?.jwt}>
|
||||
<MenuButton link href="/create/post" disabled={!profile.current?.jwt}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
@@ -181,17 +181,17 @@
|
||||
<MenuButton
|
||||
link
|
||||
href="/create/community"
|
||||
disabled={!profile.data?.jwt ||
|
||||
!profile.data?.user ||
|
||||
disabled={!profile.current?.jwt ||
|
||||
!profile.current?.user ||
|
||||
(site.data?.site_view.local_site.community_creation_admin_only &&
|
||||
!isAdmin(profile.data.user))}
|
||||
!isAdmin(profile.current.user))}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.community')}
|
||||
</MenuButton>
|
||||
{#if !profile.data?.jwt}
|
||||
{#if !profile.current?.jwt}
|
||||
<span class="text-sm mx-4 my-1 py-1">
|
||||
{$t('nav.create.logingate')}
|
||||
</span>
|
||||
|
||||
@@ -72,14 +72,14 @@
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700 group cursor-pointer {buttonClass}"
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if profile.data?.user}
|
||||
{#if profile.current?.user}
|
||||
<div
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center group-hover:scale-90 transition-transform group-active:scale-[85%]"
|
||||
>
|
||||
<Avatar
|
||||
url={profile.data.user.local_user_view.person.avatar}
|
||||
url={profile.current.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={profile.data.user.local_user_view.person.name}
|
||||
alt={profile.current.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -90,7 +90,7 @@
|
||||
</button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/profile">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro size="16" />
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
$effect(() => {
|
||||
groups = getGroups(
|
||||
$resumables,
|
||||
profile.data,
|
||||
profile.current,
|
||||
profileData.profiles,
|
||||
theme.data,
|
||||
page.data.contextual?.actions,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
animate:flip={{ duration: 500, easing: expoOut }}
|
||||
>
|
||||
<div class="flex-none grid group">
|
||||
{#if profile && !hasFavorite(profile.data, follow.id)}
|
||||
{#if profile && !hasFavorite(profile.current, follow.id)}
|
||||
<Button
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
@@ -36,7 +36,7 @@
|
||||
>
|
||||
<Icon src={Star} size="16" mini />
|
||||
</Button>
|
||||
{:else if isFavorites && profile && hasFavorite(profile.data, follow.id)}
|
||||
{:else if isFavorites && profile && hasFavorite(profile.current, follow.id)}
|
||||
<Button
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
@@ -53,7 +53,9 @@
|
||||
alt={follow.name}
|
||||
title={follow.title}
|
||||
width={28}
|
||||
class={!isFavorites && profile && hasFavorite(profile.data, follow.id)
|
||||
class={!isFavorites &&
|
||||
profile &&
|
||||
hasFavorite(profile.current, follow.id)
|
||||
? ''
|
||||
: 'group-hover:hidden'}
|
||||
/>
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
loading={switching}
|
||||
rounding="lg"
|
||||
loaderWidth={22}
|
||||
selected={profile.data?.id == prof.id}
|
||||
selected={profile.current?.id == prof.id}
|
||||
onclick={async () => {
|
||||
switching = true
|
||||
|
||||
if (profile.data?.id != prof.id) {
|
||||
if (profile.current?.id != prof.id) {
|
||||
await setUserID(prof.id)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
switching = false
|
||||
}}
|
||||
class="w-full font-normal {profile.data?.id == prof.id
|
||||
class="w-full font-normal {profile.current?.id == prof.id
|
||||
? 'bg-slate-100! dark:bg-zinc-900!'
|
||||
: ''}"
|
||||
>
|
||||
@@ -46,11 +46,11 @@
|
||||
profile={prof}
|
||||
{index}
|
||||
{guest}
|
||||
selected={profile.data?.id == prof.id}
|
||||
selected={profile.current?.id == prof.id}
|
||||
/>
|
||||
{/snippet}
|
||||
<span
|
||||
class="inline-flex flex-col gap-0 {profile.data?.id == prof.id
|
||||
class="inline-flex flex-col gap-0 {profile.current?.id == prof.id
|
||||
? 'font-semibold'
|
||||
: ''}"
|
||||
>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
class={['flex flex-col p-4 overflow-auto gap-1 h-fit max-h-screen', clazz]}
|
||||
{style}
|
||||
>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<SidebarButton icon={UserCircle} href="/profile">
|
||||
{#snippet label()}
|
||||
<span>
|
||||
@@ -120,7 +120,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
{#if profile.data?.favorites && profile.data?.favorites.length > 0}
|
||||
{#if profile.current?.favorites && profile.current?.favorites.length > 0}
|
||||
<Expandable
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={settings.expand.favorites}
|
||||
@@ -131,18 +131,18 @@
|
||||
{$t('routes.profile.favorites')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.favorites?.length}
|
||||
{profile.current.favorites?.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList isFavorites items={profile.data.favorites} />
|
||||
<CommunityList isFavorites items={profile.current.favorites} />
|
||||
</Expandable>
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
{/if}
|
||||
{#if profile.data?.user}
|
||||
{#if profile.data?.user.moderates.length > 0}
|
||||
{#if profile.current?.user}
|
||||
{#if profile.current?.user.moderates.length > 0}
|
||||
<Expandable
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={settings.expand.moderates}
|
||||
@@ -153,14 +153,14 @@
|
||||
{$t('routes.profile.moderates')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.user?.moderates.length}
|
||||
{profile.current.user?.moderates.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList
|
||||
items={profile.data.user.moderates.map(i => i.community)}
|
||||
items={profile.current.user.moderates.map(i => i.community)}
|
||||
/>
|
||||
</Expandable>
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
@@ -176,13 +176,15 @@
|
||||
{$t('profile.subscribed')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.data.user?.follows.length}
|
||||
{profile.current.user?.follows.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList items={profile.data.user.follows.map(i => i.community)} />
|
||||
<CommunityList
|
||||
items={profile.current.user.follows.map(i => i.community)}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</nav>
|
||||
@@ -3,7 +3,7 @@ import { env } from '$env/dynamic/public'
|
||||
import { profile } from './auth.svelte'
|
||||
|
||||
class InstanceData {
|
||||
#instance = $derived(profile.data.instance)
|
||||
#instance = $derived(profile.current.instance)
|
||||
|
||||
get data() {
|
||||
return this.#instance ?? DEFAULT_INSTANCE_URL
|
||||
|
||||
@@ -59,9 +59,10 @@ export function client({
|
||||
) => Promise<Response>
|
||||
auth?: string
|
||||
} = {}) {
|
||||
if (!instanceURL) instanceURL = profile.data.instance || DEFAULT_INSTANCE_URL
|
||||
if (!instanceURL)
|
||||
instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL
|
||||
|
||||
const jwt = auth ? auth : profile.data?.jwt
|
||||
const jwt = auth ? auth : profile.current?.jwt
|
||||
|
||||
const headers = jwt ? { authorization: `Bearer ${jwt}` } : {}
|
||||
|
||||
|
||||
@@ -106,12 +106,12 @@ function resumableStore(limit: number = 10) {
|
||||
export const resumables = resumableStore()
|
||||
|
||||
export function addFavorite(item: Community, add: boolean = true) {
|
||||
const favs = profile.data.favorites ?? []
|
||||
const favs = profile.current.favorites ?? []
|
||||
if (favs.map(fav => fav.id).includes(item.id)) if (add) return
|
||||
if (!add) {
|
||||
favs.splice(favs.map(c => c.id).indexOf(item.id), 1)
|
||||
} else {
|
||||
favs.unshift(item)
|
||||
}
|
||||
profile.data.favorites = favs
|
||||
profile.current.favorites = favs
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import type { Community, MyUserInfo } from 'lemmy-js-client'
|
||||
// TODO obliterate this file
|
||||
|
||||
export const blockUser = async (block: boolean, id: number) => {
|
||||
const auth = profile.data?.jwt
|
||||
const auth = profile.current?.jwt
|
||||
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
@@ -23,17 +23,17 @@ export const addSubscription = (
|
||||
community: Community,
|
||||
subscribe: boolean = true,
|
||||
) => {
|
||||
const index = profile.data.user?.follows
|
||||
const index = profile.current.user?.follows
|
||||
.map(f => f.community.id)
|
||||
.indexOf(community.id)
|
||||
|
||||
if (subscribe && index == -1) {
|
||||
profile.data.user?.follows.push({
|
||||
follower: profile.data.user.follows[0]?.follower,
|
||||
profile.current.user?.follows.push({
|
||||
follower: profile.current.user.follows[0]?.follower,
|
||||
community: community,
|
||||
})
|
||||
} else {
|
||||
profile.data.user?.follows.splice(index ?? 0, 1)
|
||||
profile.current.user?.follows.splice(index ?? 0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,14 @@
|
||||
|
||||
let switching = $state(-1)
|
||||
|
||||
let radioSelected = $state(profile.data.id)
|
||||
let radioSelected = $state(profile.current.id)
|
||||
$effect(() => {
|
||||
switching = radioSelected
|
||||
setUserID(radioSelected)
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (profile.data.user) switching = -1
|
||||
if (profile.current.user) switching = -1
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -55,7 +55,9 @@
|
||||
|
||||
{#if debugging}
|
||||
<DebugObject
|
||||
object={debugProfile?.id == profile.data?.id ? profile.data : debugProfile}
|
||||
object={debugProfile?.id == profile.current?.id
|
||||
? profile.current
|
||||
: debugProfile}
|
||||
bind:open={debugging}
|
||||
>
|
||||
{#snippet title()}
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function load({ fetch, url }) {
|
||||
const uri = url.searchParams.get('uri')
|
||||
if (!uri) error(404)
|
||||
|
||||
if (!profile.data.jwt)
|
||||
if (!profile.current.jwt)
|
||||
redirect(302, `/login?ref=${encodeURIComponent(url.toString())}`)
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
export async function load({ fetch, url }) {
|
||||
if (!profile) return
|
||||
|
||||
const { jwt } = profile.data!
|
||||
const { jwt } = profile.current!
|
||||
if (!jwt) return
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
let reviewing = $state(false)
|
||||
|
||||
async function review(approve: boolean) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
let registrationApplicationAnswer: ApproveRegistrationApplication = {
|
||||
approve: approve,
|
||||
@@ -67,7 +67,7 @@
|
||||
type: 'success',
|
||||
})
|
||||
application.creator_local_user.accepted_application = approve
|
||||
application.admin = profile.data.user!.local_user_view.person
|
||||
application.admin = profile.current.user!.local_user_view.person
|
||||
application.registration_application.deny_reason = denyReason
|
||||
|
||||
$notifications.applications -= 1
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
)
|
||||
|
||||
async function save() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
if (instance == '') return
|
||||
await trycatch(async () => {
|
||||
if (
|
||||
!profile.data?.jwt ||
|
||||
!profile.current?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked ||
|
||||
!data.federated_instances?.federated_instances?.allowed
|
||||
)
|
||||
@@ -81,7 +81,7 @@
|
||||
const save = async () => {
|
||||
const res = await trycatch(async () => {
|
||||
if (
|
||||
!profile.data?.jwt ||
|
||||
!profile.current?.jwt ||
|
||||
!data.federated_instances?.federated_instances?.blocked
|
||||
)
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = profile.data
|
||||
const { jwt } = profile.current
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
let saving = $state(false)
|
||||
|
||||
async function save() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
saving = true
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
action: () => removeAdmin(id, true),
|
||||
})
|
||||
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
const result = await trycatch(() =>
|
||||
getClient().addAdmin({
|
||||
@@ -77,7 +77,7 @@
|
||||
class="flex flex-row items-center gap-2 mt-auto w-full"
|
||||
onsubmit={preventDefault(() => {
|
||||
trycatch(async () => {
|
||||
if (!profile.data?.jwt || newAdmin == '') return
|
||||
if (!profile.current?.jwt || newAdmin == '') return
|
||||
adding = true
|
||||
|
||||
const r = await addAdmin(`${newAdmin}@${instance.data}`, true)
|
||||
|
||||
@@ -81,10 +81,10 @@
|
||||
{/snippet}
|
||||
</Header>
|
||||
|
||||
{#if profile.data.user}
|
||||
{#if !data.community.value.discussion_languages.every( l => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
{#if profile.current.user}
|
||||
{#if !data.community.value.discussion_languages.every( l => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0}
|
||||
{@const missing = data.community.value.discussion_languages.filter(
|
||||
i => !profile.data.user?.discussion_languages.includes(i),
|
||||
i => !profile.current.user?.discussion_languages.includes(i),
|
||||
)}
|
||||
<Note class="p-1! pl-3! flex-col md:flex-row">
|
||||
<div>{$t('routes.community.languageWarning')}</div>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
})
|
||||
|
||||
async function addModerator() {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
formData.addingModerator = true
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
}
|
||||
|
||||
async function removeMod(id: number) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
|
||||
@@ -4,11 +4,11 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
if (profile.data.instance != params.instance)
|
||||
if (profile.current.instance != params.instance)
|
||||
redirect(302, resolveRoute('/comment/[instance]/[id]/confirm', params))
|
||||
|
||||
const comment = await client({
|
||||
instanceURL: profile.data.instance,
|
||||
instanceURL: profile.current.instance,
|
||||
func: fetch,
|
||||
}).getComment({
|
||||
id: Number(params.id),
|
||||
@@ -16,6 +16,6 @@ export async function load({ params, fetch }) {
|
||||
|
||||
redirect(
|
||||
302,
|
||||
`/post/${profile.data.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
||||
`/post/${profile.current.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
|
||||
)
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
import { Plus } from 'svelte-hero-icons'
|
||||
|
||||
let loading = $state(false)
|
||||
const fetched = $state.snapshot(profile.data.instance)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
@@ -27,7 +27,7 @@
|
||||
if (res.comment) {
|
||||
goto(
|
||||
resolveRoute(`/comment/[instance]/[id]`, {
|
||||
instance: profile.data.instance,
|
||||
instance: profile.current.instance,
|
||||
id: res.comment.comment.id.toString(),
|
||||
}),
|
||||
)
|
||||
@@ -56,7 +56,7 @@
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
|
||||
@@ -2,6 +2,6 @@ import { profile } from '$lib/auth.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
if (profile.data.instance == params.instance)
|
||||
if (profile.current.instance == params.instance)
|
||||
redirect(302, `/comment/${params.instance}/${params.id}`)
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
id: number | undefined = community?.community.id,
|
||||
subscribed: SubscribedType | undefined = community?.subscribed,
|
||||
) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if (!id || !subscribed) return
|
||||
|
||||
subscribing = true
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
let { data } = $props()
|
||||
|
||||
onMount(() => {
|
||||
if (!profile.data?.jwt) {
|
||||
if (!profile.current?.jwt) {
|
||||
goto('/login')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
let markingAsRead = $state(false)
|
||||
|
||||
async function markAllAsRead() {
|
||||
if (!profile.data?.user) {
|
||||
if (!profile.current?.user) {
|
||||
goto('/login')
|
||||
return
|
||||
}
|
||||
@@ -156,7 +156,7 @@ items-center px-2 w-max top-6 lg:top-22"
|
||||
/>
|
||||
{:else}
|
||||
{#each data.inbox.value as item, index}
|
||||
{#if item.creator.id != profile.data.user?.local_user_view.person.id}
|
||||
{#if item.creator.id != profile.current.user?.local_user_view.person.id}
|
||||
<div
|
||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6
|
||||
{item.read ? '' : 'bg-blue-50/50 dark:bg-blue-500/5'}"
|
||||
|
||||
@@ -12,7 +12,7 @@ import { error } from '@sveltejs/kit'
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const type: InboxFeedType =
|
||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
let loading = $state(false)
|
||||
|
||||
async function markAsRead(isRead: boolean) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
}
|
||||
|
||||
item.read = isRead
|
||||
if (profile.data.user) $notifications.inbox += isRead ? -1 : 1
|
||||
if (profile.current.user) $notifications.inbox += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
}
|
||||
|
||||
function getOtherPartyId(message: PrivateMessageView): number {
|
||||
return message.creator.id == profile.data.user?.local_user_view.person.id
|
||||
return message.creator.id == profile.current.user?.local_user_view.person.id
|
||||
? message.recipient.id
|
||||
: message.creator.id
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
.filter(c => c.creator.id != c.recipient.id) // you messaged yourself
|
||||
.map(i => ({
|
||||
user:
|
||||
i.creator.id != profile.data.user?.local_user_view.person.id
|
||||
i.creator.id != profile.current.user?.local_user_view.person.id
|
||||
? i.creator
|
||||
: i.recipient,
|
||||
message: {
|
||||
@@ -153,8 +153,8 @@
|
||||
bg-linear-to-r from-slate-700 via-slate-700 to-slate-700/0 dark:from-zinc-300 dark:via-zinc-300 dark:to-zinc-300/0
|
||||
text-transparent bg-clip-text flex-1 overflow-hidden"
|
||||
>
|
||||
{#if preview.message.last_sender == profile.data.user?.local_user_view.person.id}
|
||||
{profile.data.user?.local_user_view.person.name}:
|
||||
{#if preview.message.last_sender == profile.current.user?.local_user_view.person.id}
|
||||
{profile.current.user?.local_user_view.person.name}:
|
||||
{/if}
|
||||
{preview.message.content}
|
||||
</div>
|
||||
|
||||
@@ -2,5 +2,5 @@ import { profile } from '$lib/auth.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export function load() {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import { error } from '@sveltejs/kit'
|
||||
type ReportListType = 'unread' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: ReportListType =
|
||||
@@ -30,7 +30,7 @@ export async function load({ url, fetch }) {
|
||||
community_id: community,
|
||||
}
|
||||
|
||||
const admin = profile.data?.user ? isAdmin(profile!.data.user!) : false
|
||||
const admin = profile.current?.user ? isAdmin(profile!.data.user!) : false
|
||||
|
||||
const [posts, comments, messages] = await Promise.all([
|
||||
client.listPostReports({
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
let resolving = $state(false)
|
||||
async function resolve() {
|
||||
if (!profile.data?.jwt || !profile.data.user) return
|
||||
if (!profile.current?.jwt || !profile.current.user) return
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
{$t('nav.communities')}
|
||||
</Header>
|
||||
<div class="w-full h-full flex flex-col mt-4">
|
||||
{#if !profile.data.user}
|
||||
{#if !profile.current.user}
|
||||
<div class="mx-auto my-auto">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
@@ -20,7 +20,7 @@
|
||||
rounding="2xl"
|
||||
class="flex flex-col dark:bg-zinc-950 max-h-[32rem] overflow-auto"
|
||||
>
|
||||
{#each profile.data.user.moderates as moderate}
|
||||
{#each profile.current.user.moderates as moderate}
|
||||
{@const community = moderate.community}
|
||||
<div
|
||||
class="-mx-4 px-4 hover:bg-slate-100 hover:dark:bg-zinc-900 transition-colors duration-75"
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
<UserAutocomplete
|
||||
instance={page.url.searchParams.get('instance') || undefined}
|
||||
placeholder="Filter by user"
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
@@ -217,10 +217,10 @@
|
||||
onselect={e =>
|
||||
searchParam(page.url, 'user', e?.id.toString() ?? '', 'page')}
|
||||
/>
|
||||
{#if profile.data?.user && isAdmin(profile.data?.user)}
|
||||
{#if profile.current?.user && isAdmin(profile.current?.user)}
|
||||
<UserAutocomplete
|
||||
placeholder="Filter by moderator"
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
class="flex-1"
|
||||
|
||||
@@ -7,7 +7,7 @@ export function load({ params }) {
|
||||
redirect(
|
||||
302,
|
||||
resolveRoute(`/post/[instance]/[id]`, {
|
||||
instance: profile.data.instance.toLowerCase(),
|
||||
instance: profile.current.instance.toLowerCase(),
|
||||
id: params.instance,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
onMount(async () => {
|
||||
if (
|
||||
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
||||
profile.data?.jwt
|
||||
profile.current?.jwt
|
||||
) {
|
||||
getClient().markPostAsRead({
|
||||
read: settings.markPostsAsRead,
|
||||
|
||||
@@ -28,7 +28,7 @@ function buildContext(thread?: string) {
|
||||
}
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
if (profile.data.instance != params.instance)
|
||||
if (profile.current.instance != params.instance)
|
||||
redirect(302, resolveRoute('/post/[instance]/[id]/confirm', params))
|
||||
|
||||
// TODO use Lemmy profile default settings
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
{#if !commenting}
|
||||
<EndPlaceholder>
|
||||
<Button
|
||||
@@ -60,8 +60,8 @@
|
||||
disabled={(post.post_view.post.locked ||
|
||||
post.post_view.banned_from_community) &&
|
||||
!(
|
||||
profile.data?.user?.local_user_view.local_user.admin ||
|
||||
profile.data?.user?.moderates
|
||||
profile.current?.user?.local_user_view.local_user.admin ||
|
||||
profile.current?.user?.moderates
|
||||
.map(c => c.community.id)
|
||||
.includes(post.community_view.community.id)
|
||||
)}
|
||||
@@ -119,7 +119,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if commenting || !profile.data.jwt}
|
||||
{#if commenting || !profile.current.jwt}
|
||||
<div class="gap-2 flex items-center">
|
||||
<Select
|
||||
size="md"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import { Plus } from 'svelte-hero-icons'
|
||||
|
||||
let loading = $state(false)
|
||||
const fetched = $state.snapshot(profile.data.instance)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
@@ -27,7 +27,7 @@
|
||||
if (res.post) {
|
||||
goto(
|
||||
resolveRoute(`/post/[instance]/[id]`, {
|
||||
instance: profile.data.instance,
|
||||
instance: profile.current.instance,
|
||||
id: res.post.post.id.toString(),
|
||||
}),
|
||||
)
|
||||
@@ -56,7 +56,7 @@
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.data.jwt}
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
|
||||
@@ -2,6 +2,6 @@ import { profile } from '$lib/auth.svelte.js'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
if (profile.data.instance == params.instance)
|
||||
if (profile.current.instance == params.instance)
|
||||
redirect(302, `/post/${params.instance}/${params.id}`)
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
let data = $state(pageData)
|
||||
|
||||
async function unblockUser(item: PersonBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
data.person_blocks.splice(
|
||||
data.person_blocks.findIndex(i => i.target.id == item.target.id),
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
|
||||
async function unblockCommunity(item: CommunityBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
|
||||
data.community_blocks.splice(
|
||||
data.community_blocks.findIndex(i => i.community.id == item.community.id),
|
||||
@@ -63,7 +63,7 @@
|
||||
}
|
||||
|
||||
async function unblockInstances(item: InstanceBlockView) {
|
||||
if (!profile.data?.jwt) return
|
||||
if (!profile.current?.jwt) return
|
||||
if (!data.my_user?.instance_blocks) return
|
||||
|
||||
data.my_user.instance_blocks.splice(
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
old_password: oldPassword,
|
||||
})
|
||||
if (res?.jwt) {
|
||||
const { instance, username } = profile.data
|
||||
deleteProfile(profile.data.id)
|
||||
const { instance, username } = profile.current
|
||||
deleteProfile(profile.current.id)
|
||||
await setUser(res.jwt, instance, username!)
|
||||
|
||||
toast({ content: $t('toast.loginRefresh'), type: 'success' })
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
let bannerImage: FileList | undefined = $state()
|
||||
|
||||
async function save() {
|
||||
if (!formData || !profile.data?.jwt) return
|
||||
if (!formData || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -49,16 +49,16 @@
|
||||
let pfp = profileImage
|
||||
? await uploadImage(
|
||||
profileImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
let banner = bannerImage
|
||||
? await uploadImage(
|
||||
bannerImage[0],
|
||||
profile.data.instance,
|
||||
profile.data.jwt,
|
||||
profile.current.instance,
|
||||
profile.current.jwt,
|
||||
)
|
||||
: undefined
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ import { error } from '@sveltejs/kit'
|
||||
export const ssr = false
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
if (!profile.current.jwt) error(401)
|
||||
|
||||
const my_user =
|
||||
// profile.data?.user ??
|
||||
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
||||
// profile.current?.user ??
|
||||
(await client({ auth: profile.current?.jwt, func: fetch }).getSite())
|
||||
.my_user
|
||||
|
||||
return {
|
||||
my_user: my_user,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const { jwt } = profile.data
|
||||
const { jwt } = profile.current
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) throw error(401)
|
||||
if (!profile.current.jwt) throw error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
>
|
||||
<ObjectAutocomplete
|
||||
label={$t('nav.create.community')}
|
||||
jwt={profile.data?.jwt}
|
||||
jwt={profile.current?.jwt}
|
||||
listing_type="All"
|
||||
showWhenEmpty={true}
|
||||
onselect={c =>
|
||||
|
||||
@@ -50,7 +50,7 @@ export async function load({ url, fetch }) {
|
||||
})!,
|
||||
results: new ReactiveState(everything),
|
||||
streamed: {
|
||||
object: profile.data?.jwt
|
||||
object: profile.current?.jwt
|
||||
? getClient(undefined, fetch).resolveObject({
|
||||
q: query,
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@
|
||||
class="flex flex-col *:py-2 divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
style="scroll-behavior: smooth;"
|
||||
>
|
||||
{#if profile.data?.jwt}
|
||||
{#if profile.current?.jwt}
|
||||
<Section open={false} id="account" title={$t('settings.account.title')}>
|
||||
<div>
|
||||
<Button
|
||||
|
||||
@@ -55,11 +55,11 @@
|
||||
let sortForm = $state<HTMLFormElement>()
|
||||
|
||||
async function blockUser(block: number) {
|
||||
if (!profile.data?.user || !profile.data?.jwt)
|
||||
if (!profile.current?.user || !profile.current?.jwt)
|
||||
throw new Error('Unauthenticated')
|
||||
|
||||
try {
|
||||
const blocked = isBlocked(profile.data.user, block)
|
||||
const blocked = isBlocked(profile.current.user, block)
|
||||
|
||||
await getClient().blockPerson({
|
||||
block: !blocked,
|
||||
@@ -67,10 +67,10 @@
|
||||
})
|
||||
|
||||
if (blocked) {
|
||||
const index = profile.data.user.person_blocks
|
||||
const index = profile.current.user.person_blocks
|
||||
.map(p => p.target.id)
|
||||
.indexOf(block)
|
||||
profile.data.user.person_blocks.splice(index, 1)
|
||||
profile.current.user.person_blocks.splice(index, 1)
|
||||
}
|
||||
|
||||
toast({
|
||||
@@ -210,7 +210,7 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
{#snippet actions()}
|
||||
{#if profile.data?.user && profile.data.jwt && data.person_view.value.person.id != profile.data.user.local_user_view.person.id}
|
||||
{#if profile.current?.user && profile.current.jwt && data.person_view.value.person.id != profile.current.user.local_user_view.person.id}
|
||||
<div class="flex items-center gap-2 w-full flex-wrap">
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -237,7 +237,7 @@
|
||||
{$t('form.profile.matrix')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if isAdmin(profile.data?.user)}
|
||||
{#if isAdmin(profile.current?.user)}
|
||||
<Menu class="ml-auto" placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button size="sm" rounding="pill">
|
||||
@@ -292,7 +292,7 @@
|
||||
<Icon mini size="16" src={NoSymbol} />
|
||||
{/snippet}
|
||||
{isBlocked(
|
||||
profile.data.user,
|
||||
profile.current.user,
|
||||
data.person_view.value.person.id,
|
||||
)
|
||||
? 'Unblock'
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
style="rotate: -5deg; transition: rotate 1s linear;"
|
||||
>
|
||||
<div class="bg-black/20 font-mono fixed left-1/2 -translate-x-1/2">
|
||||
<p>{profile.data.username ?? 'You'} was slain by Command Palette</p>
|
||||
<p>{profile.current.username ?? 'You'} was slain by Command Palette</p>
|
||||
</div>
|
||||
<img
|
||||
src="/other/mc.png"
|
||||
|
||||
Reference in new issue
Block a user