feat: Switch to getSite().my_user instead of a hacky workaround
This commit is contained in:
1 parent
c3fc860117
commit
18010722a2
5 files changed
+33
-20
No files matched your search
@@ -89,6 +89,21 @@
|
|||||||
class="rounded-md max-h-[32rem] w-full max-w-full"
|
class="rounded-md max-h-[32rem] w-full max-w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{:else if postRes.post.embed_video_url}
|
||||||
|
<div class="self-start" class:blur-3xl={postRes.post.nsfw}>
|
||||||
|
<!-- svelte-ignore a11y-media-has-caption -->
|
||||||
|
<video class="rounded-md max-h-[32rem] w-full max-w-full" controls>
|
||||||
|
<source src={postRes.post.embed_video_url} />
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
{:else if postRes.post.thumbnail_url}
|
||||||
|
<div class="self-start" class:blur-3xl={postRes.post.nsfw}>
|
||||||
|
<img
|
||||||
|
src={postRes.post.thumbnail_url}
|
||||||
|
alt={postRes.post.name}
|
||||||
|
class="rounded-md max-h-[32rem] w-full max-w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if postRes.post.body && !postRes.post.nsfw}
|
{#if postRes.post.body && !postRes.post.nsfw}
|
||||||
<p
|
<p
|
||||||
@@ -124,7 +139,7 @@
|
|||||||
<Icon src={Square2Stack} width={16} mini />
|
<Icon src={Square2Stack} width={16} mini />
|
||||||
Copy Link
|
Copy Link
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $user?.person_view.person.id == postRes.post.creator_id}
|
{#if $user?.person.id == postRes.post.creator_id}
|
||||||
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||||
<Icon src={Trash} width={16} mini />
|
<Icon src={Trash} width={16} mini />
|
||||||
Delete
|
Delete
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<StickyCard>
|
<StickyCard>
|
||||||
<!-- {#if site.site.icon} -->
|
{#if site.site.icon}
|
||||||
<!-- <Avatar width={64} url={site.site.icon} alt={site.site.name} /> -->
|
<Avatar width={64} url={site.site.icon} alt={site.site.name} />
|
||||||
<!-- {/if} -->
|
{/if}
|
||||||
<span class="flex flex-row items-center gap-1 text-sm">
|
<span class="flex flex-row items-center gap-1 text-sm">
|
||||||
<Icon src={Calendar} width={16} height={16} mini />
|
<Icon src={Calendar} width={16} height={16} mini />
|
||||||
<RelativeDate date={new Date(site.site.published)} />
|
<RelativeDate date={new Date(site.site.published)} />
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
>
|
>
|
||||||
{#if $user}
|
{#if $user}
|
||||||
<img
|
<img
|
||||||
src={$user.person_view.person.avatar ??
|
src={$user.person.avatar ??
|
||||||
'https://xylo.xylight.dev/img/logo-background.svg'}
|
'https://xylo.xylight.dev/img/logo-background.svg'}
|
||||||
alt=""
|
alt=""
|
||||||
width={32}
|
width={32}
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
<span class="text-xs opacity-80 text-left mx-4 my-2">
|
<span class="text-xs opacity-80 text-left mx-4 my-2">
|
||||||
{$user ? $user.person_view.person.name : 'Profile'}
|
{$user ? $user.person.name : 'Profile'}
|
||||||
</span>
|
</span>
|
||||||
<MenuButton link href="/experiments">
|
<MenuButton link href="/experiments">
|
||||||
<Icon src={Beaker} mini width={16} />
|
<Icon src={Beaker} mini width={16} />
|
||||||
@@ -103,10 +103,7 @@
|
|||||||
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
{:else}
|
||||||
<MenuButton
|
<MenuButton link href="/u/{$user.person.name}@{$authData.instance}">
|
||||||
link
|
|
||||||
href="/u/{$user.person_view.person.name}@{$authData.instance}"
|
|
||||||
>
|
|
||||||
<Icon src={UserCircle} mini width={16} /> Profile
|
<Icon src={UserCircle} mini width={16} /> Profile
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton link href="/inbox">
|
<MenuButton link href="/inbox">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
class="sticky top-20 border bg-white shadow-md border-slate-100
|
class="sticky top-20 border bg-white shadow-md border-slate-100
|
||||||
dark:border-zinc-800 dark:bg-zinc-900 break-words flex
|
dark:border-zinc-800 dark:bg-zinc-900 break-words flex
|
||||||
flex-col gap-4 p-8 max-w-[20rem] w-full flex-shrink-0 rounded-md h-max max-h-[calc(100vh-6rem)]
|
flex-col gap-4 p-8 w-[20rem] rounded-md h-max max-h-[calc(100vh-6rem)]
|
||||||
overflow-auto"
|
overflow-auto"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
+10
-9
@@ -2,11 +2,13 @@ import {
|
|||||||
type GetPersonDetailsResponse,
|
type GetPersonDetailsResponse,
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
type LoginResponse,
|
type LoginResponse,
|
||||||
|
type Person,
|
||||||
|
type PersonView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import { PUBLIC_PROXY_URL } from '$env/static/public'
|
import { PUBLIC_PROXY_URL } from '$env/static/public'
|
||||||
|
|
||||||
export const DEFAULT_INSTANCE_URL = 'lemmy.ml'
|
export const DEFAULT_INSTANCE_URL = 'lemmy.world'
|
||||||
export let instance_url = writable(DEFAULT_INSTANCE_URL)
|
export let instance_url = writable(DEFAULT_INSTANCE_URL)
|
||||||
export let corsSupported = writable(true)
|
export let corsSupported = writable(true)
|
||||||
|
|
||||||
@@ -43,9 +45,7 @@ export interface UserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const authData = writable<AuthData | undefined>()
|
export const authData = writable<AuthData | undefined>()
|
||||||
export const user = writable<
|
export const user = writable<(PersonView & UserData) | undefined>()
|
||||||
(GetPersonDetailsResponse & UserData) | undefined
|
|
||||||
>()
|
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
// check for unread messages
|
// check for unread messages
|
||||||
@@ -72,14 +72,15 @@ if (typeof localStorage != 'undefined') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
authData.subscribe(async (data) => {
|
authData.subscribe(async (data) => {
|
||||||
if (!data) return
|
if (!data?.token) return
|
||||||
try {
|
try {
|
||||||
const person = await getClient().getPersonDetails({
|
const site = await getClient().getSite({
|
||||||
auth: data?.token,
|
auth: data.token,
|
||||||
username: `${data?.username}@${data?.instance}`,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
user.set({ ...person, unreads: 0 })
|
if (!site.my_user) throw Error('Missing user')
|
||||||
|
|
||||||
|
user.set({ ...site.my_user.local_user_view, unreads: 0 })
|
||||||
|
|
||||||
if (typeof localStorage != 'undefined') {
|
if (typeof localStorage != 'undefined') {
|
||||||
localStorage.setItem('user', JSON.stringify(data))
|
localStorage.setItem('user', JSON.stringify(data))
|
||||||
|
|||||||
Reference in new issue
Block a user