feat: Switch to getSite().my_user instead of a hacky workaround

This commit is contained in:
Xyphyn committed 2023-07-13 10:51:11 -07:00
1 parent c3fc860117
commit 18010722a2
5 files changed
+33 -20

No files matched your search

+16 -1
View File
@@ -89,6 +89,21 @@
class="rounded-md max-h-[32rem] w-full max-w-full"
/>
</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 postRes.post.body && !postRes.post.nsfw}
<p
@@ -124,7 +139,7 @@
<Icon src={Square2Stack} width={16} mini />
Copy Link
</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}>
<Icon src={Trash} width={16} mini />
Delete
+3 -3
View File
@@ -18,9 +18,9 @@
</script>
<StickyCard>
<!-- {#if site.site.icon} -->
<!-- <Avatar width={64} url={site.site.icon} alt={site.site.name} /> -->
<!-- {/if} -->
{#if site.site.icon}
<Avatar width={64} url={site.site.icon} alt={site.site.name} />
{/if}
<span class="flex flex-row items-center gap-1 text-sm">
<Icon src={Calendar} width={16} height={16} mini />
<RelativeDate date={new Date(site.site.published)} />
+3 -6
View File
@@ -77,7 +77,7 @@
>
{#if $user}
<img
src={$user.person_view.person.avatar ??
src={$user.person.avatar ??
'https://xylo.xylight.dev/img/logo-background.svg'}
alt=""
width={32}
@@ -92,7 +92,7 @@
{/if}
</button>
<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>
<MenuButton link href="/experiments">
<Icon src={Beaker} mini width={16} />
@@ -103,10 +103,7 @@
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
</MenuButton>
{:else}
<MenuButton
link
href="/u/{$user.person_view.person.name}@{$authData.instance}"
>
<MenuButton link href="/u/{$user.person.name}@{$authData.instance}">
<Icon src={UserCircle} mini width={16} /> Profile
</MenuButton>
<MenuButton link href="/inbox">
+1 -1
View File
@@ -1,7 +1,7 @@
<div
class="sticky top-20 border bg-white shadow-md border-slate-100
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"
>
<slot />
+10 -9
View File
@@ -2,11 +2,13 @@ import {
type GetPersonDetailsResponse,
LemmyHttp,
type LoginResponse,
type Person,
type PersonView,
} from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
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 corsSupported = writable(true)
@@ -43,9 +45,7 @@ export interface UserData {
}
export const authData = writable<AuthData | undefined>()
export const user = writable<
(GetPersonDetailsResponse & UserData) | undefined
>()
export const user = writable<(PersonView & UserData) | undefined>()
setInterval(async () => {
// check for unread messages
@@ -72,14 +72,15 @@ if (typeof localStorage != 'undefined') {
}
authData.subscribe(async (data) => {
if (!data) return
if (!data?.token) return
try {
const person = await getClient().getPersonDetails({
auth: data?.token,
username: `${data?.username}@${data?.instance}`,
const site = await getClient().getSite({
auth: data.token,
})
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') {
localStorage.setItem('user', JSON.stringify(data))